#ifndef RTGOBJ_H
#define RTGOBJ_H

#include <string>
#include <iostream>
#include <strstream>
#include <fstream>

#include "..\objBmp\BmpLoader.hpp"

using namespace std;

// colour
typedef struct RGB_t {
	SHORT r;
	SHORT g;
	SHORT b;
} COL;

// vertex
typedef struct VEC8_t {
	float x;
	float y;
} VEC8;

// vertex
typedef struct VEC12_t {
	float x;
	float y;
	float z;
} VEC12;

// vertex & alpha
typedef struct VEC16_t {
	float x;
	float y;
	float z;
	float a;
} VEC16;

// polygon
typedef struct POLY_t {
	int pointCount;
	short surfaceId;
	short *point;
	VEC12 center;
	VEC12 normal;
} POLY;


// short scaled percentage 0 .. 256  ( must be 2 bytes! )
typedef short IP2;

// float scaled percentage  0.0 .. 100.0 ( must be 4 bytes )
typedef float FP4;

// degrees
typedef float DEG4;

// surface attributes
typedef struct SURF_T {
	string name;	
	COL col;
	short flag;
	short diff;
	// ........
	// ignored all other attributes!! not useful for now
} SURF;



class rtgMaterial {
public:
	string	name;
	VEC12	ambient;
	VEC12	diffuse;
	VEC12	specular;
	VEC12	emmision;
	float	shininess;
	float	transparency;

	string	sgiTextureFile;
	string	bumpName;
	string	reflectedName;
	string	textureFile;
	BMP		texture;

};

class rtgMaterialList {
public:
	int count;
	class rtgMaterial *mat;

};

// its a quad!!! or a tri!!! no more no less ok?
class rtgObjectPolygon {
public:
	int verts;
	COL		colour;
	SHORT	*v;
	SHORT	*n;
	SHORT	*t;

};

class rtgObject {
public:
	string name;

	VEC12	translate;
	VEC12	rotate;
	VEC12	scale;
	VEC12	sPivot;
	VEC12	rPivot;

	// matrix
	VEC16	ltm0;
	VEC16	ltm1;
	VEC16	ltm2;
	VEC16	ltm3;

	int		usesMaterial;
	int		usesMaterial2;

// Body 
	int		vertCount;
	VEC12	*vertex;

	int		colCount;
	VEC16	*colour;

	int		normCount;
	VEC12	*normal;

	int		texCount;
	VEC8	*texture;

	int		polyCount;
	class rtgObjectPolygon *polygon;

	void render (class rtgScene *scn);

};


class rtgObjectList {
public:
	int count;
	string name;
	class rtgObject *obj;
};



class rtgScene {

public:
	BOOL ready;

	string path;
	string fileName;
	string fileAbs;
	int fileSize;
	char *data;


	string headerTitle;
	float headerVersion;
	int		numberOfObjects;
	
	BOOL	vertNorms;
	BOOL	vertColors;
	BOOL	texCoords;
	BOOL	polyNorms;
	BOOL	outputHierarchy;
	BOOL	outputLocal;
	BOOL	showIndexCounters;
	BOOL	outputMaterials;
	BOOL	outputAnimation;
	BOOL	outputAllNodes;
	BOOL	outputDecomp;
	BOOL	outputDegrees;

	class rtgMaterialList materials;
	// hard limit on number of textures
	int					txCount;
	unsigned int		txBound[1000];


	class rtgObjectList objects;
	
	int		discard; // this is how many objects were not loaded! because they are just blank rotations 
					// encapsulating whatever follows :) trueNumObj = numObj-discard ok!???


		rtgScene();

		void render ( void );
		
		int load ( string path );
		
		

};














#endif