sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
16:6dd2e60bc5bc
Child:
17:dce982e0a383
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/renderclass.cpp	Mon May 20 08:25:22 2013 +0000
@@ -0,0 +1,85 @@
+#include "renderclass.h"
+#include "mbed.h"
+#include "laserProjectorHardware.h"
+#include <vector>
+
+Ticker renderTimer;
+Ticker translationTimer;
+
+//for translating -----------------------------------------------------------------
+
+point2dl shearing(point2dl dataBefore, float velocity, float theta){
+    point2dl dataAfter;
+    dataAfter.x = dataBefore.x ;//+ velocity * cos(theta) * timer_v.read_us()/st/1000;   
+    dataAfter.y = dataBefore.y ;//+ velocity * sin(theta) * timer_v.read_us()/st/1000; 
+    dataAfter.laserSwitch = dataBefore.laserSwitch;
+    
+    return dataAfter;
+}
+
+point2dl rotation(point2dl dataBefore, float theta){
+    point2dl dataAfter;
+    dataAfter.x = cos(theta)*dataBefore.x - sin(theta)*dataBefore.y;
+    dataAfter.y = sin(theta)*dataBefore.x + cos(theta)*dataBefore.y;
+    dataAfter.laserSwitch = dataBefore.laserSwitch;
+
+    return dataAfter;
+}
+//----------------------------------------------------------------------------------
+
+void render::startRender(){
+    //void (render::*fpdraw)() = draw;                  // I can't solve the error.......I tried a few days.......... 
+    //renderTimer.attach_us((this->*fpdraw)(), 200);   //  ???????how to set menber function???????
+}
+
+void render::stopRender(){
+    renderTimer.detach();
+}
+
+void render::setRender(vector<letter> *p){
+    ptext = p;
+    
+    //for(int i=0; i!=(*ptext).size(); i++){
+    for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr){
+        translated.push_back(*itr);
+    }                                            //copy the liblary to the buffer.
+}
+
+void render::draw(){
+    drawPoint.x = translated[currentLetters].letpoints[currentPoints].x;
+    drawPoint.y = translated[currentLetters].letpoints[currentPoints].y;
+    drawPoint.laserSwitch = translated[currentLetters].letpoints[currentPoints].laserSwitch;
+    IO.writeOutXY(drawPoint.x , drawPoint.y);
+    IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
+    
+    
+    currentPoints++;
+    if(currentPoints > translated[currentLetters].letpoints.size() ){
+        currentLetters++;
+        currentPoints = 0;
+    }
+    if(currentLetters > translated.size()){
+        currentLetters = 0;
+        currentPoints = 0;
+    }
+
+}
+
+void render::translating(float speed, float angle){ //DO when get the speed and angle data.
+    for (int i = 0; i > 10;  i++){
+        int j=0;
+        if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()){
+            currentPoints = 0;
+            currentLetters++;
+            j=0;
+        }
+        if(currentLetters > (*ptext).size()) break; 
+        
+        point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints],angle);
+        point2dl bufferShear = shearing(bufferRotate, speed, angle);
+    
+        translated[currentLetters].letpoints[currentPoints] = bufferShear;
+    
+        j++;
+    }
+}
\ No newline at end of file