sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
24:ab74d2018e6c
Parent:
22:e86d63dfbbe1
Child:
25:423050363215
--- a/renderclass.cpp	Fri Jun 28 02:30:51 2013 +0000
+++ b/renderclass.cpp	Tue Jul 02 08:26:45 2013 +0000
@@ -18,7 +18,7 @@
     int x=dataBefore.x;
     dataBefore.x = x + abs((int)angle) % (2 * (CENTER_AD_MIRROR_X-200)) -  CENTER_AD_MIRROR_X+200;//x + (CENTER_AD_MIRROR_X-200) * cos(angle);//radious * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y;//
     dataBefore.y = -dataBefore.y;//radious * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;//
-    
+
 }
 //----------------------------------------------------------------------------------
 
@@ -32,25 +32,40 @@
 void render::stopRender()
 {
     renderTimer.detach();
-    translated.clear();
-    currentLetters=0;
-    currentPoints=0;
+    speedTimer.stop();
 }
 
 void render::setRender(vector<letter> *p)
 {
+    translated.clear();
+    
     ptext = p;
     pc.printf("Size of text to render: %d/n", (*ptext).size() );
     //for(int i=0; i!=(*ptext).size(); i++){
+    int count=0;
     for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
-        translated.push_back(*itr);
+        letter translatedLetter;
+        for(int i=0; i<(*itr).letpoints.size(); i++) {
+            point2dl tranPoint;
+            tranPoint.x=itr->letpoints[i].x+560*count;
+            tranPoint.y=itr->letpoints[i].y;
+            tranPoint.laserSwitch=itr->letpoints[i].laserSwitch;
+            translatedLetter.letpoints.push_back(tranPoint);
+        
     }                                            //copy the liblary to the buffer.
+    translated.push_back(translatedLetter);
+    count++;
+}
 
+    shearingSwitch = 1;
+    radious = 1800;
 
     currentLetters=0;
-    currentPoints=0;
-    shearingSwitch = 1;
-    radious = 1800;
+
+    firstPointCounter=0;
+    lastPointCounter=0;
+
+    rendererState=FIRST_POINT;
 }
 
 
@@ -70,47 +85,66 @@
 void render::draw()
 {
     if(translated.size()>0) {
-        point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
-        transform(drawPoint);               // transform it with the current speed and angle
-        IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
-        
-        
-        
-        ////laser switch
-        if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch);
-        else                IO.setRedPower(0);
+
+        switch(rendererState) {
+
+            case NORMAL_POINT:
+                point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
+                transform(drawPoint);               // transform it with the current speed and angle
+                IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
+                IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
 
-        currentPoints++;
+                // move to the next point
+                currentPoints++;
+
+                //Should we change the state?
+                if(currentPoints >= translated[currentLetters].letpoints.size() ) {
+                    rendererState=AFTER_LAST_POINT;
+                }
+                break;
 
-        if(currentPoints >= translated[currentLetters].letpoints.size() ) {
-            currentLetters++;
-            currentPoints = 0;
-            //renderTimer.detach();
- 
-            wait_us(RENDER_INTERVAL);
-            IO.setRedPower(0);
-            //wait_us(RENDER_INTERVAL);
-            
-            //renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
-            speedTimer.reset();
-            //}
-        }
-        if(currentLetters >= translated.size()) {
-            currentLetters = 0;
-            currentPoints = 0;
-            //renderTimer.detach();
-            //wait_us(RENDER_INTERVAL);
-            IO.setRedPower(0);
-            //wait_us(RENDER_INTERVAL*20);
-            //renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
-            speedTimer.reset();
+            case AFTER_LAST_POINT:
+                // just wait!
+                if (lastPointCounter<WAITING_LAST) {
+                IO.setRedPower(0);
+                lastPointCounter++;
+                }
+                else {
+                    lastPointCounter=0;
+                    currentPoints = 0;
+                    // switch the laser off and move to the first point of the next letter:
+                    
+                    currentLetters++;
+                    if(currentLetters >= translated.size()) {
+                        currentLetters = 0;
+                        speedTimer.reset();
+                    }
+                    rendererState=FIRST_POINT;
+                    }
+                    break;
+
+                case FIRST_POINT:
+                    if (firstPointCounter<WAITING_FIRST) {
+                    firstPointCounter++;
+                    
+                    // show first point!
+                    point2dl drawPoint=translated[currentLetters].letpoints[0];
+                    transform(drawPoint);               // transform it with the current speed and angle
+                    IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
+                    //IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
+
+                    } else {
+                        firstPointCounter=0;
+                        currentPoints=1;
+                        rendererState=NORMAL_POINT;
+                    }
+                    break;
+                }
         }
     }
-}
 
-void render::transform(point2dl& mypoint)
-{
-    rotation(mypoint);
-    if(shearingSwitch == 1) shearing(mypoint);
-}
+    void render::transform(point2dl& mypoint) {
+        rotation(mypoint);
+        if(shearingSwitch == 1) shearing(mypoint);
+    }