Hiromasa Oku
/
linearMirrorMotion1017
this version 10/17
Fork of linearMirrorMotion by
renderclass.cpp@20:8475768fc2f7, 2013-05-31 (annotated)
- Committer:
- hiromasaoku
- Date:
- Fri May 31 06:32:07 2013 +0000
- Revision:
- 20:8475768fc2f7
- Parent:
- 19:8e9fe7d25b9c
for sharing
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 | { |
hiromasaoku | 20:8475768fc2f7 | 12 | dataBefore.x = dataBefore.x - speed * cos(angle+PI/2)*speedTimer.read_us()/400; |
hiromasaoku | 20:8475768fc2f7 | 13 | dataBefore.y = dataBefore.y - speed * sin(angle+PI/2)*speedTimer.read_us()/400; |
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; |
hiromasaoku | 20:8475768fc2f7 | 19 | dataBefore.x = 1800 * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y; |
hiromasaoku | 20:8475768fc2f7 | 20 | dataBefore.y = 1800 * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y; |
hiromasaoku | 16:6dd2e60bc5bc | 21 | } |
hiromasaoku | 16:6dd2e60bc5bc | 22 | //---------------------------------------------------------------------------------- |
hiromasaoku | 16:6dd2e60bc5bc | 23 | |
hiromasaoku | 18:6f86abfae754 | 24 | void render::startRender() |
hiromasaoku | 18:6f86abfae754 | 25 | { |
hiromasaoku | 20:8475768fc2f7 | 26 | speedTimer.start(); |
hiromasaoku | 19:8e9fe7d25b9c | 27 | renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); |
hiromasaoku | 19:8e9fe7d25b9c | 28 | pc.printf("render started!\n"); |
hiromasaoku | 16:6dd2e60bc5bc | 29 | } |
hiromasaoku | 16:6dd2e60bc5bc | 30 | |
hiromasaoku | 18:6f86abfae754 | 31 | void render::stopRender() |
hiromasaoku | 18:6f86abfae754 | 32 | { |
hiromasaoku | 16:6dd2e60bc5bc | 33 | renderTimer.detach(); |
hiromasaoku | 19:8e9fe7d25b9c | 34 | translated.clear(); |
hiromasaoku | 19:8e9fe7d25b9c | 35 | currentLetters=0; |
hiromasaoku | 19:8e9fe7d25b9c | 36 | currentPoints=0; |
hiromasaoku | 16:6dd2e60bc5bc | 37 | } |
hiromasaoku | 16:6dd2e60bc5bc | 38 | |
hiromasaoku | 18:6f86abfae754 | 39 | void render::setRender(vector<letter> *p) |
hiromasaoku | 18:6f86abfae754 | 40 | { |
hiromasaoku | 16:6dd2e60bc5bc | 41 | ptext = p; |
hiromasaoku | 19:8e9fe7d25b9c | 42 | pc.printf("Size of text to render: %d/n", (*ptext).size() ); |
hiromasaoku | 16:6dd2e60bc5bc | 43 | //for(int i=0; i!=(*ptext).size(); i++){ |
hiromasaoku | 18:6f86abfae754 | 44 | for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) { |
hiromasaoku | 16:6dd2e60bc5bc | 45 | translated.push_back(*itr); |
hiromasaoku | 16:6dd2e60bc5bc | 46 | } //copy the liblary to the buffer. |
hiromasaoku | 19:8e9fe7d25b9c | 47 | |
hiromasaoku | 19:8e9fe7d25b9c | 48 | |
hiromasaoku | 18:6f86abfae754 | 49 | currentLetters=0; |
hiromasaoku | 18:6f86abfae754 | 50 | currentPoints=0; |
hiromasaoku | 20:8475768fc2f7 | 51 | shearingSwitch = 1; |
hiromasaoku | 20:8475768fc2f7 | 52 | |
hiromasaoku | 16:6dd2e60bc5bc | 53 | } |
hiromasaoku | 16:6dd2e60bc5bc | 54 | |
hiromasaoku | 18:6f86abfae754 | 55 | |
hiromasaoku | 19:8e9fe7d25b9c | 56 | void render::updateSpeed(float gspeed, float gangle){ |
hiromasaoku | 19:8e9fe7d25b9c | 57 | speed = gspeed; |
hiromasaoku | 19:8e9fe7d25b9c | 58 | angle = gangle; |
hiromasaoku | 19:8e9fe7d25b9c | 59 | |
hiromasaoku | 19:8e9fe7d25b9c | 60 | //speed=sqrt(vx*vx+vy*vy);//*factorSpeed; |
hiromasaoku | 19:8e9fe7d25b9c | 61 | //angle=atan2(vy,vx); |
hiromasaoku | 18:6f86abfae754 | 62 | } |
hiromasaoku | 20:8475768fc2f7 | 63 | |
hiromasaoku | 20:8475768fc2f7 | 64 | int stopcounter=100; |
hiromasaoku | 20:8475768fc2f7 | 65 | |
hiromasaoku | 18:6f86abfae754 | 66 | void render::draw() |
hiromasaoku | 18:6f86abfae754 | 67 | { |
hiromasaoku | 19:8e9fe7d25b9c | 68 | if(translated.size()>0){ |
hiromasaoku | 20:8475768fc2f7 | 69 | if(stopcounter == 99) speedTimer.reset(); |
hiromasaoku | 20:8475768fc2f7 | 70 | if(stopcounter==100){ |
hiromasaoku | 20:8475768fc2f7 | 71 | |
hiromasaoku | 18:6f86abfae754 | 72 | point2dl drawPoint=translated[currentLetters].letpoints[currentPoints]; |
hiromasaoku | 18:6f86abfae754 | 73 | transform(drawPoint); // transform it with the current speed and angle |
hiromasaoku | 19:8e9fe7d25b9c | 74 | //IO.setRedPower(drawPoint.laserSwitch); |
hiromasaoku | 20:8475768fc2f7 | 75 | IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y); |
hiromasaoku | 19:8e9fe7d25b9c | 76 | |
hiromasaoku | 19:8e9fe7d25b9c | 77 | |
hiromasaoku | 19:8e9fe7d25b9c | 78 | if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch); |
hiromasaoku | 20:8475768fc2f7 | 79 | else IO.setRedPower(0); |
hiromasaoku | 18:6f86abfae754 | 80 | |
hiromasaoku | 16:6dd2e60bc5bc | 81 | currentPoints++; |
hiromasaoku | 20:8475768fc2f7 | 82 | } |
hiromasaoku | 20:8475768fc2f7 | 83 | else stopcounter++; |
hiromasaoku | 19:8e9fe7d25b9c | 84 | |
hiromasaoku | 19:8e9fe7d25b9c | 85 | if(currentPoints >= translated[currentLetters].letpoints.size() ) { |
hiromasaoku | 20:8475768fc2f7 | 86 | if(stopcounter == 100) stopcounter = 0; |
hiromasaoku | 20:8475768fc2f7 | 87 | else if(stopcounter == 0){ |
hiromasaoku | 20:8475768fc2f7 | 88 | renderTimer.detach(); |
hiromasaoku | 20:8475768fc2f7 | 89 | } |
hiromasaoku | 20:8475768fc2f7 | 90 | //wait_us(RENDER_INTERVAL); |
hiromasaoku | 20:8475768fc2f7 | 91 | else if(stopcounter == 1){ |
hiromasaoku | 20:8475768fc2f7 | 92 | IO.setRedPower(0); |
hiromasaoku | 20:8475768fc2f7 | 93 | //wait_us(RENDER_INTERVAL); |
hiromasaoku | 16:6dd2e60bc5bc | 94 | currentLetters++; |
hiromasaoku | 16:6dd2e60bc5bc | 95 | currentPoints = 0; |
hiromasaoku | 19:8e9fe7d25b9c | 96 | renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); |
hiromasaoku | 20:8475768fc2f7 | 97 | speedTimer.reset(); |
hiromasaoku | 20:8475768fc2f7 | 98 | } |
hiromasaoku | 16:6dd2e60bc5bc | 99 | } |
hiromasaoku | 19:8e9fe7d25b9c | 100 | if(currentLetters >= translated.size()) { |
hiromasaoku | 16:6dd2e60bc5bc | 101 | currentLetters = 0; |
hiromasaoku | 16:6dd2e60bc5bc | 102 | currentPoints = 0; |
hiromasaoku | 19:8e9fe7d25b9c | 103 | renderTimer.detach(); |
hiromasaoku | 20:8475768fc2f7 | 104 | //wait_us(RENDER_INTERVAL); |
hiromasaoku | 19:8e9fe7d25b9c | 105 | IO.setRedPower(0); |
hiromasaoku | 20:8475768fc2f7 | 106 | //wait_us(RENDER_INTERVAL*200); |
hiromasaoku | 19:8e9fe7d25b9c | 107 | renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); |
hiromasaoku | 20:8475768fc2f7 | 108 | speedTimer.reset(); |
hiromasaoku | 20:8475768fc2f7 | 109 | stopcounter = -200; |
hiromasaoku | 19:8e9fe7d25b9c | 110 | } |
hiromasaoku | 16:6dd2e60bc5bc | 111 | } |
hiromasaoku | 18:6f86abfae754 | 112 | } |
hiromasaoku | 18:6f86abfae754 | 113 | |
hiromasaoku | 18:6f86abfae754 | 114 | void render::transform(point2dl& mypoint) |
hiromasaoku | 18:6f86abfae754 | 115 | { |
hiromasaoku | 18:6f86abfae754 | 116 | rotation(mypoint); |
hiromasaoku | 20:8475768fc2f7 | 117 | if(shearingSwitch == 1) shearing(mypoint); |
hiromasaoku | 16:6dd2e60bc5bc | 118 | } |
hiromasaoku | 16:6dd2e60bc5bc | 119 |