www.pudn.com > 3DmaxSLoader.rar > glStructures.h
//////////////////////////////////////////////////////////////////////
//
// C3dsReader, CTriObject 和 CTriList 类的数据结构的定义.
//
//////////////////////////////////////////////////////////////////////
#ifndef GLSTRUCTURES_H
#define GLSTRUCTURES_H
const long SizeofChunk = sizeof(unsigned short)+sizeof(long);
//PI的宏定义
#define M_PI 3.141592653589
#define M_2PI 6.283185307178
// 定义块的结构
typedef struct {
unsigned short id;
long len;
} Chunk3DS;
// 定义块的标识
const unsigned short M3DMAGIC = 0x4d4d;//基本块
const unsigned short CMAGIC = 0xc23d;//
const unsigned short M3D_VERSION = 0x0002;//版本号
const unsigned short MDATA = 0x3d3d;//编辑程序块
const unsigned short MESH_VERSION = 0x3d3e;//编辑程序配置主块
const unsigned short MAT_ENTRY = 0xafff;//材质列表开始
const unsigned short MASTER_SCALE = 0x0100;//
const unsigned short NAMED_OBJECT = 0x4000;//物体描述块
const unsigned short MAT_NAME = 0xa000;//材质名称
const unsigned short MAT_AMBIENT = 0xa010;
const unsigned short MAT_DIFFUSE = 0xa020;//满射色。父chunk:0xafff子chunk:0x0011、0x0012
//长度:头长度+子chunk长度内容:无
const unsigned short MAT_SPECULAR = 0xa030;
const unsigned short MAT_SHININESS = 0xa040;
const unsigned short MAT_TRANSPARENCY = 0xa050;
const unsigned short MAT_SHADING = 0xa100;
const unsigned short N_TRI_OBJECT = 0x4100;//三角形列表
const unsigned short POINT_ARRAY = 0x4110;//定点列表
const unsigned short FACE_ARRAY = 0x4120;//面列表
const unsigned short MSH_MAT_GROUP = 0x4130;//面材质
const unsigned short SMOOTH_GROUP = 0x4150;//面光滑组
const unsigned short MESH_MATRIX = 0x4160;//平移矩阵
const unsigned short COLOR_24 = 0x0011;//字节格式的颜色a
const unsigned short LIN_COLOR_24 = 0x0012;//字节格式的gamma矫正a
const unsigned short COLOR_F = 0x0010;//浮点数格式的颜色a
const unsigned short INT_PERCENTAGE = 0x0030;//字格式的百分比a
const unsigned short FLOAT_PERCENTAGE = 0x0031;//浮点数格式的百分比a
const unsigned short N_DIRECT_LIGHT = 0x4600;//光源块
const unsigned short N_CAMERA = 0x4700;//相机块
const unsigned short KFDATA = 0xb000;//关键帧主chunk,包含所有的关键帧信息
const unsigned short KFHDR = 0xb00a;//未知
const unsigned short KFSEG = 0xb008;//关键帧的起点和终点
//父chunk:0xB000起始帧(一个双字)结尾帧(一个双字)
const unsigned short OBJECT_NODE_TAG = 0xb002;//物体信息开始块
const unsigned short NODE_ID = 0xb030;//关键帧的索引
const unsigned short NODE_HDR = 0xb010;//名称与层次结构描述
const unsigned short PIVOT = 0xb013;//支点坐标
const unsigned short POS_TRACK_TAG = 0xb020;//物体中心点
const unsigned short ROT_TRACK_TAG = 0xb021;//转动的关键帧信息
const unsigned short SCL_TRACK_TAG = 0xb022;//缩放的关键帧信息
#define W_TENS 1
#define W_CONT (1<<1)
#define W_BIAS (1<<2)
#define W_EASETO (1<<3)
#define W_EASEFROM (1<<4)
// 材料的数据结构
struct tMaterial {
float ambientColor[3];
float diffuseColor[3];
float specularColor[3];
float emissiveColor[3];
float shininess;
float transparency;
};
// 定义材料符号表
const int MaxMaterialDictEntries = 256;
class MaterialDict {
private:
char* m_name[MaxMaterialDictEntries];
long m_count;
tMaterial m_material[MaxMaterialDictEntries];
public:
void Clear(void)
{
for (int i = 0; i < m_count; i++) {
if (m_name[i] != NULL) {
delete [] m_name[i];
}
}
m_count = 0;
}
MaterialDict(void)
{
m_count = 0;
for (int i = 0; i < MaxMaterialDictEntries; i++) {
m_name[i] = NULL;
}
}
~MaterialDict(void)
{
Clear();
}
tMaterial* Lookup(char* name)
{
for (long i = 0; i < m_count; i++) {
if (strcmp(name, m_name[i]) == 0) {
return &m_material[i];
}
}
return NULL;
}
void Add(char* name, tMaterial& material)
{
if (Lookup(name) == NULL) {
m_name[m_count] = new char[strlen(name)+1];
strcpy(m_name[m_count], name);
m_material[m_count++] = material;
}
}
tMaterial* operator[](int index)
{
if (index >= 0 && index < m_count) {
return &m_material[index];
}
return NULL;
}
};
struct tVector //位置矢量
{
float x,y,z;
};
struct tVectorRGBA //RGBA颜色
{
float r,g,b,a;
};
struct tQuaternion //四元数
{
float x,y,z,a;
};
struct Key //帧结构
{
float tension;
float continuity;
float bias;
float easeto;
float easefrom;
long time;
};
struct Poskey //Poskey
{
float tension;
float continuity;
float bias;
float easeto;
float easefrom;
long time;
float pos[3];
};
struct Rotkey //Rotkey
{
float tension;
float continuity;
float bias;
float easeto;
float easefrom;
long time;
float angle;
float axis[3];
};
#endif