Hiromasa Oku
/
linearMirrorMotion1017
this version 10/17
Fork of linearMirrorMotion by
Diff: renderclass.cpp
- Revision:
- 20:8475768fc2f7
- Parent:
- 19:8e9fe7d25b9c
diff -r 8e9fe7d25b9c -r 8475768fc2f7 renderclass.cpp --- a/renderclass.cpp Fri May 24 06:37:58 2013 +0000 +++ b/renderclass.cpp Fri May 31 06:32:07 2013 +0000 @@ -9,21 +9,21 @@ inline void render::shearing(point2dl& dataBefore) { - 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; - + dataBefore.x = dataBefore.x - speed * cos(angle+PI/2)*speedTimer.read_us()/400; + dataBefore.y = dataBefore.y - speed * sin(angle+PI/2)*speedTimer.read_us()/400; } 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; + dataBefore.x = 1800 * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y; + dataBefore.y = 1800 * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y; } //---------------------------------------------------------------------------------- void render::startRender() { + speedTimer.start(); renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); pc.printf("render started!\n"); } @@ -43,12 +43,13 @@ //for(int i=0; i!=(*ptext).size(); i++){ for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) { translated.push_back(*itr); - pc.printf("moving...." ); } //copy the liblary to the buffer. currentLetters=0; currentPoints=0; + shearingSwitch = 1; + } @@ -59,40 +60,53 @@ //speed=sqrt(vx*vx+vy*vy);//*factorSpeed; //angle=atan2(vy,vx); } -float t=0; + +int stopcounter=100; + void render::draw() { if(translated.size()>0){ + if(stopcounter == 99) speedTimer.reset(); + if(stopcounter==100){ + point2dl drawPoint=translated[currentLetters].letpoints[currentPoints]; transform(drawPoint); // transform it with the current speed and angle - pc.printf("%d, %d, %d \n" , (int)drawPoint.x, (int)drawPoint.y, (int)drawPoint.laserSwitch); //IO.setRedPower(drawPoint.laserSwitch); - IO.writeOutXY(CENTER_AD_MIRROR_X+ 4*(int)drawPoint.x , CENTER_AD_MIRROR_Y - 4*(int)drawPoint.y); + IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y); if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch); - else IO.setRedPower(0); ///laserswitch txt library needs to rewrite..........?\(>o<)/? + else IO.setRedPower(0); currentPoints++; + } + else stopcounter++; if(currentPoints >= translated[currentLetters].letpoints.size() ) { + if(stopcounter == 100) stopcounter = 0; + else if(stopcounter == 0){ + renderTimer.detach(); + } + //wait_us(RENDER_INTERVAL); + else if(stopcounter == 1){ + IO.setRedPower(0); + //wait_us(RENDER_INTERVAL); currentLetters++; currentPoints = 0; - - renderTimer.detach(); - wait_us(RENDER_INTERVAL); - IO.setRedPower(0); - wait_us(RENDER_INTERVAL*40); renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); + speedTimer.reset(); + } } if(currentLetters >= translated.size()) { currentLetters = 0; currentPoints = 0; renderTimer.detach(); - wait_us(RENDER_INTERVAL); + //wait_us(RENDER_INTERVAL); IO.setRedPower(0); - wait_us(RENDER_INTERVAL*20); + //wait_us(RENDER_INTERVAL*200); renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); + speedTimer.reset(); + stopcounter = -200; } } } @@ -100,26 +114,6 @@ void render::transform(point2dl& mypoint) { rotation(mypoint); - shearing(mypoint); + if(shearingSwitch == 1) shearing(mypoint); } -/* -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]); - point2dl bufferShear = shearing(bufferRotate); - - translated[currentLetters].letpoints[currentPoints] = bufferShear; - - j++; - } -}*/ \ No newline at end of file