#ifndef DEF_TX_WORLD
 #define DEF_TX_WORLD

//------------------------------------------//
//		TKA4 Main Object Graph classes		//
//				26. 10. 2007				//
//------------------------------------------//


//--- Pragma 
#pragma comment (lib, "opengl32.lib")  
#pragma comment (lib, "glu32.lib")     
//=== Pragma 


//--- Includes
#include <GL/gl.h>
#include <GL/glu.h>

#include "TX_Error.h"
#include "../GLTools/GLTools.h"
#include "../StrDivider/StrDiv.h"
//=== Includes 


//--- Defines
#define MAX_VIEW_AREA  1000
//=== Defines
	


//--- txLight ---//
class txLight {	
public:	
	GLint  number;

	GLfloat  LightPos[4];  // Point source
	GLfloat  Param[4];

	GLfloat  Ambient[4];
	GLfloat  Diffuse[4];
	GLfloat  Specular[4];

public:
	txLight(int num, char* filename) {
		number = num;

		if (filename == STR_NONE || filename == NULL) {
			
			
			LightPos[0]=-100.0f; LightPos[1]=100.0f; LightPos[2]=50.0f; LightPos[3]=1;
			Param[0]=0; Param[1]=0; Param[2]=0; Param[3]=0;
			
			Ambient[0]=0.25f; Ambient[1]=0.25f; Ambient[2]=0.25f; Ambient[3]=1.0f;
			Diffuse[0]=1; Diffuse[1]=1; Diffuse[2]=1; Diffuse[3]=1;
			Specular[0]=1; Specular[1]=1; Specular[2]=1; Specular[3]=1;
		}
	}


	inline void Init() {
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Param);

		glLightfv(GL_LIGHT0+number, GL_AMBIENT, Ambient);
		glLightfv(GL_LIGHT0+number, GL_DIFFUSE, Diffuse);
		glLightfv(GL_LIGHT0+number, GL_SPECULAR, Specular);

		glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
	}


	inline void Disable() { glDisable (GL_LIGHT0+number); }
	inline void Enable() { glEnable (GL_LIGHT0+number); }
};



//---  Abstract Class Object TX  ---//
/*	Base for all Graph Objects.	   */
class txWorld {
public: 
	txErrorFile *Log;
	int  Screen_Width, Screen_Height;
	
	long int  World_Time;
	GLTFrame  Camera;

	int  LightCount;
	txLight  *Lights;


public:
	txWorld (txErrorFile *log, char *s);
	~txWorld () { delete [] Lights; }

	inline void Init ();
};


//----------------------------------------------------------------

txWorld :: txWorld (txErrorFile *log, char *s)
{ 
	Log = log;
		
	if (GetParamFromStr(s, "CAMERA") == STR_NONE) {
		gltInitFrame(&Camera);
	}
		
	if (GetParamFromStr(s, "WORLD_TIME") == STR_NONE) {
		World_Time = 0;
	}

	LightCount = 1;
	Lights = new txLight(0, GetParamFromStr(s, "LIGHT0"));
};


//--- txWorld Init ---
void txWorld :: Init()
{
	for (int i = 0; i<LightCount; i++) {
		Lights[i].Init();
		Lights[i].Enable();
	}

}


#endif