Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/model.h @ 3420

Last change on this file since 3420 was 3418, checked in by bensch, 20 years ago

orxonox/trunk/importer: added primitive sphere, but it still has some errors on it

File size: 4.0 KB
Line 
1/*!
2  \file model.h
3  \brief Contains the Model Class that handles 3D-Models
4*/
5
6#ifndef _MODEL_H
7#define _MODEL_H
8
9#include "../stdincl.h"
10
11#include "array.h"
12#include "material.h"
13#include "vector.h"
14
15using namespace std;
16
17enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER};
18
19//! Class that handles 3D-Models. it can also read them in and display them.
20class Model
21{
22 public:
23  Model(void);
24  Model(PRIMITIVE type);
25  Model(char* modelName);
26  virtual ~Model(void);
27
28  void setName(const char* name);
29 
30  void draw(void) const;
31  void draw(int groupNumber) const;
32  void draw(char* groupName) const;
33  int getGroupCount() const;
34
35 protected:
36  char* name;            //!< This is the name of the Model.
37  bool finalized;        //!< Sets the Object to be finalized.
38 
39  //! This is the placeholder of one Vertex beloning to a Face.
40  struct FaceElement
41  {
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.
45    FaceElement* next;   //!< Point to the next FaceElement in this List.
46  };
47
48  //! This is the placeholder of a Face belonging to a Group of Faces.
49  struct Face
50  {
51    int vertexCount;        //!< The Count of vertices this Face has.
52    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
53
54    char* materialString;   //!< The Name of the Material to which to Change.
55
56    Face* next;             //!< Pointer to the next Face.
57  }; 
58
59  //! Group to handle multiple Models per obj-file.
60  struct Group
61  {
62    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
63
64    GLuint listNumber;  //!< The number of the GL-List this Group gets.
65    Face* firstFace;    //!< The first Face in this group.
66    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
67    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...
68    int faceCount;      //!< The Number of Faces this Group holds.
69
70    Group* next;        //!< Pointer to the next Group.
71  };
72
73
74  Array* vertices;      //!< The Array that handles the Vertices.
75  int verticesCount;    //!< A global Counter for vertices.
76  Array* normals;       //!< The Array that handles the Normals.
77  Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
78
79 
80  Group* firstGroup;    //!< The first of all groups.
81  Group* currentGroup;  //!< The currentGroup. this is the one we will work with.
82  int groupCount;       //!< The Count of Groups.
83
84  Material* material;   //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..)
85  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
86
87  bool initialize(void);
88  bool initGroup(Group* group);
89  bool initFace (Face* face);
90  bool cleanup(void);
91  bool cleanupGroup(Group* group);
92  bool cleanupFace(Face* face);
93  bool cleanupFaceElement(FaceElement* faceElem);
94
95 public:
96  bool addGroup(char* groupString);
97  bool addVertex(char* vertexString);
98  bool addVertex(const float x, const float y, const float z);
99  bool addFace(char* faceString);
100  bool addFace(const float faceElemCount, int type, ...);
101  bool addVertexNormal(char* normalString);
102  bool addVertexNormal(const float x, const float y, const float z);
103  bool addVertexTexture(char* vTextureString);
104  bool addVertexTexture(const float u, const float v);
105  bool addUseMtl(char* mtlString);
106  void finalize(void);
107
108 protected:
109  bool importToGL(void);
110  bool addGLElement(FaceElement* elem);
111
112  bool buildVertexNormals(void);
113
114  void cubeModel(void);
115  void sphereModel(void);
116  void cylinderModel(void);
117};
118
119#endif
Note: See TracBrowser for help on using the repository browser.