sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
hiromasaoku
Date:
Mon May 20 08:25:22 2013 +0000
Revision:
16:6dd2e60bc5bc
Child:
17:dce982e0a383
a safety commit

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 renderTimer;
hiromasaoku 16:6dd2e60bc5bc 7 Ticker translationTimer;
hiromasaoku 16:6dd2e60bc5bc 8
hiromasaoku 16:6dd2e60bc5bc 9 //for translating -----------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 10
hiromasaoku 16:6dd2e60bc5bc 11 point2dl shearing(point2dl dataBefore, float velocity, float theta){
hiromasaoku 16:6dd2e60bc5bc 12 point2dl dataAfter;
hiromasaoku 16:6dd2e60bc5bc 13 dataAfter.x = dataBefore.x ;//+ velocity * cos(theta) * timer_v.read_us()/st/1000;
hiromasaoku 16:6dd2e60bc5bc 14 dataAfter.y = dataBefore.y ;//+ velocity * sin(theta) * timer_v.read_us()/st/1000;
hiromasaoku 16:6dd2e60bc5bc 15 dataAfter.laserSwitch = dataBefore.laserSwitch;
hiromasaoku 16:6dd2e60bc5bc 16
hiromasaoku 16:6dd2e60bc5bc 17 return dataAfter;
hiromasaoku 16:6dd2e60bc5bc 18 }
hiromasaoku 16:6dd2e60bc5bc 19
hiromasaoku 16:6dd2e60bc5bc 20 point2dl rotation(point2dl dataBefore, float theta){
hiromasaoku 16:6dd2e60bc5bc 21 point2dl dataAfter;
hiromasaoku 16:6dd2e60bc5bc 22 dataAfter.x = cos(theta)*dataBefore.x - sin(theta)*dataBefore.y;
hiromasaoku 16:6dd2e60bc5bc 23 dataAfter.y = sin(theta)*dataBefore.x + cos(theta)*dataBefore.y;
hiromasaoku 16:6dd2e60bc5bc 24 dataAfter.laserSwitch = dataBefore.laserSwitch;
hiromasaoku 16:6dd2e60bc5bc 25
hiromasaoku 16:6dd2e60bc5bc 26 return dataAfter;
hiromasaoku 16:6dd2e60bc5bc 27 }
hiromasaoku 16:6dd2e60bc5bc 28 //----------------------------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 29
hiromasaoku 16:6dd2e60bc5bc 30 void render::startRender(){
hiromasaoku 16:6dd2e60bc5bc 31 //void (render::*fpdraw)() = draw; // I can't solve the error.......I tried a few days..........
hiromasaoku 16:6dd2e60bc5bc 32 //renderTimer.attach_us((this->*fpdraw)(), 200); // ???????how to set menber function???????
hiromasaoku 16:6dd2e60bc5bc 33 }
hiromasaoku 16:6dd2e60bc5bc 34
hiromasaoku 16:6dd2e60bc5bc 35 void render::stopRender(){
hiromasaoku 16:6dd2e60bc5bc 36 renderTimer.detach();
hiromasaoku 16:6dd2e60bc5bc 37 }
hiromasaoku 16:6dd2e60bc5bc 38
hiromasaoku 16:6dd2e60bc5bc 39 void render::setRender(vector<letter> *p){
hiromasaoku 16:6dd2e60bc5bc 40 ptext = p;
hiromasaoku 16:6dd2e60bc5bc 41
hiromasaoku 16:6dd2e60bc5bc 42 //for(int i=0; i!=(*ptext).size(); i++){
hiromasaoku 16:6dd2e60bc5bc 43 for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr){
hiromasaoku 16:6dd2e60bc5bc 44 translated.push_back(*itr);
hiromasaoku 16:6dd2e60bc5bc 45 } //copy the liblary to the buffer.
hiromasaoku 16:6dd2e60bc5bc 46 }
hiromasaoku 16:6dd2e60bc5bc 47
hiromasaoku 16:6dd2e60bc5bc 48 void render::draw(){
hiromasaoku 16:6dd2e60bc5bc 49 drawPoint.x = translated[currentLetters].letpoints[currentPoints].x;
hiromasaoku 16:6dd2e60bc5bc 50 drawPoint.y = translated[currentLetters].letpoints[currentPoints].y;
hiromasaoku 16:6dd2e60bc5bc 51 drawPoint.laserSwitch = translated[currentLetters].letpoints[currentPoints].laserSwitch;
hiromasaoku 16:6dd2e60bc5bc 52 IO.writeOutXY(drawPoint.x , drawPoint.y);
hiromasaoku 16:6dd2e60bc5bc 53 IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
hiromasaoku 16:6dd2e60bc5bc 54
hiromasaoku 16:6dd2e60bc5bc 55
hiromasaoku 16:6dd2e60bc5bc 56 currentPoints++;
hiromasaoku 16:6dd2e60bc5bc 57 if(currentPoints > translated[currentLetters].letpoints.size() ){
hiromasaoku 16:6dd2e60bc5bc 58 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 59 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 60 }
hiromasaoku 16:6dd2e60bc5bc 61 if(currentLetters > translated.size()){
hiromasaoku 16:6dd2e60bc5bc 62 currentLetters = 0;
hiromasaoku 16:6dd2e60bc5bc 63 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 64 }
hiromasaoku 16:6dd2e60bc5bc 65
hiromasaoku 16:6dd2e60bc5bc 66 }
hiromasaoku 16:6dd2e60bc5bc 67
hiromasaoku 16:6dd2e60bc5bc 68 void render::translating(float speed, float angle){ //DO when get the speed and angle data.
hiromasaoku 16:6dd2e60bc5bc 69 for (int i = 0; i > 10; i++){
hiromasaoku 16:6dd2e60bc5bc 70 int j=0;
hiromasaoku 16:6dd2e60bc5bc 71 if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()){
hiromasaoku 16:6dd2e60bc5bc 72 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 73 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 74 j=0;
hiromasaoku 16:6dd2e60bc5bc 75 }
hiromasaoku 16:6dd2e60bc5bc 76 if(currentLetters > (*ptext).size()) break;
hiromasaoku 16:6dd2e60bc5bc 77
hiromasaoku 16:6dd2e60bc5bc 78 point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints],angle);
hiromasaoku 16:6dd2e60bc5bc 79 point2dl bufferShear = shearing(bufferRotate, speed, angle);
hiromasaoku 16:6dd2e60bc5bc 80
hiromasaoku 16:6dd2e60bc5bc 81 translated[currentLetters].letpoints[currentPoints] = bufferShear;
hiromasaoku 16:6dd2e60bc5bc 82
hiromasaoku 16:6dd2e60bc5bc 83 j++;
hiromasaoku 16:6dd2e60bc5bc 84 }
hiromasaoku 16:6dd2e60bc5bc 85 }