Takashi Asano
/
linearMirrorMotion1017
sotsuron
Fork of linearMirrorMotion1017 by
renderclass.cpp
- Committer:
- hiromasaoku
- Date:
- 2013-05-20
- Revision:
- 18:6f86abfae754
- Parent:
- 17:dce982e0a383
- Child:
- 19:8e9fe7d25b9c
File content as of revision 18:6f86abfae754:
#include "renderclass.h" #include "mbed.h" #include "laserProjectorHardware.h" #include <vector> Ticker translationTimer; //for translating ----------------------------------------------------------------- inline void render::shearing(point2dl& dataBefore) { point2dl dataAfter; dataBefore.x = dataBefore.x ;//+ speed * cos(angle) * timer_v.read_us()/st/1000; dataBefore.y = dataBefore.y ;//+ speed * sin(angle) * timer_v.read_us()/st/1000; } inline void render::rotation(point2dl& dataBefore) { int x=dataBefore.x; dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y; dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y; } //---------------------------------------------------------------------------------- void render::startRender() { //void (render::*fpdraw)() = draw; // I can't solve the error.......I tried a few days.......... renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); // ???????how to set menber function??????? } void render::stopRender() { renderTimer.detach(); } void render::setRender(vector<letter> *p) { ptext = p; //for(int i=0; i!=(*ptext).size(); i++){ for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) { translated.push_back(*itr); } //copy the liblary to the buffer. currentLetters=0; currentPoints=0; } void render::updateSpeed(float vx, float vy){ speed=sqrt(vx*vx+vy*vy);//*factorSpeed; angle=atan2(vy,vx); } void render::draw() { point2dl drawPoint=translated[currentLetters].letpoints[currentPoints]; transform(drawPoint); // transform it with the current speed and angle IO.writeOutXY(drawPoint.x , drawPoint.y); IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch); currentPoints++; if(currentPoints > translated[currentLetters].letpoints.size() ) { currentLetters++; currentPoints = 0; } if(currentLetters > translated.size()) { currentLetters = 0; currentPoints = 0; } } void render::transform(point2dl& mypoint) { rotation(mypoint); shearing(mypoint); } /* void render::translating(float speed, float angle) //DO when get the speed and angle data. { for (int i = 0; i > 10; i++) { int j=0; if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()) { currentPoints = 0; currentLetters++; j=0; } if(currentLetters > (*ptext).size()) break; point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints]); point2dl bufferShear = shearing(bufferRotate); translated[currentLetters].letpoints[currentPoints] = bufferShear; j++; } }*/