Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/static_model.h @ 6618

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

trunk: staticModel now uses vector instead of tArray (more portable)

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