Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/abstract_model.h @ 6009

Last change on this file since 6009 was 6009, checked in by bensch, 18 years ago

orxonox/trunk: abstract model implementation in .cc

@patrick: do you aprove?

File size: 5.5 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 *  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 "base_object.h"
25#include "vector.h"
26
27using namespace std;
28
29
30
31//! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading
32typedef struct
33{
34  char             v[3];                 //!< the vector of the vertex
35  unsigned char    lightNormalIndex;     //!< the index of the light normal
36} sVertex;
37
38
39//! compressed texture offset data: coords scaled by the texture size. Only for loading
40typedef struct
41{
42  short            s;                    //!< the s,t coordinates of a texture
43  short            t;                    //!< the s,t coordinates of a texture
44} sTexCoor;
45
46
47//! holds tha informations about a md2 frame
48typedef struct
49{
50  sVec3D           scale;                //!< scales values of the model
51  sVec3D           translate;            //!< translates the model
52  char             name[16];             //!< frame name: something like "run32"
53  sVertex          pVertices[1];         //!< first vertex of thes frame
54} sFrame;
55
56
57//! holds the information about a triangle
58typedef struct
59{
60  unsigned short   indexToVertices[3];   //!< index to the verteces of the triangle
61  unsigned short   indexToTexCoor[3];    //!< index to the texture coordinates
62} sTriangle;
63
64
65//! holds the information about a triangle
66typedef struct
67{
68  unsigned int   indexToVertices[3];   //!< index to the verteces of the triangle
69  unsigned int   indexToNormals[3];    //!< index to the normals of the triangle
70  unsigned int   indexToTexCoor[3];    //!< index to the texture coordinates
71} sTriangleExt;
72
73
74//! the command list of the md2 model, very md2 specific
75typedef struct
76{
77  float            s;                    //!< texture coordinate 1
78  float            t;                    //!< texture coordinate 2
79  int              vertexIndex;          //!< index of the vertex in the vertex list
80} glCommandVertex;
81
82
83//! a md2 animation definition
84typedef struct
85{
86  int              firstFrame;           //!< first frame of the animation
87  int              lastFrame;            //!< last frame of the animation
88  int              fps;                  //!< speed: number of frames per second
89} sAnim;
90
91
92//! animation state definition
93typedef struct
94{
95  int              startFrame;           //!< the start frame of an animation
96  int              endFrame;             //!< last frame of the animation
97  int              fps;                  //!< fps of the animaion (speed)
98
99  float            localTime;            //!< the local time
100  float            lastTime;             //!< last time stamp
101  float            interpolationState;   //!< the state of the animation [0..1]
102
103  int              type;                 //!< animation type
104
105  int              currentFrame;         //!< the current frame
106  int              nextFrame;            //!< the next frame in the list
107} sAnimState;
108
109//! Model Information definitions
110typedef struct
111{
112  unsigned int     numVertices;          //!< number of Vertices in the Model
113  unsigned int     numTriangles;         //!< number of triangles in the Model
114  unsigned int     numNormals;           //!< how many Normals in the Model
115  unsigned int     numTexCoor;           //!< how many Texture Coordinates in the Model
116
117  const float*     pVertices;            //!< array of the Vertives
118  sTriangleExt*    pTriangles;           //!< array of all triangles
119  const float*     pNormals;             //!< array of the Normals
120  const float*     pTexCoor;             //!< array of the Texture Coordinates
121
122} modelInfo;
123
124
125
126//! This class defines the basic components of a model
127class AbstractModel : public BaseObject {
128
129  public:
130    AbstractModel();
131    virtual ~AbstractModel();
132
133    inline const modelInfo* getModelInfo() const { return &this->pModelInfo; }
134
135    /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
136    inline const float* getVertexArray() const { return this->pModelInfo.pVertices; };
137    /** @returns the VertexCount of this Model */
138    inline unsigned int getVertexCount() const { return this->pModelInfo.numVertices; };
139
140    /** @returns a Pointer to the Normals-Array, if it was deleted it returns NULL */
141    inline const float* getNormalsArray() const { return this->pModelInfo.pNormals; };
142    /** @returns the NormalsCount of this Model */
143    inline unsigned int getNormalsCount() const { return this->pModelInfo.numNormals; };
144
145    /** @returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */
146    inline const float* getTexCoordArray() const { return this->pModelInfo.pTexCoor; };
147    /** @returns the TexCoord-Count of this Model */
148    inline unsigned int getTexCoordCount() const { return this->pModelInfo.numTexCoor; };
149
150    /** @returns the Array of triangles */
151    inline sTriangleExt* getTriangles() const { return this->pModelInfo.pTriangles; };
152    /** @returns the Count of Faces of this Model */
153    inline unsigned int getFaceCount() const { return this->pModelInfo.numTriangles; };
154
155
156  protected:
157    modelInfo      pModelInfo;      //!< Reference to the modelInfo
158};
159
160#endif /* _ABSTRACT_MODEL_H */
Note: See TracBrowser for help on using the repository browser.