Takashi Asano
/
linearMirrorMotion1017
sotsuron
Fork of linearMirrorMotion1017 by
renderclass.cpp@23:ce375ac0ddfe, 2013-07-01 (annotated)
- Committer:
- takapiasano
- Date:
- Mon Jul 01 04:08:17 2013 +0000
- Revision:
- 23:ce375ac0ddfe
- Parent:
- 22:e86d63dfbbe1
circle demo
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 | 23:ce375ac0ddfe | 12 | dataBefore.x = dataBefore.x - vx * speedTimer.read_us()/1500000; //2000000;//dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800; |
takapiasano | 23:ce375ac0ddfe | 13 | dataBefore.y = dataBefore.y - vy * speedTimer.read_us()/1500000;//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 | 23:ce375ac0ddfe | 19 | dataBefore.x = radious * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y;//x + abs((int)angle) % (2 * (CENTER_AD_MIRROR_X-200)) - CENTER_AD_MIRROR_X+200;// |
takapiasano | 23:ce375ac0ddfe | 20 | dataBefore.y = radious * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;//-dataBefore.y;//radious * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;// |
takapiasano | 21:4095a071724d | 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(); |
hiromasaoku | 19:8e9fe7d25b9c | 35 | translated.clear(); |
hiromasaoku | 19:8e9fe7d25b9c | 36 | currentLetters=0; |
hiromasaoku | 19:8e9fe7d25b9c | 37 | currentPoints=0; |
hiromasaoku | 16:6dd2e60bc5bc | 38 | } |
hiromasaoku | 16:6dd2e60bc5bc | 39 | |
hiromasaoku | 18:6f86abfae754 | 40 | void render::setRender(vector<letter> *p) |
hiromasaoku | 18:6f86abfae754 | 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++){ |
hiromasaoku | 18:6f86abfae754 | 45 | for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) { |
hiromasaoku | 16:6dd2e60bc5bc | 46 | translated.push_back(*itr); |
hiromasaoku | 16:6dd2e60bc5bc | 47 | } //copy the liblary to the buffer. |
takapiasano | 21:4095a071724d | 48 | |
takapiasano | 21:4095a071724d | 49 | |
hiromasaoku | 18:6f86abfae754 | 50 | currentLetters=0; |
hiromasaoku | 18:6f86abfae754 | 51 | currentPoints=0; |
hiromasaoku | 20:8475768fc2f7 | 52 | shearingSwitch = 1; |
takapiasano | 22:e86d63dfbbe1 | 53 | radious = 1800; |
hiromasaoku | 16:6dd2e60bc5bc | 54 | } |
hiromasaoku | 16:6dd2e60bc5bc | 55 | |
hiromasaoku | 18:6f86abfae754 | 56 | |
takapiasano | 22:e86d63dfbbe1 | 57 | void render::updateSpeed(float gspeed, float gangle, float vvx, float vvy) |
takapiasano | 21:4095a071724d | 58 | { |
hiromasaoku | 19:8e9fe7d25b9c | 59 | speed = gspeed; |
hiromasaoku | 19:8e9fe7d25b9c | 60 | angle = gangle; |
takapiasano | 21:4095a071724d | 61 | |
takapiasano | 23:ce375ac0ddfe | 62 | vx =gspeed * radious * cos(angle+PI/2);// vvx;// |
takapiasano | 23:ce375ac0ddfe | 63 | vy =gspeed * radious * sin(angle+PI/2);// vvy;// |
takapiasano | 22:e86d63dfbbe1 | 64 | |
takapiasano | 22:e86d63dfbbe1 | 65 | |
hiromasaoku | 19:8e9fe7d25b9c | 66 | //speed=sqrt(vx*vx+vy*vy);//*factorSpeed; |
hiromasaoku | 19:8e9fe7d25b9c | 67 | //angle=atan2(vy,vx); |
hiromasaoku | 18:6f86abfae754 | 68 | } |
hiromasaoku | 20:8475768fc2f7 | 69 | |
hiromasaoku | 18:6f86abfae754 | 70 | void render::draw() |
hiromasaoku | 18:6f86abfae754 | 71 | { |
takapiasano | 21:4095a071724d | 72 | if(translated.size()>0) { |
takapiasano | 21:4095a071724d | 73 | point2dl drawPoint=translated[currentLetters].letpoints[currentPoints]; |
takapiasano | 21:4095a071724d | 74 | transform(drawPoint); // transform it with the current speed and angle |
takapiasano | 21:4095a071724d | 75 | IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y); |
takapiasano | 21:4095a071724d | 76 | |
takapiasano | 22:e86d63dfbbe1 | 77 | |
takapiasano | 22:e86d63dfbbe1 | 78 | |
takapiasano | 21:4095a071724d | 79 | ////laser switch |
takapiasano | 21:4095a071724d | 80 | if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch); |
takapiasano | 21:4095a071724d | 81 | else IO.setRedPower(0); |
takapiasano | 21:4095a071724d | 82 | |
takapiasano | 21:4095a071724d | 83 | currentPoints++; |
hiromasaoku | 18:6f86abfae754 | 84 | |
takapiasano | 21:4095a071724d | 85 | if(currentPoints >= translated[currentLetters].letpoints.size() ) { |
takapiasano | 21:4095a071724d | 86 | currentLetters++; |
takapiasano | 21:4095a071724d | 87 | currentPoints = 0; |
takapiasano | 21:4095a071724d | 88 | //renderTimer.detach(); |
takapiasano | 21:4095a071724d | 89 | |
takapiasano | 21:4095a071724d | 90 | wait_us(RENDER_INTERVAL); |
takapiasano | 21:4095a071724d | 91 | IO.setRedPower(0); |
takapiasano | 21:4095a071724d | 92 | //wait_us(RENDER_INTERVAL); |
takapiasano | 21:4095a071724d | 93 | |
takapiasano | 21:4095a071724d | 94 | //renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); |
takapiasano | 21:4095a071724d | 95 | speedTimer.reset(); |
takapiasano | 21:4095a071724d | 96 | //} |
hiromasaoku | 20:8475768fc2f7 | 97 | } |
takapiasano | 21:4095a071724d | 98 | if(currentLetters >= translated.size()) { |
takapiasano | 21:4095a071724d | 99 | currentLetters = 0; |
takapiasano | 21:4095a071724d | 100 | currentPoints = 0; |
takapiasano | 22:e86d63dfbbe1 | 101 | //renderTimer.detach(); |
takapiasano | 21:4095a071724d | 102 | //wait_us(RENDER_INTERVAL); |
takapiasano | 21:4095a071724d | 103 | IO.setRedPower(0); |
takapiasano | 21:4095a071724d | 104 | //wait_us(RENDER_INTERVAL*20); |
takapiasano | 22:e86d63dfbbe1 | 105 | //renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); |
takapiasano | 21:4095a071724d | 106 | speedTimer.reset(); |
hiromasaoku | 20:8475768fc2f7 | 107 | } |
hiromasaoku | 16:6dd2e60bc5bc | 108 | } |
hiromasaoku | 18:6f86abfae754 | 109 | } |
hiromasaoku | 18:6f86abfae754 | 110 | |
hiromasaoku | 18:6f86abfae754 | 111 | void render::transform(point2dl& mypoint) |
hiromasaoku | 18:6f86abfae754 | 112 | { |
hiromasaoku | 18:6f86abfae754 | 113 | rotation(mypoint); |
hiromasaoku | 20:8475768fc2f7 | 114 | if(shearingSwitch == 1) shearing(mypoint); |
hiromasaoku | 16:6dd2e60bc5bc | 115 | } |
hiromasaoku | 16:6dd2e60bc5bc | 116 |