Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/model.h @ 6111

Last change on this file since 6111 was 6033, checked in by bensch, 19 years ago

orxonox/trunk: model now also implements a Draw function, based on what it knows and patrick did

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