Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/lib/graphics/importer/static_model.h @ 9164

Last change on this file since 9164 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 5.1 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 public:
97  StaticModel(const std::string& modelName = "");
98  virtual ~StaticModel();
99
100  virtual void draw() const;
101  void draw(int groupNumber) const;
102  void draw(const std::string& groupName) const;
103
104  void rebuild();
105
106  Material* addMaterial(Material* material);
107  Material* addMaterial(const std::string& materialName);
108
109  bool addGroup(const std::string& groupString);
110
111  bool addVertex(const std::string& vertexString);
112  bool addVertex(float x, float y, float z);
113
114  bool addFace(const std::string& faceString);
115  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
116
117  bool addVertexNormal(const std::string& normalString);
118  bool addVertexNormal(float x, float y, float z);
119
120  bool addVertexTexture(const std::string& vTextureString);
121  bool addVertexTexture(float u, float v);
122
123  bool setMaterial(const std::string& mtlString);
124  bool setMaterial(Material* mtl);
125
126  void finalize();
127
128
129 protected:
130  void cubeModel();
131
132  Material* findMaterialByName(const std::string& materialName);
133
134 protected:
135  float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
136
137 private:
138  bool buildVertexNormals();
139
140  bool importToDisplayList();
141  bool buildTriangleList();
142
143  bool addGLElement(ModelFaceElement* elem);
144
145  bool cleanup();
146
147 private:
148  bool                       finalized;       //!< Sets the Object to be finalized.
149
150  unsigned int               faceCount;       //!< A modelwide Counter for the faces
151
152  std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
153  std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
154  std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
155
156  ModelGroup*                firstGroup;      //!< The first of all groups.
157  ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
158  int                        groupCount;      //!< The Count of Groups.
159
160  std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
161};
162
163#endif
Note: See TracBrowser for help on using the repository browser.