this version 10/17

Dependencies:   mbed

Fork of linearMirrorMotion by Alvaro Cassinelli

renderclass.cpp

Committer:
hiromasaoku
Date:
2013-05-20
Revision:
17:dce982e0a383
Parent:
16:6dd2e60bc5bc
Child:
18:6f86abfae754

File content as of revision 17:dce982e0a383:

#include "renderclass.h"
#include "mbed.h"
#include "laserProjectorHardware.h"
#include <vector>

Ticker translationTimer;

//for translating -----------------------------------------------------------------

point2dl shearing(point2dl dataBefore, float velocity, float theta){
    point2dl dataAfter;
    dataAfter.x = dataBefore.x ;//+ velocity * cos(theta) * timer_v.read_us()/st/1000;   
    dataAfter.y = dataBefore.y ;//+ velocity * sin(theta) * timer_v.read_us()/st/1000; 
    dataAfter.laserSwitch = dataBefore.laserSwitch;
    
    return dataAfter;
}

point2dl rotation(point2dl dataBefore, float theta){
    point2dl dataAfter;
    dataAfter.x = cos(theta)*dataBefore.x - sin(theta)*dataBefore.y;
    dataAfter.y = sin(theta)*dataBefore.x + cos(theta)*dataBefore.y;
    dataAfter.laserSwitch = dataBefore.laserSwitch;

    return dataAfter;
}
//----------------------------------------------------------------------------------

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.
}

void render::draw(){
    drawPoint.x = translated[currentLetters].letpoints[currentPoints].x;
    drawPoint.y = translated[currentLetters].letpoints[currentPoints].y;
    drawPoint.laserSwitch = translated[currentLetters].letpoints[currentPoints].laserSwitch;
    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::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],angle);
        point2dl bufferShear = shearing(bufferRotate, speed, angle);
    
        translated[currentLetters].letpoints[currentPoints] = bufferShear;
    
        j++;
    }
}