Kochol Game Engine  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Structs.h
Go to the documentation of this file.
1 // File name: structs.h
2 // Date: 30/5/1385
3 // Programmer: Ali Akbar Mohammadi(Kochol)
4 
5 #ifndef GFX_STRUCTS_H
6 #define GFX_STRUCTS_H
7 
8 #include "../kgedef.h"
9 #include "../math/Matrix.h"
10 #include "../math/Vector.h"
11 #include "Color.h"
12 #include <math.h>
13 
14 namespace kge
15 {
16 namespace gfx
17 {
18 
21 {
22  EVT_V2 = 0,
33 // EVT_P0NT1BT2I3, /**< Vertex3 + Normal vector + Texture coord + Tangent + Binormal in multi stream mode. */
34 // EVT_P0NTC1BT2I3,/**< Vertex3 + Normal vector + Texture coord + Color + Tangent + Binormal + Instance data in multi stream mode. */
35 // EVT_PJ0NT1BT2I3,/**< Vertex3 + Joint index for hardware skinning + Normal vector + Texture coord + Tangent + Binormal + Instance data in multi stream mode. */
36 // EVT_P0NT1I2, /**< Vertex3 + Normal vector + Texture coord + Instance data in multi stream mode. */
37 // EVT_P0NTC1I2, /**< Vertex3 + Normal vector + Texture coord + Color + Instance data in multi stream mode. */
38 // EVT_PJ0NT1I2, /**< Vertex3 + Joint index for hardware skinning + Normal vector + Texture coord + Instance data in multi stream mode. */
39 
42 }; // VertexType
43 
44 struct Vertex2
45 {
46  float X;
47  float Y;
48 }; // Vertex2
49 
51 
52 struct Vertex3
53 {
54  float X;
55  float Y;
56  float Z;
58  Vertex3() : X(0.0f), Y(0.0f), Z(0.0f) {}
59 
60  Vertex3(float x, float y, float z) : X(x), Y(y), Z(z) {}
61 
65  inline void Transform4(math::Matrix * mat)
66  {
67  float xt,yt,zt;
68  xt= X * mat->m_fMat[0] +
69  Y * mat->m_fMat[4] +
70  Z * mat->m_fMat[8] +
71  mat->m_fMat[12];
72  yt= X * mat->m_fMat[1] +
73  Y * mat->m_fMat[5] +
74  Z * mat->m_fMat[9] +
75  mat->m_fMat[13];
76  zt= X * mat->m_fMat[2] +
77  Y * mat->m_fMat[6] +
78  Z * mat->m_fMat[10]+
79  mat->m_fMat[14];
80  X = xt;
81  Y = yt;
82  Z = zt;
83  } // Transform4
84 
85  inline void Transform3(math::Matrix * mat)
86  {
87  float xt,yt,zt;
88  xt= X * mat->m_fMat[0] +
89  Y * mat->m_fMat[4] +
90  Z * mat->m_fMat[8];
91  yt= X * mat->m_fMat[1] +
92  Y * mat->m_fMat[5] +
93  Z * mat->m_fMat[9];
94  zt= X * mat->m_fMat[2] +
95  Y * mat->m_fMat[6] +
96  Z * mat->m_fMat[10];
97  X = xt;
98  Y = yt;
99  Z = zt;
100  } // Transform3
101 
102  inline Vertex3 operator - (const Vertex3 &o) const
103  {
104  Vertex3 r;
105  r.X = X - o.X;
106  r.Y = Y - o.Y;
107  r.Z = Z - o.Z;
108 
109  return r;
110  }
111 
112  inline Vertex3 operator + (const Vertex3 &o) const
113  {
114  Vertex3 r;
115  r.X = X + o.X;
116  r.Y = Y + o.Y;
117  r.Z = Z + o.Z;
118 
119  return r;
120  }
121 
122  inline Vertex3 operator * (const float &f) const
123  {
124  Vertex3 r;
125  r.X = X * f;
126  r.Y = Y * f;
127  r.Z = Z * f;
128 
129  return r;
130  }
131 
132  //inline Vertex3 operator *= (const float &f) const
133  //{
134  // Vertex3 r;
135  // r.X = X * f;
136  // r.Y = Y * f;
137  // r.Z = Z * f;
138 
139  // return r;
140  //}
141 
142  inline void Normalize()
143  {
144  float f = (float)sqrt(X*X + Y*Y + Z*Z);
145  if (f != 0.0f)
146  {
147  X /= f;
148  Y /= f;
149  Z /= f;
150  }
151  } // Normalize
152 
154  {
155  math::Vector v;
156  v.x = X;
157  v.y = Y;
158  v.z = Z;
159  return v;
160 
161  } // ToVector
162 
163  inline void Cross(const Vertex3& v1, const Vertex3& v2)
164  {
165  X=v1.Y*v2.Z-v1.Z*v2.Y;
166  Y=v1.Z*v2.X-v1.X*v2.Z;
167  Z=v1.X*v2.Y-v1.Y*v2.X;
168 
169  } // Cross
170 
171 }; // Vertex3
172 
174 struct Vertex3C
175 {
178 }; // Vertex3C
179 
181 struct Vertex3T
182 {
185 }; // Vertex3T
186 
188 struct Vertex3CT
189 {
193 }; // Vertex3CT
194 
196 struct Vertex3TN
197 {
201 }; // Vertex3TN
202 
205 {
210 
211 }; // Vertex3TTN
212 
215 {
216  Vertex3 pos; //*< Makane Vertex.
217  Vertex3 Nor; //*< Normal Vector.
218  Vertex2 tex; //*< Makane Texture.
219  float Color;
220 }; // Vertex3TNC
221 
223 struct VertexNTC
224 {
225  Vertex3 Nor; //*< Normal Vector.
226  Vertex2 tex; //*< Texture coordinate.
229 }; // Vertex3TNC
230 
232 struct Vertex3I
233 {
235  int BoneID;
236 };
237 
240 {
241  u32 TextureID; //*< Texture ha dar renderer ba in shenase ha shenakhte mishavand.
242  char* Name; //*< Texture name.
243 
244 }; // Texture.
245 
248 {
255 };
256 
258 struct LightData
259 {
271  float Range;
273  float Theta;
275  float Phi;
279  int Index;
280 
281 }; // LightSpot
282 
285 {
290 }; // FogType
291 
292 // byte-align structures
293 #ifdef _MSC_VER
294 # pragma pack(push, packing)
295 # pragma pack(1)
296 # define PACK_STRUCT
297 #elif defined(__GNUC__)
298 # define PACK_STRUCT __attribute__((packed))
299 #else
300 # error compiler not supported
301 #endif
302 
303 // Rotation/Translation information for joints
304 struct KeyFrame
305 {
306  float m_fTime;
307  float m_fParam[3];
308 } PACK_STRUCT; // KeyFrame
309 
310 // Bone Joints for animation
311 struct Joint
312 {
313  char m_cName[32]; //Bone name
314  Vertex3 m_vRotation; //Starting rotation
315  Vertex3 m_vPosition; //Starting position
316  u16 m_usNumRotFrames; //Number of rotation frames
317  u16 m_usNumTransFrames; //Number of translation frames
318  KeyFrame * m_RotKeyFrames; //Rotation keyframes
319  KeyFrame * m_TransKeyFrames; //Translation keyframes
320  short m_sParent; //Parent joint index
326 } PACK_STRUCT; // Joint
327 
328 // Default alignment
329 #ifdef _MSC_VER
330 # pragma pack(pop, packing)
331 #endif
332 
333 #undef PACK_STRUCT
334 
335 } // gfx
336 
337 } // kge
338 
339 #endif // GFX_STRUCTS_H