#include "videoLineModule.h"

//-------------------------------------------
videoLineModule::videoLineModule(){
	setup();
	bPointNew = false;
}

//-------------------------------------------	
void videoLineModule::setMovie(char * movieName){
	
	char path[255];
	sprintf(path, "movies/%s", movieName);
	video.loadMovie(path);
	
	sprintf(path, "settings/%s.xml", movieName);
	ts.loadSettings(path);
	
	box->setStartPointAngle(ts.getStartingPoint(), ts.getStartingAngle());
	
}

//-------------------------------------------	
void videoLineModule::reset(){
	pct 				= 0;
}
		
//-------------------------------------------	
void videoLineModule::setup(){
	pct 				= 0;
}


//-------------------------------------------	
void videoLineModule::update(){
	pct += 0.01f;
	if (pct > 0 && pct < 1){
		video.setPaused(true);
		video.setPosition(pct);
		video.idleMovie();
	
		ofVec3f point = ts.getPointForPct(pct);
		if ((point.x != pointPos.x)  && (point.x >= 0.0f)){
			bPointNew = true;
			pointPos.set(point);
		}
	
	}
	box->updatePts();
}

//-------------------------------------------	
bool videoLineModule::bHaveNewPoint(){
	return bPointNew;
}

//-------------------------------------------	
ofVec3f videoLineModule::getNewPoint(){
	bPointNew = false;
	return interpolatePt(box->ptsTranslated, pointPos.x/640.0f, 1-(pointPos.y/480.0f));
}


//-------------------------------------------	
void videoLineModule::draw(float offsetx, float offsety){
	
	
	
	// add the offset to the translation:
	ofVec3f ptsTransAndOffsetted[4];
	for (int i = 0; i < 4; i++){
		ptsTransAndOffsetted[i].set(box->ptsTranslated[i].x - offsetx, 	
									box->ptsTranslated[i].y - offsety, 0	
									);
	}
	
	// draw the texture:
	ofSetColor(0xffffff);
	video.tex.draw(ptsTransAndOffsetted);
	
	glPushMatrix();
		ofSetColor(0xffffff);
		box->draw(offsetx, offsety);
	glPopMatrix();
	
	
}

