#ifndef DEF_MOTIONS
 #define DEF_MOTIONS

//------------------------------------------//
//	TKA4 CEngine and basis Graph classes	//
//				29. 10. 2007				//
//------------------------------------------//


//--- Includes
#include <windows.h>
#include <stdio.h>
#include <math.h>

#include "TX_Object.h"
//=== Includes 


//--- Pragma 
#pragma warning(disable:4305) 
//=== Pragma 

//--- Defines
#define H_STEP  3.0f
//=== Defines


//---------------------------------------------------------------------


//---  Camera Gradual Motion  ---//
class txObj_CameraGradualMotion : public txObject {
private :	
	
	//--- helper subroutine
	inline void interpolate(GLfloat *cot, GLfloat *ct) {
		for (int i = 0; i<3; i++)
			cot[i] = cot[i] + (ct[i]-cot[i])/H_STEP; 
	};

public :

	//--- txObj :: Execute Forward
	virtual void Execute_Forward()
	{
		GLTFrame *co = &World -> CameraOld, 
				  *c = &World -> Camera;

		
		interpolate(co -> vForward, c -> vForward);
		interpolate(co -> vLocation, c -> vLocation);
		interpolate(co -> vUp, c -> vUp);

		if (c->AngleX > 90) c->AngleX = 90;
		if (c->AngleX < -90) c->AngleX = -90;

		co->AngleX = co->AngleX + (c->AngleX - co->AngleX)/H_STEP;
		co->AngX = co->AngleX;
		//co->SetAngX(c->AngleX - co->AngleX); 


		World->Lights[1].LightPos[0] = World->CameraOld.vLocation[0];
		World->Lights[1].LightPos[1] = World->CameraOld.vLocation[1];
		World->Lights[1].LightPos[2] = World->CameraOld.vLocation[2];
		
		World->Lights[1].ApplyPosition();
	
		gltApplyCameraTransform(&World->CameraOld);	

	}

};


//--- tx Collision Map ---//
class  txObj_CollisionActor : public txObject {
public :
	txcSimple *current;
	
	txObj_CollisionActor() {};

	virtual void Execute_Init() {
	}

	//--- txObj_ :: Execute Forward
	virtual void Execute_Forward()
	{
		bool temp = true;
		for (current = World->Collision.first->next; current != NULL; current = current -> next)
		{
			if (current->io == txc_border) {
				if (!current->IsIn(World->Camera.vLocation)) {
					temp = false;
					break;
				} 
			} 
			else
				temp = (temp) && current->IsIn(World->Camera.vLocation);
		}

		if (!temp) World->Camera = World->CameraOld;
	}
};


#endif



