Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h @ 4234

Last change on this file since 4234 was 4234, checked in by patrick, 19 years ago

orxonox/branches/md2_loader: fixed the segfault bug: the glcommand list had some offset problems :)

File size: 6.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer:
14*/
15
16/*!
17    \file abstract_model.h
18    \brief Definition of an abstract model. containing all needed for other model
19*/
20
21#ifndef _ABSTRACT_MODEL_H
22#define _ABSTRACT_MODEL_H
23
24#include "stdincl.h"
25#include "base_object.h"
26#include <vector>
27#include <math.h>
28#include <SDL_image.h>
29
30using namespace std;
31
32
33
34//! this is a small and performant 3D vector
35typedef float sVec3D[3];
36
37//! small and performant 2D vector
38typedef float sVec2D[2];
39
40//! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading
41typedef struct
42{
43  byte v[3];
44  unsigned char lightNormalIndex;
45} sVertex;
46
47//! compressed texture offset data: coords scaled by the texture size. Only for loading
48typedef struct
49{
50  short s,t;
51} sTexCoor;
52
53
54//! holds tha informations about a md2 frame
55typedef struct
56{
57  sVec3D scale;                        //!< scales values of the model
58  sVec3D translate;                    //!< translates the model
59  char name[16];                       //!< frame name: something like "run32"
60  sVertex pVertices[1];                //!< first vertex of thes frame
61} sFrame;
62
63
64//! holds the information about a triangle
65typedef struct
66{
67  short indexToVertices[3];             //!< index to the verteces of the triangle
68  short indexToTexCoor[3];              //!< index to the texture coordinates
69} sTriangle;
70
71
72typedef struct
73{
74   float s, t;
75   int vertexIndex;
76} glCommandVertex;
77
78
79//! a md2 animation definition
80typedef struct
81{
82  int firstFrame;                       //!< first frame of the animation
83  int lastFrame;                        //!< last frame of the animation
84  int fps;                              //!< speed: number of frames per second
85} sAnim;
86
87//! animation state definition
88typedef struct
89{
90  int startFrame;
91  int endFrame;
92  int fps;
93
94  float localTime;
95  float lastTime;
96  float interpolationState;            //!< the state of the animation [0..1]
97 
98  int type;                            //!< animation type
99
100  int currentFrame;
101  int nextFrame;
102} sAnimState;
103
104
105//! This is our 3D point class.  CONFLICTING with Vector.cc
106class CVector3
107{
108 public:
109  float x, y, z;
110};
111
112//! This is our 2D point class.  CONFLICTING with Vector.cc
113class CVector2
114{
115 public:
116  float x, y;
117};
118
119// CONFLICTING with model.h
120struct tFace
121{
122  int vertIndex[3];                     // indicies for the verts that make up this triangle
123  int coordIndex[3];                    // indicies for the tex coords to texture this face
124};
125
126// CONFLICTING with material.cc, there are some small differences, i will use this struct and switch over later
127struct tMaterialInfo
128{
129  char  strName[255];                   // The texture name
130  char  strFile[255];                   // The texture file name (If this is set it's a texture map)
131  byte  color[3];       // The color of the object (R, G, B)
132  int   texureId;                               // the texture ID
133  float uTile;                          // u tiling of texture 
134  float vTile;                          // v tiling of texture 
135  float uOffset;                                // u offset of texture
136  float vOffset;                                // v offset of texture
137} ;
138
139//! properties of a 3D object
140struct t3DObject
141{
142  int  numOfVerts;                      // The number of verts in the model
143  int  numOfFaces;                      // The number of faces in the model
144  int  numTexVertex;                    // The number of texture coordinates
145  int  materialID;                      // The texture ID to use, which is the index into our texture array
146  bool bHasTexture;                     // This is TRUE if there is a texture map for this object
147  char strName[255];                    // The name of the object
148  CVector3  *pVerts;                    // The object's vertices
149  CVector3  *pNormals;                  // The object's normals
150  CVector2  *pTexVerts;                 // The texture's UV coordinates
151  tFace *pFaces;                                // The faces information of the object
152};
153
154// CONFLICTING with animation.cc
155struct tAnimationInfo
156{
157  char strName[255];                    // This stores the name of the animation (Jump, Pain, etc..)
158  int startFrame;                               // This stores the first frame number for this animation
159  int endFrame;                         // This stores the last frame number for this animation
160};
161
162// CONFLICTING with animation.cc and vector.cc
163struct t3DModel
164{
165  int numOfObjects;                                     // The number of objects in the model
166  int numOfMaterials;                                   // The number of materials for the model
167  int numOfAnimations;                          // The number of animations in this model (NEW)
168  int currentAnim;                                      // The current index into pAnimations list (NEW)
169  int currentFrame;                                     // The current frame of the current animation (NEW)
170  vector<tAnimationInfo> animationList; // The list of animations (NEW)
171  vector<tMaterialInfo> materialList;   // The list of material information (Textures and colors)
172  vector<t3DObject> objectList;                 // The object list for our model
173};
174
175
176
177//! This class defines the basic components of a model
178class AbstractModel : public BaseObject {
179
180 public:
181  AbstractModel() {}
182  virtual ~AbstractModel() {}
183};
184
185
186/* TESTING TESTING TESTING */
187/* some mathematical functions that are already implemented by vector.cc class */
188
189// magnitude of a normal
190#define Mag(Normal) (sqrt(Normal.x*Normal.x + Normal.y*Normal.y + Normal.z*Normal.z))
191
192class MathHelp {
193
194 public:
195  // vector between two points
196  static CVector3 VectorDiff(CVector3 vPoint1, CVector3 vPoint2)
197    {
198      CVector3 vVector;                                                 
199
200      vVector.x = vPoint1.x - vPoint2.x;                       
201      vVector.y = vPoint1.y - vPoint2.y;                       
202      vVector.z = vPoint1.z - vPoint2.z;                       
203
204      return vVector;                                                           
205    }
206
207  // adding vectors, returning result
208  static CVector3 AddVector(CVector3 vVector1, CVector3 vVector2)
209    {
210      CVector3 vResult;                                                 
211       
212      vResult.x = vVector2.x + vVector1.x;             
213      vResult.y = vVector2.y + vVector1.y;             
214      vResult.z = vVector2.z + vVector1.z;             
215
216      return vResult;
217    }
218
219  // This divides a vector by a single number (scalar) and returns the result
220  static CVector3 DivideVectorByScaler(CVector3 vVector1, float Scaler)
221    {
222      CVector3 vResult;                                                 
223       
224      vResult.x = vVector1.x / Scaler;                 
225      vResult.y = vVector1.y / Scaler;         
226      vResult.z = vVector1.z / Scaler;
227
228      return vResult;   
229    }
230
231  // cross product between 2 vectors
232  static CVector3 CrossProduct(CVector3 vVector1, CVector3 vVector2)
233    {
234      CVector3 vCross; 
235      vCross.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
236      vCross.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
237      vCross.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
238      return vCross;   
239    }
240
241  // calculate the normal of a vector
242  static CVector3 NormalizeVector(CVector3 vNormal)
243    {
244      double Magnitude;
245      Magnitude = Mag(vNormal); 
246      vNormal.x /= (float)Magnitude;   
247      vNormal.y /= (float)Magnitude;   
248      vNormal.z /= (float)Magnitude;   
249
250      return vNormal;   
251    }
252};
253
254
255#endif /* _ABSTRACT_MODEL_H */
Note: See TracBrowser for help on using the repository browser.