Takashi Asano
/
linearMirrorMotion1017
sotsuron
Fork of linearMirrorMotion1017 by
renderclass.cpp@25:423050363215, 2013-07-03 (annotated)
- Committer:
- takapiasano
- Date:
- Wed Jul 03 07:43:48 2013 +0000
- Revision:
- 25:423050363215
- Parent:
- 24:ab74d2018e6c
- Child:
- 26:74ecbf9985e1
Tenmetsu for Saccade mirror
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:423050363215 | 12 | dataBefore.x = dataBefore.x/4.0 - vx * speedTimer.read_us()/100; //2000000;//dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800; |
takapiasano | 25:423050363215 | 13 | dataBefore.y = dataBefore.y/4.0 - vy * speedTimer.read_us()/2000000;//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 | 25:423050363215 | 19 | dataBefore.x = 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;// |
takapiasano | 22:e86d63dfbbe1 | 20 | dataBefore.y = -dataBefore.y;//radious * sin(angle) - cos(angle)*x - sin(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"); |
hiromasaoku | 16:6dd2e60bc5bc | 30 | } |
hiromasaoku | 16:6dd2e60bc5bc | 31 | |
hiromasaoku | 18:6f86abfae754 | 32 | void render::stopRender() |
hiromasaoku | 18:6f86abfae754 | 33 | { |
hiromasaoku | 16:6dd2e60bc5bc | 34 | renderTimer.detach(); |
takapiasano | 24:ab74d2018e6c | 35 | speedTimer.stop(); |
hiromasaoku | 16:6dd2e60bc5bc | 36 | } |
hiromasaoku | 16:6dd2e60bc5bc | 37 | |
hiromasaoku | 18:6f86abfae754 | 38 | void render::setRender(vector<letter> *p) |
hiromasaoku | 18:6f86abfae754 | 39 | { |
takapiasano | 24:ab74d2018e6c | 40 | translated.clear(); |
takapiasano | 24:ab74d2018e6c | 41 | |
hiromasaoku | 16:6dd2e60bc5bc | 42 | ptext = p; |
hiromasaoku | 19:8e9fe7d25b9c | 43 | pc.printf("Size of text to render: %d/n", (*ptext).size() ); |
hiromasaoku | 16:6dd2e60bc5bc | 44 | //for(int i=0; i!=(*ptext).size(); i++){ |
takapiasano | 24:ab74d2018e6c | 45 | int count=0; |
hiromasaoku | 18:6f86abfae754 | 46 | for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) { |
takapiasano | 24:ab74d2018e6c | 47 | letter translatedLetter; |
takapiasano | 24:ab74d2018e6c | 48 | for(int i=0; i<(*itr).letpoints.size(); i++) { |
takapiasano | 24:ab74d2018e6c | 49 | point2dl tranPoint; |
takapiasano | 24:ab74d2018e6c | 50 | tranPoint.x=itr->letpoints[i].x+560*count; |
takapiasano | 24:ab74d2018e6c | 51 | tranPoint.y=itr->letpoints[i].y; |
takapiasano | 24:ab74d2018e6c | 52 | tranPoint.laserSwitch=itr->letpoints[i].laserSwitch; |
takapiasano | 24:ab74d2018e6c | 53 | translatedLetter.letpoints.push_back(tranPoint); |
takapiasano | 24:ab74d2018e6c | 54 | |
hiromasaoku | 16:6dd2e60bc5bc | 55 | } //copy the liblary to the buffer. |
takapiasano | 24:ab74d2018e6c | 56 | translated.push_back(translatedLetter); |
takapiasano | 24:ab74d2018e6c | 57 | count++; |
takapiasano | 24:ab74d2018e6c | 58 | } |
takapiasano | 21:4095a071724d | 59 | |
takapiasano | 24:ab74d2018e6c | 60 | shearingSwitch = 1; |
takapiasano | 24:ab74d2018e6c | 61 | radious = 1800; |
takapiasano | 21:4095a071724d | 62 | |
hiromasaoku | 18:6f86abfae754 | 63 | currentLetters=0; |
takapiasano | 24:ab74d2018e6c | 64 | |
takapiasano | 24:ab74d2018e6c | 65 | firstPointCounter=0; |
takapiasano | 24:ab74d2018e6c | 66 | lastPointCounter=0; |
takapiasano | 24:ab74d2018e6c | 67 | |
takapiasano | 24:ab74d2018e6c | 68 | rendererState=FIRST_POINT; |
hiromasaoku | 16:6dd2e60bc5bc | 69 | } |
hiromasaoku | 16:6dd2e60bc5bc | 70 | |
hiromasaoku | 18:6f86abfae754 | 71 | |
takapiasano | 22:e86d63dfbbe1 | 72 | void render::updateSpeed(float gspeed, float gangle, float vvx, float vvy) |
takapiasano | 21:4095a071724d | 73 | { |
hiromasaoku | 19:8e9fe7d25b9c | 74 | speed = gspeed; |
hiromasaoku | 19:8e9fe7d25b9c | 75 | angle = gangle; |
takapiasano | 21:4095a071724d | 76 | |
takapiasano | 22:e86d63dfbbe1 | 77 | vx = vvx;//gspeed * radious * cos(angle+PI/2); |
takapiasano | 22:e86d63dfbbe1 | 78 | vy = vvy;//gspeed * radious * sin(angle+PI/2); |
takapiasano | 22:e86d63dfbbe1 | 79 | |
takapiasano | 22:e86d63dfbbe1 | 80 | |
hiromasaoku | 19:8e9fe7d25b9c | 81 | //speed=sqrt(vx*vx+vy*vy);//*factorSpeed; |
hiromasaoku | 19:8e9fe7d25b9c | 82 | //angle=atan2(vy,vx); |
hiromasaoku | 18:6f86abfae754 | 83 | } |
hiromasaoku | 20:8475768fc2f7 | 84 | |
hiromasaoku | 18:6f86abfae754 | 85 | void render::draw() |
hiromasaoku | 18:6f86abfae754 | 86 | { |
takapiasano | 25:423050363215 | 87 | if(firstPointCounter == 0){ |
takapiasano | 25:423050363215 | 88 | if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); |
takapiasano | 25:423050363215 | 89 | if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); |
takapiasano | 25:423050363215 | 90 | firstPointCounter = 1; |
takapiasano | 25:423050363215 | 91 | } |
takapiasano | 25:423050363215 | 92 | else{ |
takapiasano | 25:423050363215 | 93 | |
takapiasano | 25:423050363215 | 94 | IO.setRedPower(0); |
takapiasano | 25:423050363215 | 95 | IO.setGreenPower(0); |
takapiasano | 25:423050363215 | 96 | firstPointCounter = 0 |
takapiasano | 25:423050363215 | 97 | } |
takapiasano | 25:423050363215 | 98 | |
takapiasano | 25:423050363215 | 99 | |
takapiasano | 25:423050363215 | 100 | /* |
takapiasano | 21:4095a071724d | 101 | if(translated.size()>0) { |
takapiasano | 24:ab74d2018e6c | 102 | |
takapiasano | 24:ab74d2018e6c | 103 | switch(rendererState) { |
takapiasano | 24:ab74d2018e6c | 104 | |
takapiasano | 24:ab74d2018e6c | 105 | case NORMAL_POINT: |
takapiasano | 24:ab74d2018e6c | 106 | point2dl drawPoint=translated[currentLetters].letpoints[currentPoints]; |
takapiasano | 24:ab74d2018e6c | 107 | transform(drawPoint); // transform it with the current speed and angle |
takapiasano | 24:ab74d2018e6c | 108 | IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y); |
takapiasano | 25:423050363215 | 109 | if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); |
takapiasano | 25:423050363215 | 110 | if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); |
takapiasano | 21:4095a071724d | 111 | |
takapiasano | 24:ab74d2018e6c | 112 | // move to the next point |
takapiasano | 24:ab74d2018e6c | 113 | currentPoints++; |
takapiasano | 24:ab74d2018e6c | 114 | |
takapiasano | 24:ab74d2018e6c | 115 | //Should we change the state? |
takapiasano | 24:ab74d2018e6c | 116 | if(currentPoints >= translated[currentLetters].letpoints.size() ) { |
takapiasano | 24:ab74d2018e6c | 117 | rendererState=AFTER_LAST_POINT; |
takapiasano | 24:ab74d2018e6c | 118 | } |
takapiasano | 24:ab74d2018e6c | 119 | break; |
hiromasaoku | 18:6f86abfae754 | 120 | |
takapiasano | 24:ab74d2018e6c | 121 | case AFTER_LAST_POINT: |
takapiasano | 24:ab74d2018e6c | 122 | // just wait! |
takapiasano | 24:ab74d2018e6c | 123 | if (lastPointCounter<WAITING_LAST) { |
takapiasano | 24:ab74d2018e6c | 124 | IO.setRedPower(0); |
takapiasano | 25:423050363215 | 125 | IO.setGreenPower(0); |
takapiasano | 24:ab74d2018e6c | 126 | lastPointCounter++; |
takapiasano | 24:ab74d2018e6c | 127 | } |
takapiasano | 24:ab74d2018e6c | 128 | else { |
takapiasano | 24:ab74d2018e6c | 129 | lastPointCounter=0; |
takapiasano | 24:ab74d2018e6c | 130 | currentPoints = 0; |
takapiasano | 24:ab74d2018e6c | 131 | // switch the laser off and move to the first point of the next letter: |
takapiasano | 24:ab74d2018e6c | 132 | |
takapiasano | 24:ab74d2018e6c | 133 | currentLetters++; |
takapiasano | 24:ab74d2018e6c | 134 | if(currentLetters >= translated.size()) { |
takapiasano | 24:ab74d2018e6c | 135 | currentLetters = 0; |
takapiasano | 24:ab74d2018e6c | 136 | speedTimer.reset(); |
takapiasano | 24:ab74d2018e6c | 137 | } |
takapiasano | 24:ab74d2018e6c | 138 | rendererState=FIRST_POINT; |
takapiasano | 24:ab74d2018e6c | 139 | } |
takapiasano | 24:ab74d2018e6c | 140 | break; |
takapiasano | 24:ab74d2018e6c | 141 | |
takapiasano | 24:ab74d2018e6c | 142 | case FIRST_POINT: |
takapiasano | 24:ab74d2018e6c | 143 | if (firstPointCounter<WAITING_FIRST) { |
takapiasano | 24:ab74d2018e6c | 144 | firstPointCounter++; |
takapiasano | 24:ab74d2018e6c | 145 | |
takapiasano | 24:ab74d2018e6c | 146 | // show first point! |
takapiasano | 24:ab74d2018e6c | 147 | point2dl drawPoint=translated[currentLetters].letpoints[0]; |
takapiasano | 24:ab74d2018e6c | 148 | transform(drawPoint); // transform it with the current speed and angle |
takapiasano | 24:ab74d2018e6c | 149 | IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y); |
takapiasano | 24:ab74d2018e6c | 150 | //IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); |
takapiasano | 24:ab74d2018e6c | 151 | |
takapiasano | 24:ab74d2018e6c | 152 | } else { |
takapiasano | 24:ab74d2018e6c | 153 | firstPointCounter=0; |
takapiasano | 24:ab74d2018e6c | 154 | currentPoints=1; |
takapiasano | 24:ab74d2018e6c | 155 | rendererState=NORMAL_POINT; |
takapiasano | 24:ab74d2018e6c | 156 | } |
takapiasano | 24:ab74d2018e6c | 157 | break; |
takapiasano | 24:ab74d2018e6c | 158 | } |
hiromasaoku | 20:8475768fc2f7 | 159 | } |
takapiasano | 25:423050363215 | 160 | */ |
takapiasano | 25:423050363215 | 161 | } |
hiromasaoku | 18:6f86abfae754 | 162 | |
takapiasano | 24:ab74d2018e6c | 163 | void render::transform(point2dl& mypoint) { |
takapiasano | 24:ab74d2018e6c | 164 | rotation(mypoint); |
takapiasano | 24:ab74d2018e6c | 165 | if(shearingSwitch == 1) shearing(mypoint); |
takapiasano | 25:423050363215 | 166 | } |
hiromasaoku | 16:6dd2e60bc5bc | 167 |