sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
hiromasaoku
Date:
Fri May 24 06:37:58 2013 +0000
Revision:
19:8e9fe7d25b9c
Parent:
18:6f86abfae754
Child:
20:8475768fc2f7
moves almost successfully  \(^u^)/

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 {
hiromasaoku 18:6f86abfae754 12 dataBefore.x = dataBefore.x ;//+ speed * cos(angle) * timer_v.read_us()/st/1000;
hiromasaoku 18:6f86abfae754 13 dataBefore.y = dataBefore.y ;//+ speed * sin(angle) * timer_v.read_us()/st/1000;
hiromasaoku 18:6f86abfae754 14
hiromasaoku 16:6dd2e60bc5bc 15 }
hiromasaoku 16:6dd2e60bc5bc 16
hiromasaoku 18:6f86abfae754 17 inline void render::rotation(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 18 {
hiromasaoku 18:6f86abfae754 19 int x=dataBefore.x;
hiromasaoku 18:6f86abfae754 20 dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;
hiromasaoku 18:6f86abfae754 21 dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
hiromasaoku 16:6dd2e60bc5bc 22 }
hiromasaoku 16:6dd2e60bc5bc 23 //----------------------------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 24
hiromasaoku 18:6f86abfae754 25 void render::startRender()
hiromasaoku 18:6f86abfae754 26 {
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 19:8e9fe7d25b9c 46 pc.printf("moving...." );
hiromasaoku 16:6dd2e60bc5bc 47 } //copy the liblary to the buffer.
hiromasaoku 19:8e9fe7d25b9c 48
hiromasaoku 19:8e9fe7d25b9c 49
hiromasaoku 18:6f86abfae754 50 currentLetters=0;
hiromasaoku 18:6f86abfae754 51 currentPoints=0;
hiromasaoku 16:6dd2e60bc5bc 52 }
hiromasaoku 16:6dd2e60bc5bc 53
hiromasaoku 18:6f86abfae754 54
hiromasaoku 19:8e9fe7d25b9c 55 void render::updateSpeed(float gspeed, float gangle){
hiromasaoku 19:8e9fe7d25b9c 56 speed = gspeed;
hiromasaoku 19:8e9fe7d25b9c 57 angle = gangle;
hiromasaoku 19:8e9fe7d25b9c 58
hiromasaoku 19:8e9fe7d25b9c 59 //speed=sqrt(vx*vx+vy*vy);//*factorSpeed;
hiromasaoku 19:8e9fe7d25b9c 60 //angle=atan2(vy,vx);
hiromasaoku 18:6f86abfae754 61 }
hiromasaoku 19:8e9fe7d25b9c 62 float t=0;
hiromasaoku 18:6f86abfae754 63 void render::draw()
hiromasaoku 18:6f86abfae754 64 {
hiromasaoku 19:8e9fe7d25b9c 65 if(translated.size()>0){
hiromasaoku 18:6f86abfae754 66 point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
hiromasaoku 18:6f86abfae754 67 transform(drawPoint); // transform it with the current speed and angle
hiromasaoku 19:8e9fe7d25b9c 68 pc.printf("%d, %d, %d \n" , (int)drawPoint.x, (int)drawPoint.y, (int)drawPoint.laserSwitch);
hiromasaoku 19:8e9fe7d25b9c 69 //IO.setRedPower(drawPoint.laserSwitch);
hiromasaoku 19:8e9fe7d25b9c 70 IO.writeOutXY(CENTER_AD_MIRROR_X+ 4*(int)drawPoint.x , CENTER_AD_MIRROR_Y - 4*(int)drawPoint.y);
hiromasaoku 19:8e9fe7d25b9c 71
hiromasaoku 19:8e9fe7d25b9c 72
hiromasaoku 19:8e9fe7d25b9c 73 if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch);
hiromasaoku 19:8e9fe7d25b9c 74 else IO.setRedPower(0); ///laserswitch txt library needs to rewrite..........?\(>o<)/?
hiromasaoku 18:6f86abfae754 75
hiromasaoku 16:6dd2e60bc5bc 76 currentPoints++;
hiromasaoku 19:8e9fe7d25b9c 77
hiromasaoku 19:8e9fe7d25b9c 78 if(currentPoints >= translated[currentLetters].letpoints.size() ) {
hiromasaoku 16:6dd2e60bc5bc 79 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 80 currentPoints = 0;
hiromasaoku 19:8e9fe7d25b9c 81
hiromasaoku 19:8e9fe7d25b9c 82 renderTimer.detach();
hiromasaoku 19:8e9fe7d25b9c 83 wait_us(RENDER_INTERVAL);
hiromasaoku 19:8e9fe7d25b9c 84 IO.setRedPower(0);
hiromasaoku 19:8e9fe7d25b9c 85 wait_us(RENDER_INTERVAL*40);
hiromasaoku 19:8e9fe7d25b9c 86 renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
hiromasaoku 16:6dd2e60bc5bc 87 }
hiromasaoku 19:8e9fe7d25b9c 88 if(currentLetters >= translated.size()) {
hiromasaoku 16:6dd2e60bc5bc 89 currentLetters = 0;
hiromasaoku 16:6dd2e60bc5bc 90 currentPoints = 0;
hiromasaoku 19:8e9fe7d25b9c 91 renderTimer.detach();
hiromasaoku 19:8e9fe7d25b9c 92 wait_us(RENDER_INTERVAL);
hiromasaoku 19:8e9fe7d25b9c 93 IO.setRedPower(0);
hiromasaoku 19:8e9fe7d25b9c 94 wait_us(RENDER_INTERVAL*20);
hiromasaoku 19:8e9fe7d25b9c 95 renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
hiromasaoku 19:8e9fe7d25b9c 96 }
hiromasaoku 16:6dd2e60bc5bc 97 }
hiromasaoku 18:6f86abfae754 98 }
hiromasaoku 18:6f86abfae754 99
hiromasaoku 18:6f86abfae754 100 void render::transform(point2dl& mypoint)
hiromasaoku 18:6f86abfae754 101 {
hiromasaoku 18:6f86abfae754 102 rotation(mypoint);
hiromasaoku 18:6f86abfae754 103 shearing(mypoint);
hiromasaoku 16:6dd2e60bc5bc 104 }
hiromasaoku 16:6dd2e60bc5bc 105
hiromasaoku 18:6f86abfae754 106 /*
hiromasaoku 18:6f86abfae754 107 void render::translating(float speed, float angle) //DO when get the speed and angle data.
hiromasaoku 18:6f86abfae754 108 {
hiromasaoku 18:6f86abfae754 109 for (int i = 0; i > 10; i++) {
hiromasaoku 16:6dd2e60bc5bc 110 int j=0;
hiromasaoku 18:6f86abfae754 111 if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()) {
hiromasaoku 16:6dd2e60bc5bc 112 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 113 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 114 j=0;
hiromasaoku 16:6dd2e60bc5bc 115 }
hiromasaoku 18:6f86abfae754 116 if(currentLetters > (*ptext).size()) break;
hiromasaoku 18:6f86abfae754 117
hiromasaoku 18:6f86abfae754 118 point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints]);
hiromasaoku 18:6f86abfae754 119 point2dl bufferShear = shearing(bufferRotate);
hiromasaoku 18:6f86abfae754 120
hiromasaoku 16:6dd2e60bc5bc 121 translated[currentLetters].letpoints[currentPoints] = bufferShear;
hiromasaoku 18:6f86abfae754 122
hiromasaoku 16:6dd2e60bc5bc 123 j++;
hiromasaoku 16:6dd2e60bc5bc 124 }
hiromasaoku 18:6f86abfae754 125 }*/