Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7788 was 7221, checked in by bensch, 18 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
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
[3657]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
[4468]20
[3894]21//! an enumerator for VERTEX_FORMAT
[4830]22typedef enum VERTEX_FORMAT {
23  VERTEX_ONLY = VERTEX,
24  VERTEX_NORMAL = NORMAL,
25  VERTEX_TEXCOORD = TEXCOORD,
26  VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
27};
[2842]28
[4022]29////////////////////
30/// SUB-ELEMENTS ///
31////////////////////
32//! This is the placeholder of one Vertex beloning to a Face.
33class ModelFaceElement
[2748]34{
[4022]35 public:
36  ModelFaceElement();
37  ~ModelFaceElement();
[3063]38
[4577]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.
[4468]42
[4577]43  ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
[4022]44};
[3063]45
[4022]46//! This is the placeholder of a Face belonging to a Group of Faces.
47class ModelFace
48{
49 public:
50  ModelFace();
51  ~ModelFace();
[4577]52
53  unsigned int        vertexCount;     //!< The Count of vertices this Face has.
[4468]54  ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
55  Material*           material;        //!< The Material to use.
[4577]56
[4468]57  ModelFace*          next;            //!< Pointer to the next Face.
[4577]58};
[3063]59
[4022]60//! Group to handle multiple Models per obj-file.
61class ModelGroup
62{
63 public:
64  ModelGroup();
65  ~ModelGroup();
[2850]66
[4022]67  void cleanup();
[2850]68
[7221]69  std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
[4468]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.)
[4836]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...
[4468]75  int          faceCount;      //!< The Number of Faces this Group holds.
[4577]76
[4468]77  ModelGroup*  next;           //!< Pointer to the next Group.
[4022]78};
[2850]79
[5304]80struct ModelMaterial
81{
82  Material* material;
83  bool external;
84};
85
[4022]86/////////////
87/// MODEL ///
88/////////////
[6021]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
[4022]95{
[3398]96 public:
[7221]97  StaticModel(const std::string& modelName = "");
[6021]98  virtual ~StaticModel();
[3910]99
[6021]100  virtual void draw() const;
[3910]101  void draw(int groupNumber) const;
[7221]102  void draw(const std::string& groupName) const;
[3910]103
[5790]104  void rebuild();
105
[3913]106  Material* addMaterial(Material* material);
[7221]107  Material* addMaterial(const std::string& materialName);
[3913]108
[7221]109  bool addGroup(const std::string& groupString);
[6031]110
[7221]111  bool addVertex(const std::string& vertexString);
[3894]112  bool addVertex(float x, float y, float z);
[6031]113
[7221]114  bool addFace(const std::string& faceString);
[3895]115  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
[6031]116
[7221]117  bool addVertexNormal(const std::string& normalString);
[3894]118  bool addVertexNormal(float x, float y, float z);
[6031]119
[7221]120  bool addVertexTexture(const std::string& vTextureString);
[3894]121  bool addVertexTexture(float u, float v);
[6031]122
[7221]123  bool setMaterial(const std::string& mtlString);
[3913]124  bool setMaterial(Material* mtl);
[6031]125
[4746]126  void finalize();
[4106]127
[4468]128
129 protected:
[4746]130  void cubeModel();
[4468]131
[7221]132  Material* findMaterialByName(const std::string& materialName);
[4468]133
[4529]134 protected:
[4836]135  float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
[4529]136
[4468]137 private:
[4746]138  bool buildVertexNormals();
[4468]139
[4746]140  bool importToDisplayList();
[4791]141  bool buildTriangleList();
[6031]142
[4468]143  bool addGLElement(ModelFaceElement* elem);
144
[4746]145  bool cleanup();
[4468]146
147 private:
[5774]148  bool                       finalized;       //!< Sets the Object to be finalized.
[4468]149
[5774]150  unsigned int               faceCount;       //!< A modelwide Counter for the faces
[4468]151
[6423]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.
[6031]155
[5774]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.
[4468]159
[5774]160  std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
[2748]161};
[2773]162
163#endif
Note: See TracBrowser for help on using the repository browser.