#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 { inside, outside };

//--- 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==inside ? true : false;
		return io==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==inside ? true : false;
		return io==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==inside ? true : false;
		return io==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==inside ? true : false;
		return io==inside ? false : true;
	}
};


//--- 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==inside ? true : false;
		return io==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==inside ? true : false;
		return io==inside ? false : true;
	}
};



#endif
