Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3433 was 3427, checked in by bensch, 20 years ago

orxonox/trunk/importer: cleaned up the includes, while watching some Monty Python

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