#ifndef DEF_TX_COLLISION
 #define DEF_TX_COLLISION

//------------------------------------------//
//		TKA4 Main Object Graph classes		//
//				05. 11. 2007				//
//------------------------------------------//


//--- Includes
#include "TX_Engine.h"
#include "../GLTools/GLTools.h"
//=== Includes


enum txcInOut { txc_inside, txc_outside, txc_border };



//--- txc Simple
class txcSimple {
	public:
		txcSimple *prev, *next;
		
		txcInOut io;

		txcSimple() {prev = NULL; next = NULL;}

		inline virtual bool IsIn(float px, float py, float pz) {return true;};
		inline virtual bool IsIn(GLTVector3 p) {return true;};
};


//--- txc Rectangle 
class txcRectangle : public txcSimple {
public:
	float x,y, x2, y2;

public:
	txcRectangle () {};

	txcRectangle (float x_, float y_, float x2_, float y2_, txcInOut i) 
		: x(x_), y(y_), x2(x2_), y2(y2_) { io = i; }
	
	//--- --- ---
	inline virtual bool IsIn(float px, float py, float pz) {
		if (x < px && x2 > px)
			if (y < py && y2 > py)
				return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}

	//--- --- ---
	inline virtual bool IsIn(GLTVector3 p) {
		if (x < p[0] && x2 > p[0])
			if (y < p[1] && y2 > p[1])
				return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}
};


//--- txc BOX
class txcBox : public txcSimple {
public:
	float x,y,z,  x2, y2, z2;

public:
	txcBox () {};

	txcBox (float x_, float y_, float z_, float x2_, float y2_, float z2_, txcInOut i) 
		: x(x_), y(y_), x2(x2_), y2(y2_), z2(z2_), z(z_) { io = i; }
	
	//--- --- ---
	inline virtual bool IsIn(float px, float py, float pz) {
		if (x <= px && x2 >= px)
			if (y <= py && y2 >= py)
				if (z <= pz && z2 >= pz)
			return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}

	//--- --- ---
	inline virtual bool IsIn(GLTVector3 p) {
		if (x <= p[0] && x2 >= p[0])
			if (y <= p[1] && y2 >= p[1])
				if (z <= p[2] && z2 >= p[2])
			return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}
};


//--- txc BORDER BOX
class txcBorderBox : public txcSimple {
public:
	float x,y,z,  x2, y2, z2;

public:
	txcBorderBox () {};

	txcBorderBox (float x_, float y_, float z_, float x2_, float y2_, float z2_) 
		: x(x_), y(y_), x2(x2_), y2(y2_), z2(z2_), z(z_) { io = txc_border; }
	
	//--- --- ---
	inline virtual bool IsIn(float px, float py, float pz) {
		if (x <= px && x2 >= px)
			if (y <= py && y2 >= py)
				if (z <= pz && z2 >= pz)
			return true;
		return false;
	}

	//--- --- ---
	inline virtual bool IsIn(GLTVector3 p) {
		if (x <= p[0] && x2 >= p[0])
			if (y <= p[1] && y2 >= p[1])
				if (z <= p[2] && z2 >= p[2])
			return true;
		return false;
	}
};


//--- txc Sphere
class txcSphere : public txcSimple {
public:
	float x,y,z, r;

public:
	txcSphere () {};

	txcSphere (float x_, float y_, float z_, float r_, txcInOut i) 
		: x(x_), y(y_), z(z_), r(r_) { io = i; }
	
	//--- --- ---
	inline virtual bool IsIn(float px, float py, float pz) {
		if (
			(x - px)*(x - px) + 
			(y - py)*(y - py) + 
			(z - pz)*(z - pz) <= r*r )
				return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}

	//--- --- ---
	inline virtual bool IsIn(GLTVector3 p) {
		if (
			(x - p[0])*(x - p[0]) + 
			(y - p[1])*(y - p[1]) + 
			(z - p[2])*(z - p[2]) <= r*r )
				return io==txc_inside ? true : false;
		return io==txc_inside ? false : true;
	}
};



//---------------------------------------------------------------

//--- Collision Map ---//
class txCollisionMap {
public:
	txcSimple *first, *final, *current;

	void AddTXC(txcSimple *new_) {
		new_ -> prev = final;
		final -> next = new_;
		final = new_;
	}

	txCollisionMap() {
		first = new txcSimple(); 
		final = first; 
		current = first;
	};
};

//---------------------------------------------------------------



#endif
