Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

try with the shader

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