sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
takapiasano
Date:
Tue Jul 30 04:16:21 2013 +0000
Revision:
29:aa8fe9fccec8
Parent:
20:8475768fc2f7
close to complete

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hiromasaoku 16:6dd2e60bc5bc 1 #include "renderclass.h"
hiromasaoku 16:6dd2e60bc5bc 2 #include "mbed.h"
hiromasaoku 16:6dd2e60bc5bc 3 #include "laserProjectorHardware.h"
hiromasaoku 16:6dd2e60bc5bc 4 #include <vector>
hiromasaoku 16:6dd2e60bc5bc 5
hiromasaoku 16:6dd2e60bc5bc 6 Ticker translationTimer;
hiromasaoku 16:6dd2e60bc5bc 7
hiromasaoku 16:6dd2e60bc5bc 8 //for translating -----------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 9
hiromasaoku 18:6f86abfae754 10 inline void render::shearing(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 11 {
takapiasano 29:aa8fe9fccec8 12 dataBefore.x = -dataBefore.x/2.0 - 10.0*intvx; //vx * speedTimer.read_us()*10; //2000000;//dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800;
takapiasano 29:aa8fe9fccec8 13 dataBefore.y = dataBefore.y/2.0 - 10.0*intvy; //vy * speedTimer.read_us()*10;//dataBefore.y ;//- speed * sin(angle+PI/2)*speedTimer.read_us()/800;
hiromasaoku 16:6dd2e60bc5bc 14 }
hiromasaoku 16:6dd2e60bc5bc 15
hiromasaoku 18:6f86abfae754 16 inline void render::rotation(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 17 {
hiromasaoku 18:6f86abfae754 18 int x=dataBefore.x;
takapiasano 29:aa8fe9fccec8 19 dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;//
takapiasano 29:aa8fe9fccec8 20 dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
takapiasano 29:aa8fe9fccec8 21
hiromasaoku 16:6dd2e60bc5bc 22 }
hiromasaoku 16:6dd2e60bc5bc 23 //----------------------------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 24
hiromasaoku 18:6f86abfae754 25 void render::startRender()
hiromasaoku 18:6f86abfae754 26 {
hiromasaoku 20:8475768fc2f7 27 speedTimer.start();
hiromasaoku 19:8e9fe7d25b9c 28 renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
hiromasaoku 19:8e9fe7d25b9c 29 pc.printf("render started!\n");
takapiasano 29:aa8fe9fccec8 30 pc.printf("int : %f, %f, v :, %f,%f, " , intvx , intvy , vx , vy);
takapiasano 29:aa8fe9fccec8 31
hiromasaoku 16:6dd2e60bc5bc 32 }
hiromasaoku 16:6dd2e60bc5bc 33
hiromasaoku 18:6f86abfae754 34 void render::stopRender()
hiromasaoku 18:6f86abfae754 35 {
hiromasaoku 16:6dd2e60bc5bc 36 renderTimer.detach();
takapiasano 29:aa8fe9fccec8 37 speedTimer.stop();
hiromasaoku 16:6dd2e60bc5bc 38 }
hiromasaoku 16:6dd2e60bc5bc 39
hiromasaoku 18:6f86abfae754 40 void render::setRender(vector<letter> *p)
hiromasaoku 18:6f86abfae754 41 {
takapiasano 29:aa8fe9fccec8 42 translated.clear();
takapiasano 29:aa8fe9fccec8 43 radious = 200;
takapiasano 29:aa8fe9fccec8 44
hiromasaoku 16:6dd2e60bc5bc 45 ptext = p;
hiromasaoku 19:8e9fe7d25b9c 46 pc.printf("Size of text to render: %d/n", (*ptext).size() );
hiromasaoku 16:6dd2e60bc5bc 47 //for(int i=0; i!=(*ptext).size(); i++){
takapiasano 29:aa8fe9fccec8 48 int count=0;
hiromasaoku 18:6f86abfae754 49 for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
takapiasano 29:aa8fe9fccec8 50 letter translatedLetter;
takapiasano 29:aa8fe9fccec8 51 for(int i=0; i<(*itr).letpoints.size(); i++) {
takapiasano 29:aa8fe9fccec8 52 point2dl tranPoint;
takapiasano 29:aa8fe9fccec8 53 tranPoint.x=itr->letpoints[i].x+560*count;
takapiasano 29:aa8fe9fccec8 54 tranPoint.y=-itr->letpoints[i].y;
takapiasano 29:aa8fe9fccec8 55 tranPoint.laserSwitch=itr->letpoints[i].laserSwitch;
takapiasano 29:aa8fe9fccec8 56 translatedLetter.letpoints.push_back(tranPoint);
takapiasano 29:aa8fe9fccec8 57
hiromasaoku 16:6dd2e60bc5bc 58 } //copy the liblary to the buffer.
takapiasano 29:aa8fe9fccec8 59 translated.push_back(translatedLetter);
takapiasano 29:aa8fe9fccec8 60 count++;
takapiasano 29:aa8fe9fccec8 61 }
takapiasano 29:aa8fe9fccec8 62
takapiasano 29:aa8fe9fccec8 63 shearingSwitch = 1;
takapiasano 29:aa8fe9fccec8 64 radious = 1800;
takapiasano 29:aa8fe9fccec8 65
hiromasaoku 18:6f86abfae754 66 currentLetters=0;
hiromasaoku 20:8475768fc2f7 67
takapiasano 29:aa8fe9fccec8 68 firstPointCounter=0;
takapiasano 29:aa8fe9fccec8 69 lastPointCounter=0;
takapiasano 29:aa8fe9fccec8 70
takapiasano 29:aa8fe9fccec8 71 rendererState=FIRST_POINT;
hiromasaoku 16:6dd2e60bc5bc 72 }
hiromasaoku 16:6dd2e60bc5bc 73
hiromasaoku 18:6f86abfae754 74
takapiasano 29:aa8fe9fccec8 75 void render::updateSpeed(float vvx, float vvy)
takapiasano 29:aa8fe9fccec8 76 {
takapiasano 29:aa8fe9fccec8 77 vx = vvx;
takapiasano 29:aa8fe9fccec8 78 vy = vvy;
hiromasaoku 19:8e9fe7d25b9c 79
takapiasano 29:aa8fe9fccec8 80 //intvx += RENDER_INTERVAL*vx;
takapiasano 29:aa8fe9fccec8 81 //intvy += RENDER_INTERVAL*vy;
takapiasano 29:aa8fe9fccec8 82
takapiasano 29:aa8fe9fccec8 83 angle= 0;//(1/9.0)*PI ;//+0.3* atan( vy / vx ) * 0.7*angle; atan2
hiromasaoku 18:6f86abfae754 84 }
hiromasaoku 20:8475768fc2f7 85
hiromasaoku 20:8475768fc2f7 86
hiromasaoku 18:6f86abfae754 87 void render::draw()
hiromasaoku 18:6f86abfae754 88 {
takapiasano 29:aa8fe9fccec8 89 /*
takapiasano 29:aa8fe9fccec8 90 if(firstPointCounter < 3){
takapiasano 29:aa8fe9fccec8 91
takapiasano 29:aa8fe9fccec8 92 IO.writeOutXY(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
takapiasano 29:aa8fe9fccec8 93 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 29:aa8fe9fccec8 94 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 29:aa8fe9fccec8 95
takapiasano 29:aa8fe9fccec8 96 firstPointCounter+=1;
takapiasano 29:aa8fe9fccec8 97 }
takapiasano 29:aa8fe9fccec8 98 else{
takapiasano 29:aa8fe9fccec8 99
takapiasano 29:aa8fe9fccec8 100 IO.setRedPower(0);
takapiasano 29:aa8fe9fccec8 101 IO.setGreenPower(0);
takapiasano 29:aa8fe9fccec8 102 firstPointCounter = 0;
takapiasano 29:aa8fe9fccec8 103 }
hiromasaoku 20:8475768fc2f7 104
takapiasano 29:aa8fe9fccec8 105
takapiasano 29:aa8fe9fccec8 106 */
hiromasaoku 19:8e9fe7d25b9c 107
hiromasaoku 19:8e9fe7d25b9c 108
takapiasano 29:aa8fe9fccec8 109 //if(abs(vx)<0.001 || abs(vy) < 0.001)startSwitch = 1;
takapiasano 29:aa8fe9fccec8 110
takapiasano 29:aa8fe9fccec8 111 if(translated.size()>0 && startSwitch == 1) {
takapiasano 29:aa8fe9fccec8 112
takapiasano 29:aa8fe9fccec8 113 switch(rendererState) {
takapiasano 29:aa8fe9fccec8 114
takapiasano 29:aa8fe9fccec8 115 case NORMAL_POINT:
takapiasano 29:aa8fe9fccec8 116 intvx += speedTimer.read_us()*vx;
takapiasano 29:aa8fe9fccec8 117 intvy += speedTimer.read_us()*vy;
takapiasano 29:aa8fe9fccec8 118 speedTimer.reset();
takapiasano 29:aa8fe9fccec8 119
takapiasano 29:aa8fe9fccec8 120 point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
takapiasano 29:aa8fe9fccec8 121 transform(drawPoint); // transform it with the current speed and angle
takapiasano 29:aa8fe9fccec8 122 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 29:aa8fe9fccec8 123 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 29:aa8fe9fccec8 124 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 29:aa8fe9fccec8 125
takapiasano 29:aa8fe9fccec8 126 // move to the next point
takapiasano 29:aa8fe9fccec8 127 currentPoints++;
takapiasano 29:aa8fe9fccec8 128
takapiasano 29:aa8fe9fccec8 129 //Should we change the state?
takapiasano 29:aa8fe9fccec8 130 if(currentPoints >= translated[currentLetters].letpoints.size() ) {
takapiasano 29:aa8fe9fccec8 131 rendererState=AFTER_LAST_POINT;
takapiasano 29:aa8fe9fccec8 132 }
takapiasano 29:aa8fe9fccec8 133 break;
hiromasaoku 18:6f86abfae754 134
takapiasano 29:aa8fe9fccec8 135 case AFTER_LAST_POINT:
takapiasano 29:aa8fe9fccec8 136 // just wait!
takapiasano 29:aa8fe9fccec8 137 if (lastPointCounter<WAITING_LAST) {
takapiasano 29:aa8fe9fccec8 138 IO.setRedPower(0);
takapiasano 29:aa8fe9fccec8 139 IO.setGreenPower(0);
takapiasano 29:aa8fe9fccec8 140 lastPointCounter++;
takapiasano 29:aa8fe9fccec8 141 }
takapiasano 29:aa8fe9fccec8 142 else {
takapiasano 29:aa8fe9fccec8 143 lastPointCounter=0;
takapiasano 29:aa8fe9fccec8 144 currentPoints = 0;
takapiasano 29:aa8fe9fccec8 145 // switch the laser off and move to the first point of the next letter:
takapiasano 29:aa8fe9fccec8 146
takapiasano 29:aa8fe9fccec8 147 currentLetters++;
takapiasano 29:aa8fe9fccec8 148 if(currentLetters >= translated.size()) {
takapiasano 29:aa8fe9fccec8 149 currentLetters = 0;
takapiasano 29:aa8fe9fccec8 150 //startSwitch=0;
takapiasano 29:aa8fe9fccec8 151 intvx = intvy =0;
takapiasano 29:aa8fe9fccec8 152
takapiasano 29:aa8fe9fccec8 153
takapiasano 29:aa8fe9fccec8 154 }
takapiasano 29:aa8fe9fccec8 155 rendererState=FIRST_POINT;
takapiasano 29:aa8fe9fccec8 156
takapiasano 29:aa8fe9fccec8 157 }
takapiasano 29:aa8fe9fccec8 158 break;
takapiasano 29:aa8fe9fccec8 159
takapiasano 29:aa8fe9fccec8 160 case FIRST_POINT:
takapiasano 29:aa8fe9fccec8 161
takapiasano 29:aa8fe9fccec8 162 if (firstPointCounter<WAITING_FIRST) {
takapiasano 29:aa8fe9fccec8 163 firstPointCounter++;
takapiasano 29:aa8fe9fccec8 164
takapiasano 29:aa8fe9fccec8 165 // show first point!
takapiasano 29:aa8fe9fccec8 166 point2dl drawPoint=translated[currentLetters].letpoints[0];
takapiasano 29:aa8fe9fccec8 167
takapiasano 29:aa8fe9fccec8 168 if(currentLetters!=0){
takapiasano 29:aa8fe9fccec8 169 intvx += speedTimer.read_us()*vx;
takapiasano 29:aa8fe9fccec8 170 intvy += speedTimer.read_us()*vy;
takapiasano 29:aa8fe9fccec8 171 }
takapiasano 29:aa8fe9fccec8 172
takapiasano 29:aa8fe9fccec8 173 speedTimer.reset();
takapiasano 29:aa8fe9fccec8 174 transform(drawPoint); // transform it with the current speed and angle
takapiasano 29:aa8fe9fccec8 175 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 29:aa8fe9fccec8 176
takapiasano 29:aa8fe9fccec8 177
takapiasano 29:aa8fe9fccec8 178
takapiasano 29:aa8fe9fccec8 179 //IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 29:aa8fe9fccec8 180
takapiasano 29:aa8fe9fccec8 181 } else {
takapiasano 29:aa8fe9fccec8 182 firstPointCounter=0;
takapiasano 29:aa8fe9fccec8 183 currentPoints=1;
takapiasano 29:aa8fe9fccec8 184
takapiasano 29:aa8fe9fccec8 185 intvx += speedTimer.read_us()*vx;
takapiasano 29:aa8fe9fccec8 186 intvy += speedTimer.read_us()*vy;
takapiasano 29:aa8fe9fccec8 187 speedTimer.reset();
takapiasano 29:aa8fe9fccec8 188
takapiasano 29:aa8fe9fccec8 189 rendererState=NORMAL_POINT;
takapiasano 29:aa8fe9fccec8 190 }
takapiasano 29:aa8fe9fccec8 191 break;
takapiasano 29:aa8fe9fccec8 192 }
hiromasaoku 20:8475768fc2f7 193 }
takapiasano 29:aa8fe9fccec8 194
hiromasaoku 18:6f86abfae754 195 }
hiromasaoku 18:6f86abfae754 196
takapiasano 29:aa8fe9fccec8 197 void render::transform(point2dl& mypoint) {
takapiasano 29:aa8fe9fccec8 198 rotation(mypoint);
takapiasano 29:aa8fe9fccec8 199 if(shearingSwitch == 1) shearing(mypoint);
hiromasaoku 16:6dd2e60bc5bc 200 }
hiromasaoku 16:6dd2e60bc5bc 201