Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/importer/model.h @ 3909

Last change on this file since 3909 was 3909, checked in by bensch, 19 years ago

orxonox/trunk: importer: no more fstream c-style code only

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