sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
hiromasaoku
Date:
Mon May 20 08:51:07 2013 +0000
Revision:
17:dce982e0a383
Parent:
16:6dd2e60bc5bc
Child:
18:6f86abfae754
error vanished!!

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