#include "collisionScene.h"
#include "testApp.h"

//---------------------------------------
collisionScene::collisionScene(){

}

//---------------------------------------
void collisionScene::setupScene(){
	sceneName = "my test scene!";
	addAppListener();
	addMouseListener();
	addKeyboardListener();
	setAutoRender(true);
		
	
	fakeMarker.setup(camW, camH, 60, true);
	
	
	mx = 0;
	my = 0;
	
	//this is for setting the points with your mouse
	whichPt		 = 0;
	recordingPts = false;
	
	CC.setup();
	
}

//---------------------------------------
void collisionScene::render(){
	if( hide || pause ) return;
	
	//draw a circle for each card found
	if( planePtr->isMarkerSet()){
		planePtr->loadARMatrix();
		
						
		
			
			
				ofSetColor(0xffffff);
				ofPoint pt = planePtr->screenToMarker(CC.pt.pos.x, CC.pt.pos.y);
				ofCircle(pt.x, pt.y, 5);
			
		
			/*
			// want to see all the cards! 
			if( allCards.size() > 0){
				for(int i = 0; i < allCards.size(); i++){
					
					
					
					glPushMatrix();
					glScalef(1, -1, 1);
					ofEnableAlphaBlending();
					//glTranslatef(0, 0, allCards[i].energySmoothed * 100);
					//ofSetColor(255,0,0, allCards[i].energySmoothed * 100);
					ofBeginShape();
					for (int j = 0; j < 4; j++){
						ofPoint pt = planePtr->screenToMarker(allCards[i].c[j].x, allCards[i].c[j].y);
						ofVertex(pt.x, pt.y);
					}
					ofEndShape();
					ofDisableAlphaBlending();
					glPopMatrix();
				}
			}
			 */
		
		
		planePtr->unloadARMatrix();
	}
	
	//CC.draw();
}

//---------------------------------------
void collisionScene::update(){
	if( pause ) return;
	
	
	if( allCards.size() > 0){
		for(int i = 0; i < allCards.size(); i++){
			vector<ofPoint> pts;
			for (int j = 0; j < 4; j++){
				pts.push_back(ofPoint(allCards[i].c[j].x, allCards[i].c[j].y));
			}
			CC.checkCardCollision(pts);
		}
	}
	
	CC.update();
	
}

//---------------------------------------		
void collisionScene::keyPressed( int key ){
	if( pause ) return;
}

//---------------------------------------
void collisionScene::keyReleased( int key ){
	if( pause ) return;
	
	
}


//---------------------------------------
void collisionScene::mouseMoved(int x, int y ){
	if( pause ) return;

	mx = x;
	my = y;
	
	
}

//---------------------------------------
void collisionScene::mouseDragged( int x, int y, int button ){
}

//---------------------------------------
void collisionScene::mousePressed( int x, int y, int button ){
	if( pause ) return;

	CC.pt.pos.set(0,480/2.0f,0);
	CC.pt.vel.set(1,0,0);
}

//---------------------------------------
void collisionScene::mouseReleased(int x, int y, int button ){
	if( pause ) return;

}	

