Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/importer/static_model.h @ 9684

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

orxonox/branches/new_class_id: slowly but surely reimplementing to the new groove… way to go

File size: 5.2 KB
Line 
1/*!
2 * @file static_model.h
3 * @brief Contains the Model Class that handles Static 3D-Models rendered with glList's
4 */
5
6#ifndef _STATIC_MODEL_H
7#define _STATIC_MODEL_H
8
9#include "model.h"
10
11#include "material.h"
12#include "glincl.h"
13#include <vector>
14#include <list>
15
16// definition of different modes for setting up Faces
17#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
18#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
19#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
20
21//! an enumerator for VERTEX_FORMAT
22typedef enum VERTEX_FORMAT {
23  VERTEX_ONLY = VERTEX,
24  VERTEX_NORMAL = NORMAL,
25  VERTEX_TEXCOORD = TEXCOORD,
26  VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
27};
28
29////////////////////
30/// SUB-ELEMENTS ///
31////////////////////
32//! This is the placeholder of one Vertex beloning to a Face.
33class ModelFaceElement
34{
35 public:
36  ModelFaceElement();
37  ~ModelFaceElement();
38
39  int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
40  int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
41  int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
42
43  ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
44};
45
46//! This is the placeholder of a Face belonging to a Group of Faces.
47class ModelFace
48{
49 public:
50  ModelFace();
51  ~ModelFace();
52
53  unsigned int        vertexCount;     //!< The Count of vertices this Face has.
54  ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
55  Material*           material;        //!< The Material to use.
56
57  ModelFace*          next;            //!< Pointer to the next Face.
58};
59
60//! Group to handle multiple Models per obj-file.
61class ModelGroup
62{
63 public:
64  ModelGroup();
65  ~ModelGroup();
66
67  void cleanup();
68
69  std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
70  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
71  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
72  ModelFace*   firstFace;      //!< The first Face in this group.
73  ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
74  int          faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM...
75  int          faceCount;      //!< The Number of Faces this Group holds.
76
77  ModelGroup*  next;           //!< Pointer to the next Group.
78};
79
80struct ModelMaterial
81{
82  Material* material;
83  bool external;
84};
85
86/////////////
87/// MODEL ///
88/////////////
89//! Class that handles static 3D-Models.
90/**
91 * it can also read them in and display them.
92 * All the objects are rendered with glLists
93 */
94class StaticModel : public Model
95{
96  NewObjectListDeclaration(StaticModel);
97  public:
98  StaticModel(const std::string& modelName = "");
99  virtual ~StaticModel();
100
101  virtual void draw() const;
102  void draw(int groupNumber) const;
103  void draw(const std::string& groupName) const;
104
105  void rebuild();
106
107  Material* addMaterial(Material* material);
108  Material* addMaterial(const std::string& materialName);
109
110  bool addGroup(const std::string& groupString);
111
112  bool addVertex(const std::string& vertexString);
113  bool addVertex(float x, float y, float z);
114
115  bool addFace(const std::string& faceString);
116  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
117
118  bool addVertexNormal(const std::string& normalString);
119  bool addVertexNormal(float x, float y, float z);
120
121  bool addVertexTexture(const std::string& vTextureString);
122  bool addVertexTexture(float u, float v);
123
124  bool setMaterial(const std::string& mtlString);
125  bool setMaterial(Material* mtl);
126
127  void finalize();
128
129
130 protected:
131  void cubeModel();
132
133  Material* findMaterialByName(const std::string& materialName);
134
135 protected:
136  float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
137
138 private:
139  bool buildVertexNormals();
140
141  bool importToDisplayList();
142  bool buildTriangleList();
143
144  bool addGLElement(ModelFaceElement* elem);
145
146  bool cleanup();
147
148 private:
149  bool                       finalized;       //!< Sets the Object to be finalized.
150
151  unsigned int               faceCount;       //!< A modelwide Counter for the faces
152
153  std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
154  std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
155  std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
156
157  ModelGroup*                firstGroup;      //!< The first of all groups.
158  ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
159  int                        groupCount;      //!< The Count of Groups.
160
161  std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
162};
163
164#endif
Note: See TracBrowser for help on using the repository browser.