#pragma once

#include "ofxPoint2f.h"
#include "ofMain.h"

#include "arFakeMarker.h"
#include "coordWarping.h"

class arPlane : public arFakeMarker{

	public:
		
		//------------------------------------
		void calculateCoordinateTranslation(){
			plane_dst[0] = ofPoint(-halfSize.x, -halfSize.y);
			plane_dst[1] = ofPoint(halfSize.x,  -halfSize.y);
			plane_dst[2] = ofPoint(halfSize.x,  halfSize.y);
			plane_dst[3] = ofPoint(-halfSize.x, halfSize.y);
		
			CW.calculateMatrix(plane_src, plane_dst);
		}
		
		//------------------------------------		
		void setPlanePoints(ofPoint p1, ofPoint p2, ofPoint p3, ofPoint p4){
			plane_src[0] = p1;
			plane_src[1] = p2;
			plane_src[2] = p3;
			plane_src[3] = p4;
			
			arFakeMarker::setMarkerPoints(plane_src[0], plane_src[1], plane_src[2], plane_src[3]);				
			calculateCoordinateTranslation();
		}
		
		//------------------------------------
		void setPlaneSize(int mm){
			arFakeMarker::setMarkerSize(mm);
			calculateCoordinateTranslation();
		}		

		//------------------------------------		
		ofPoint screenToMarker(float & xIn, float & yIn){
			ofPoint result = CW.transform(xIn, yIn);
			result.x /= (float)renderW/(float)cameraW;
			result.y /= (float)renderH/(float)cameraH;
			return result;
		}
		
		//------------------------------------		
		ofPoint screenToMarker(ofxPoint2f & pt){
			ofPoint result =  CW.transform(pt.x, pt.y);
			result.x /= (float)renderW/(float)cameraW;
			result.y /= (float)renderH/(float)cameraH;		
			return result;	
		}

		//------------------------------------		
		ofPoint screenToMarker(ofPoint & pt){
			ofPoint result =  CW.transform(pt.x, pt.y);
			result.x /= (float)renderW/(float)cameraW;
			result.y /= (float)renderH/(float)cameraH;
			return result;
		}
		
		coordWarping CW;
		
		ofxPoint2f plane_src[4];
		ofxPoint2f plane_dst[4];		
};
	
		
