-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes3ds.h
158 lines (135 loc) · 2.15 KB
/
types3ds.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef _TYPES3DS_H_
#define _TYPES3DS_H_
#include <cmath>
template <typename T>
void deleteElement(T *p)
{
delete p;
}
typedef unsigned char Byte;
typedef unsigned short Word;
typedef unsigned int DWord;
enum Axis { x, y, z };
struct ChunkHeader
{
Word id;
DWord length;
};// __attribute__((packed));
struct Color
{
Color(): r(1.f), g(1.f), b(1.f), a(1.f) {}
GLfloat r, g, b, a;
};
struct Vector
{
Vector(GLfloat x = 0.f, GLfloat y = 0.f, GLfloat z = 0.f): x(x), y(y), z(z) {}
Vector(const Vector &v)
{
x = v.x;
y = v.y;
z = v.z;
}
Vector &operator +=(const Vector &v)
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Vector &operator -=(const Vector &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Vector operator *(const Vector &v) const
{
Vector r;
r.x = y*v.z - v.y*z;
r.y = z*v.x - v.z*x;
r.z = x*v.y - v.x*y;
return r;
}
GLfloat dotProduct(const Vector &v) const
{
return x*v.x + y*v.y + z*v.z;
}
Vector operator *(GLfloat c) const
{
Vector r;
r.x = x*c;
r.y = y*c;
r.z = z*c;
return r;
}
float length() const
{
return sqrt(x*x + y*y + z*z);
}
Vector normalize()
{
GLfloat length = this->length();
x /= length;
y /= length;
z /= length;
return *this;
}
Vector normalized() const
{
Vector r(*this);
r.normalize();
return r;
}
Vector operator +(const Vector &v) const
{
Vector r;
r.x = x+v.x;
r.y = y+v.y;
r.z = z+v.z;
return r;
}
Vector operator -(const Vector &v) const
{
Vector r;
r.x = x-v.x;
r.y = y-v.y;
r.z = z-v.z;
return r;
}
GLfloat x, y, z;
};
typedef Vector Vertex;
struct Face
{
Word vertexA, vertexB, vertexC;
};
struct MapCoord
{
GLfloat u, v;
};
struct Material
{
Material(): name(NULL), texmapFile(NULL) {}
~Material()
{
delete [] name;
delete [] texmapFile;
}
char *name, *texmapFile;
Color ambient, diffuse, specular;
GLuint textureRef;
};
struct VertexList
{
VertexList(): material(NULL), verticesRefs(NULL), numVerticesRefs(0) {}
~VertexList()
{
if (verticesRefs != NULL)
delete [] verticesRefs;
}
Material *material;
Word *verticesRefs;
DWord numVerticesRefs;
};
#endif // _TYPES3DS_H_