sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
18:6f86abfae754
Parent:
17:dce982e0a383
Child:
19:8e9fe7d25b9c
--- a/renderclass.cpp	Mon May 20 08:51:07 2013 +0000
+++ b/renderclass.cpp	Mon May 20 09:31:29 2013 +0000
@@ -7,78 +7,97 @@
 
 //for translating -----------------------------------------------------------------
 
-point2dl shearing(point2dl dataBefore, float velocity, float theta){
+inline void render::shearing(point2dl& dataBefore)
+{
     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;
+    dataBefore.x = dataBefore.x ;//+ speed * cos(angle) * timer_v.read_us()/st/1000;
+    dataBefore.y = dataBefore.y ;//+ speed * sin(angle) * timer_v.read_us()/st/1000;
+
 }
 
-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;
+inline void render::rotation(point2dl& dataBefore)
+{
+    int x=dataBefore.x;
+    dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;
+    dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
 }
 //----------------------------------------------------------------------------------
 
-void render::startRender(){
-    //void (render::*fpdraw)() = draw;                  // I can't solve the error.......I tried a few days.......... 
+void render::startRender()
+{
+    //void (render::*fpdraw)() = draw;                  // I can't solve the error.......I tried a few days..........
     renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);   //  ???????how to set menber function???????
 }
 
-void render::stopRender(){
+void render::stopRender()
+{
     renderTimer.detach();
 }
 
-void render::setRender(vector<letter> *p){
+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){
+    for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
         translated.push_back(*itr);
     }                                            //copy the liblary to the buffer.
+
+    currentLetters=0;
+    currentPoints=0;
 }
 
-void render::draw(){
-    drawPoint.x = translated[currentLetters].letpoints[currentPoints].x;
-    drawPoint.y = translated[currentLetters].letpoints[currentPoints].y;
-    drawPoint.laserSwitch = translated[currentLetters].letpoints[currentPoints].laserSwitch;
+
+void render::updateSpeed(float vx, float vy){
+    speed=sqrt(vx*vx+vy*vy);//*factorSpeed;
+    angle=atan2(vy,vx);
+}
+
+void render::draw()
+{
+
+    point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
+    transform(drawPoint); // transform it with the current speed and angle
+
     IO.writeOutXY(drawPoint.x , drawPoint.y);
     IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
-    
-    
+
     currentPoints++;
-    if(currentPoints > translated[currentLetters].letpoints.size() ){
+    if(currentPoints > translated[currentLetters].letpoints.size() ) {
         currentLetters++;
         currentPoints = 0;
     }
-    if(currentLetters > translated.size()){
+    if(currentLetters > translated.size()) {
         currentLetters = 0;
         currentPoints = 0;
     }
+}
+
+void render::transform(point2dl& mypoint)
+{
+
+    rotation(mypoint);
+    shearing(mypoint);
 
 }
 
-void render::translating(float speed, float angle){ //DO when get the speed and angle data.
-    for (int i = 0; i > 10;  i++){
+/*
+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()){
+        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);
-    
+        if(currentLetters > (*ptext).size()) break;
+
+        point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints]);
+        point2dl bufferShear = shearing(bufferRotate);
+
         translated[currentLetters].letpoints[currentPoints] = bufferShear;
-    
+
         j++;
     }
-}
\ No newline at end of file
+}*/
\ No newline at end of file