sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
hiromasaoku
Date:
Mon May 20 09:31:29 2013 +0000
Revision:
18:6f86abfae754
Parent:
17:dce982e0a383
Child:
19:8e9fe7d25b9c
Cleanup done!!!!!!!!!!!

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 16:6dd2e60bc5bc 12 point2dl dataAfter;
hiromasaoku 18:6f86abfae754 13 dataBefore.x = dataBefore.x ;//+ speed * cos(angle) * timer_v.read_us()/st/1000;
hiromasaoku 18:6f86abfae754 14 dataBefore.y = dataBefore.y ;//+ speed * sin(angle) * timer_v.read_us()/st/1000;
hiromasaoku 18:6f86abfae754 15
hiromasaoku 16:6dd2e60bc5bc 16 }
hiromasaoku 16:6dd2e60bc5bc 17
hiromasaoku 18:6f86abfae754 18 inline void render::rotation(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 19 {
hiromasaoku 18:6f86abfae754 20 int x=dataBefore.x;
hiromasaoku 18:6f86abfae754 21 dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;
hiromasaoku 18:6f86abfae754 22 dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
hiromasaoku 16:6dd2e60bc5bc 23 }
hiromasaoku 16:6dd2e60bc5bc 24 //----------------------------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 25
hiromasaoku 18:6f86abfae754 26 void render::startRender()
hiromasaoku 18:6f86abfae754 27 {
hiromasaoku 18:6f86abfae754 28 //void (render::*fpdraw)() = draw; // I can't solve the error.......I tried a few days..........
hiromasaoku 17:dce982e0a383 29 renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL); // ???????how to set menber function???????
hiromasaoku 16:6dd2e60bc5bc 30 }
hiromasaoku 16:6dd2e60bc5bc 31
hiromasaoku 18:6f86abfae754 32 void render::stopRender()
hiromasaoku 18:6f86abfae754 33 {
hiromasaoku 16:6dd2e60bc5bc 34 renderTimer.detach();
hiromasaoku 16:6dd2e60bc5bc 35 }
hiromasaoku 16:6dd2e60bc5bc 36
hiromasaoku 18:6f86abfae754 37 void render::setRender(vector<letter> *p)
hiromasaoku 18:6f86abfae754 38 {
hiromasaoku 16:6dd2e60bc5bc 39 ptext = p;
hiromasaoku 18:6f86abfae754 40
hiromasaoku 16:6dd2e60bc5bc 41 //for(int i=0; i!=(*ptext).size(); i++){
hiromasaoku 18:6f86abfae754 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 18:6f86abfae754 45
hiromasaoku 18:6f86abfae754 46 currentLetters=0;
hiromasaoku 18:6f86abfae754 47 currentPoints=0;
hiromasaoku 16:6dd2e60bc5bc 48 }
hiromasaoku 16:6dd2e60bc5bc 49
hiromasaoku 18:6f86abfae754 50
hiromasaoku 18:6f86abfae754 51 void render::updateSpeed(float vx, float vy){
hiromasaoku 18:6f86abfae754 52 speed=sqrt(vx*vx+vy*vy);//*factorSpeed;
hiromasaoku 18:6f86abfae754 53 angle=atan2(vy,vx);
hiromasaoku 18:6f86abfae754 54 }
hiromasaoku 18:6f86abfae754 55
hiromasaoku 18:6f86abfae754 56 void render::draw()
hiromasaoku 18:6f86abfae754 57 {
hiromasaoku 18:6f86abfae754 58
hiromasaoku 18:6f86abfae754 59 point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
hiromasaoku 18:6f86abfae754 60 transform(drawPoint); // transform it with the current speed and angle
hiromasaoku 18:6f86abfae754 61
hiromasaoku 16:6dd2e60bc5bc 62 IO.writeOutXY(drawPoint.x , drawPoint.y);
hiromasaoku 16:6dd2e60bc5bc 63 IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
hiromasaoku 18:6f86abfae754 64
hiromasaoku 16:6dd2e60bc5bc 65 currentPoints++;
hiromasaoku 18:6f86abfae754 66 if(currentPoints > translated[currentLetters].letpoints.size() ) {
hiromasaoku 16:6dd2e60bc5bc 67 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 68 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 69 }
hiromasaoku 18:6f86abfae754 70 if(currentLetters > translated.size()) {
hiromasaoku 16:6dd2e60bc5bc 71 currentLetters = 0;
hiromasaoku 16:6dd2e60bc5bc 72 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 73 }
hiromasaoku 18:6f86abfae754 74 }
hiromasaoku 18:6f86abfae754 75
hiromasaoku 18:6f86abfae754 76 void render::transform(point2dl& mypoint)
hiromasaoku 18:6f86abfae754 77 {
hiromasaoku 18:6f86abfae754 78
hiromasaoku 18:6f86abfae754 79 rotation(mypoint);
hiromasaoku 18:6f86abfae754 80 shearing(mypoint);
hiromasaoku 16:6dd2e60bc5bc 81
hiromasaoku 16:6dd2e60bc5bc 82 }
hiromasaoku 16:6dd2e60bc5bc 83
hiromasaoku 18:6f86abfae754 84 /*
hiromasaoku 18:6f86abfae754 85 void render::translating(float speed, float angle) //DO when get the speed and angle data.
hiromasaoku 18:6f86abfae754 86 {
hiromasaoku 18:6f86abfae754 87 for (int i = 0; i > 10; i++) {
hiromasaoku 16:6dd2e60bc5bc 88 int j=0;
hiromasaoku 18:6f86abfae754 89 if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()) {
hiromasaoku 16:6dd2e60bc5bc 90 currentPoints = 0;
hiromasaoku 16:6dd2e60bc5bc 91 currentLetters++;
hiromasaoku 16:6dd2e60bc5bc 92 j=0;
hiromasaoku 16:6dd2e60bc5bc 93 }
hiromasaoku 18:6f86abfae754 94 if(currentLetters > (*ptext).size()) break;
hiromasaoku 18:6f86abfae754 95
hiromasaoku 18:6f86abfae754 96 point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints]);
hiromasaoku 18:6f86abfae754 97 point2dl bufferShear = shearing(bufferRotate);
hiromasaoku 18:6f86abfae754 98
hiromasaoku 16:6dd2e60bc5bc 99 translated[currentLetters].letpoints[currentPoints] = bufferShear;
hiromasaoku 18:6f86abfae754 100
hiromasaoku 16:6dd2e60bc5bc 101 j++;
hiromasaoku 16:6dd2e60bc5bc 102 }
hiromasaoku 18:6f86abfae754 103 }*/