// Author : Chris Tolley
// Date   : 1/14/2003
// ms3dUtilities.h contains structs to used in the loading and
// displaying of ms3d files

#include "texture.h"
#include "matrix.h"
#include <vector>
using std::vector;

// a Vertex struct to hold the special vertices in an ms3d file
struct ms3dVertex
{
	// Flags used by the MilkShape3d editor
	unsigned char flags_;
	// The x,y,z point
	float vert_[3];
	// The index of the bone on the ms3d model
	char bone_;
	// An unused variable
	unsigned char unused_;
};// End ms3dVertex struct

// a triangle struct to hold ms3d triangle information
struct ms3dTriangle
{
	// editor flag
 	unsigned short int flag_;
	// indexes to which vertices make up this triangle
	unsigned short int VertIndexs_[3];
	// The vertex normals used for lighting
	float normal_[3][3];
	// The texture coordinates for this triangle
	float texCoords_[2][3];
	// unused byte
	unsigned char smoothing_;
	// unused byte
	unsigned char group_;
};


// A mesh struct to hold ms3d mesh data
struct ms3dMesh
{
	// 2 byte flag for the editor
	unsigned char flag_;
	// 32 byte character string for the name of the mest
	char name_[32];
	// 2 byte int containing the number of triangles
	unsigned short numTris_;
	// A vector of indexes to triangles
	vector<unsigned short int> triIndexs_;
	// 1 byte material index.
	char material_;
};// End ms3dMesh struct

// A material struct to hold ms3d material data
struct ms3dMaterial
{
	// The name of the material
	char name_[32];
	// The material's ambient value
	float ambient_[4];
	// The material's diffuse value
	float diffuse_[4];
	// The material's specular value
	float specular_[4];
	// The material's emissive value
	float emissive_[4];
	// The material's shininess, between 1 to 128
	float shininess_;
	// The material's transparency, either 0 or 1
	float transparency_;
	// An unused byte
	char mode_;
	// The material's alpha value.
	char alpha_[128];
	// The texture for this mesh
	texture texture_;
};// End ms3dMaterial struct

// A struct to hold key frame information for ms3d models
struct ms3dKeyFrame
{
	// A time value to hold this key frame's place
	float time_;
	// Holds rotation and translation values.
	float values_[3];
};// End ms3dKeyFrame struct

// A struct to hold ms3d joint data
struct ms3dJoint
{
	// Editor flags
	char flag_;
	// The name of this joint
	char name_[32];
	// The name of the parent joint
	char parent_[32];
	// Starting rotation
	float rotation_[3];
	// Starting position
	float position_[3];
	// The number of rotation frames
	unsigned short int numRotationFrames_;
	// The number of translation frames
	unsigned short int numTranslationFrames_;
	// Rotation key frames
	vector< ms3dKeyFrame > rotationKeyFrames_;
	// Translation key frames
	vector< ms3dKeyFrame > translationKeyFrames_;

	// Below is data which is not loaded from the file
	// The parent joint index
	short parentIndex_;

	// Matrices to hold rotation and translation data
//	Matrix local_;
//	Matrix absolute_;
//	Matrix final_;
	
	// The current translation and rotation frames to use.
	unsigned short currRotationFrame_;
	unsigned short currTranslationFrame_;

};// End ms3dJoint struct