sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
takapiasano
Date:
Mon Jul 22 08:09:18 2013 +0000
Revision:
26:74ecbf9985e1
Parent:
25:423050363215
Child:
27:38bc8dc67dab
ajust dekita

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 26:74ecbf9985e1 12 dataBefore.x = -dataBefore.x/2.0 - 5.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 26:74ecbf9985e1 13 dataBefore.y = dataBefore.y/2.0 - 5.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 26:74ecbf9985e1 19 dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;//
takapiasano 26:74ecbf9985e1 20 dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
takapiasano 24:ab74d2018e6c 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 26:74ecbf9985e1 30 pc.printf("int : %f, %f, v :, %f,%f, " , intvx , intvy , vx , vy);
takapiasano 26:74ecbf9985e1 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 24:ab74d2018e6c 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 24:ab74d2018e6c 42 translated.clear();
takapiasano 26:74ecbf9985e1 43 radious = 200;
takapiasano 26:74ecbf9985e1 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 24:ab74d2018e6c 48 int count=0;
hiromasaoku 18:6f86abfae754 49 for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
takapiasano 24:ab74d2018e6c 50 letter translatedLetter;
takapiasano 24:ab74d2018e6c 51 for(int i=0; i<(*itr).letpoints.size(); i++) {
takapiasano 24:ab74d2018e6c 52 point2dl tranPoint;
takapiasano 24:ab74d2018e6c 53 tranPoint.x=itr->letpoints[i].x+560*count;
takapiasano 26:74ecbf9985e1 54 tranPoint.y=-itr->letpoints[i].y;
takapiasano 24:ab74d2018e6c 55 tranPoint.laserSwitch=itr->letpoints[i].laserSwitch;
takapiasano 24:ab74d2018e6c 56 translatedLetter.letpoints.push_back(tranPoint);
takapiasano 24:ab74d2018e6c 57
hiromasaoku 16:6dd2e60bc5bc 58 } //copy the liblary to the buffer.
takapiasano 24:ab74d2018e6c 59 translated.push_back(translatedLetter);
takapiasano 24:ab74d2018e6c 60 count++;
takapiasano 24:ab74d2018e6c 61 }
takapiasano 21:4095a071724d 62
takapiasano 24:ab74d2018e6c 63 shearingSwitch = 1;
takapiasano 24:ab74d2018e6c 64 radious = 1800;
takapiasano 21:4095a071724d 65
hiromasaoku 18:6f86abfae754 66 currentLetters=0;
takapiasano 24:ab74d2018e6c 67
takapiasano 24:ab74d2018e6c 68 firstPointCounter=0;
takapiasano 24:ab74d2018e6c 69 lastPointCounter=0;
takapiasano 24:ab74d2018e6c 70
takapiasano 24:ab74d2018e6c 71 rendererState=FIRST_POINT;
hiromasaoku 16:6dd2e60bc5bc 72 }
hiromasaoku 16:6dd2e60bc5bc 73
hiromasaoku 18:6f86abfae754 74
takapiasano 26:74ecbf9985e1 75 void render::updateSpeed(float vvx, float vvy)
takapiasano 21:4095a071724d 76 {
takapiasano 26:74ecbf9985e1 77 vx = vvx;
takapiasano 26:74ecbf9985e1 78 vy = vvy;
takapiasano 26:74ecbf9985e1 79
takapiasano 26:74ecbf9985e1 80 //intvx += RENDER_INTERVAL*vx;
takapiasano 26:74ecbf9985e1 81 //intvy += RENDER_INTERVAL*vy;
takapiasano 26:74ecbf9985e1 82
takapiasano 26:74ecbf9985e1 83 angle= 0;//(1/9.0)*PI ;//+0.3* atan( vy / vx ) * 0.7*angle; atan2
takapiasano 26:74ecbf9985e1 84 }
takapiasano 21:4095a071724d 85
hiromasaoku 20:8475768fc2f7 86
hiromasaoku 18:6f86abfae754 87 void render::draw()
hiromasaoku 18:6f86abfae754 88 {
takapiasano 26:74ecbf9985e1 89 /*
takapiasano 26:74ecbf9985e1 90 if(firstPointCounter < 3){
takapiasano 26:74ecbf9985e1 91
takapiasano 26:74ecbf9985e1 92 IO.writeOutXY(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
takapiasano 25:423050363215 93 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 25:423050363215 94 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 26:74ecbf9985e1 95
takapiasano 26:74ecbf9985e1 96 firstPointCounter+=1;
takapiasano 25:423050363215 97 }
takapiasano 25:423050363215 98 else{
takapiasano 25:423050363215 99
takapiasano 25:423050363215 100 IO.setRedPower(0);
takapiasano 25:423050363215 101 IO.setGreenPower(0);
takapiasano 26:74ecbf9985e1 102 firstPointCounter = 0;
takapiasano 25:423050363215 103 }
takapiasano 25:423050363215 104
takapiasano 25:423050363215 105
takapiasano 26:74ecbf9985e1 106 */
takapiasano 26:74ecbf9985e1 107
takapiasano 26:74ecbf9985e1 108
takapiasano 26:74ecbf9985e1 109 //if(abs(vx)<0.001 || abs(vy) < 0.001)startSwitch = 1;
takapiasano 26:74ecbf9985e1 110
takapiasano 26:74ecbf9985e1 111 if(translated.size()>0 && startSwitch == 1) {
takapiasano 24:ab74d2018e6c 112
takapiasano 24:ab74d2018e6c 113 switch(rendererState) {
takapiasano 24:ab74d2018e6c 114
takapiasano 24:ab74d2018e6c 115 case NORMAL_POINT:
takapiasano 26:74ecbf9985e1 116 intvx += speedTimer.read_us()*vx;
takapiasano 26:74ecbf9985e1 117 intvy += speedTimer.read_us()*vy;
takapiasano 26:74ecbf9985e1 118 speedTimer.reset();
takapiasano 26:74ecbf9985e1 119
takapiasano 24:ab74d2018e6c 120 point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
takapiasano 24:ab74d2018e6c 121 transform(drawPoint); // transform it with the current speed and angle
takapiasano 24:ab74d2018e6c 122 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 25:423050363215 123 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 25:423050363215 124 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 21:4095a071724d 125
takapiasano 24:ab74d2018e6c 126 // move to the next point
takapiasano 24:ab74d2018e6c 127 currentPoints++;
takapiasano 24:ab74d2018e6c 128
takapiasano 24:ab74d2018e6c 129 //Should we change the state?
takapiasano 24:ab74d2018e6c 130 if(currentPoints >= translated[currentLetters].letpoints.size() ) {
takapiasano 24:ab74d2018e6c 131 rendererState=AFTER_LAST_POINT;
takapiasano 24:ab74d2018e6c 132 }
takapiasano 24:ab74d2018e6c 133 break;
hiromasaoku 18:6f86abfae754 134
takapiasano 24:ab74d2018e6c 135 case AFTER_LAST_POINT:
takapiasano 24:ab74d2018e6c 136 // just wait!
takapiasano 24:ab74d2018e6c 137 if (lastPointCounter<WAITING_LAST) {
takapiasano 24:ab74d2018e6c 138 IO.setRedPower(0);
takapiasano 25:423050363215 139 IO.setGreenPower(0);
takapiasano 24:ab74d2018e6c 140 lastPointCounter++;
takapiasano 24:ab74d2018e6c 141 }
takapiasano 24:ab74d2018e6c 142 else {
takapiasano 24:ab74d2018e6c 143 lastPointCounter=0;
takapiasano 24:ab74d2018e6c 144 currentPoints = 0;
takapiasano 24:ab74d2018e6c 145 // switch the laser off and move to the first point of the next letter:
takapiasano 24:ab74d2018e6c 146
takapiasano 24:ab74d2018e6c 147 currentLetters++;
takapiasano 24:ab74d2018e6c 148 if(currentLetters >= translated.size()) {
takapiasano 24:ab74d2018e6c 149 currentLetters = 0;
takapiasano 26:74ecbf9985e1 150 startSwitch=0;
takapiasano 26:74ecbf9985e1 151 intvx = intvy =0;
takapiasano 26:74ecbf9985e1 152
takapiasano 26:74ecbf9985e1 153
takapiasano 24:ab74d2018e6c 154 }
takapiasano 24:ab74d2018e6c 155 rendererState=FIRST_POINT;
takapiasano 26:74ecbf9985e1 156
takapiasano 24:ab74d2018e6c 157 }
takapiasano 24:ab74d2018e6c 158 break;
takapiasano 24:ab74d2018e6c 159
takapiasano 24:ab74d2018e6c 160 case FIRST_POINT:
takapiasano 26:74ecbf9985e1 161
takapiasano 24:ab74d2018e6c 162 if (firstPointCounter<WAITING_FIRST) {
takapiasano 24:ab74d2018e6c 163 firstPointCounter++;
takapiasano 24:ab74d2018e6c 164
takapiasano 24:ab74d2018e6c 165 // show first point!
takapiasano 24:ab74d2018e6c 166 point2dl drawPoint=translated[currentLetters].letpoints[0];
takapiasano 24:ab74d2018e6c 167 transform(drawPoint); // transform it with the current speed and angle
takapiasano 24:ab74d2018e6c 168 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 26:74ecbf9985e1 169 speedTimer.reset();
takapiasano 26:74ecbf9985e1 170
takapiasano 26:74ecbf9985e1 171
takapiasano 24:ab74d2018e6c 172 //IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 24:ab74d2018e6c 173
takapiasano 24:ab74d2018e6c 174 } else {
takapiasano 24:ab74d2018e6c 175 firstPointCounter=0;
takapiasano 24:ab74d2018e6c 176 currentPoints=1;
takapiasano 24:ab74d2018e6c 177 rendererState=NORMAL_POINT;
takapiasano 24:ab74d2018e6c 178 }
takapiasano 24:ab74d2018e6c 179 break;
takapiasano 24:ab74d2018e6c 180 }
hiromasaoku 20:8475768fc2f7 181 }
takapiasano 26:74ecbf9985e1 182
takapiasano 25:423050363215 183 }
hiromasaoku 18:6f86abfae754 184
takapiasano 24:ab74d2018e6c 185 void render::transform(point2dl& mypoint) {
takapiasano 24:ab74d2018e6c 186 rotation(mypoint);
takapiasano 24:ab74d2018e6c 187 if(shearingSwitch == 1) shearing(mypoint);
takapiasano 25:423050363215 188 }
hiromasaoku 16:6dd2e60bc5bc 189