Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/importer/model.cc @ 3913

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

orxonox/trunk: importer: functionality improvement

File size: 23.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
17
18#include "model.h"
19
20#include <math.h>
21#include <stdarg.h>
22
23#include "array.h"
24#include "vector.h"
25#include "list.h"
26
27using namespace std;
28
29//////////////////
30// DE-CONSTRUCT //
31//////////////////
32/**
33   \brief Creates a 3D-Model. and assigns it a Name.
34*/
35Model::Model(const char* modelName)
36{
37  PRINTF(4)("new 3D-Model is being created\n"); 
38  this->name = NULL;
39  this->setName(modelName);
40
41
42  this->finalized = false;
43  // setting the start group;
44  this->firstGroup = new Group;
45  this->currentGroup = this->firstGroup;
46  this->groupCount = 0;
47 
48  this->initGroup (this->currentGroup);
49  this->scaleFactor = 1;
50  this->material = new Material();
51
52  this->vertices = new Array();
53  this->vTexture = new Array();
54  this->normals = new Array();
55
56  this->materialList = new tList<Material>;
57}
58
59/**
60   \brief deletes an Model.
61
62   Looks if any from model allocated space is still in use, and if so deleted it.
63*/
64Model::~Model(void)
65{
66  PRINTF(4)("Deleting Model ");
67  if (this->name)
68    {
69      PRINT(4)("%s\n", this->name);
70      delete []this->name;
71    }
72  else
73      PRINT(4)("\n");
74
75  PRINTF(5)("Deleting display Lists.\n");
76  Group* walker = this->firstGroup;
77  while (walker != NULL)
78    {
79      glDeleteLists (walker->listNumber, 1);
80      Group* delWalker = walker;
81      walker = walker->next;
82      delete delWalker;
83    }
84
85  PRINTF(5)("Deleting Materials.\n");
86  if (this->material)
87    delete this->material;
88
89  // deleting the MaterialList
90  delete materialList;
91}
92
93/**
94   \brief Finalizes an Object. This can be done outside of the Class.
95*/
96void Model::finalize(void)
97{
98  this->importToGL ();
99 
100  this->cleanup();
101
102  this->finalized = true;
103}
104
105//////////
106// DRAW //
107//////////
108/**
109   \brief Draws the Models of all Groups.
110   It does this by just calling the Lists that must have been created earlier.
111*/
112void Model::draw (void) const
113{
114  PRINTF(4)("drawing the 3D-Models\n"); 
115  Group* walker = this->firstGroup;
116  while (walker != NULL)
117    {
118      PRINTF(5)("Drawing model %s\n", walker->name);
119      glCallList (walker->listNumber);
120      walker = walker->next;
121    }
122}
123
124/**
125   \brief Draws the Model number groupNumber
126   \param groupNumber The number of the group that will be displayed.
127
128   It does this by just calling the List that must have been created earlier.
129*/
130void Model::draw (int groupNumber) const 
131{
132  if (groupNumber >= this->groupCount)
133    {
134      PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
135      return;
136    }
137  PRINTF(4)("drawing the requested 3D-Models if found.\n"); 
138  Group* walker = this->firstGroup;
139  int counter = 0;
140  while (walker != NULL)
141    {
142      if (counter == groupNumber)
143        {
144          PRINTF(4)("Drawing model number %i named %s\n", counter, walker->name);
145          glCallList (walker->listNumber);
146          return;
147        }
148      ++counter;
149      walker = walker->next;
150    }
151  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->name);
152  return;
153
154}
155
156/**
157   \brief Draws the Model with a specific groupName
158   \param groupName The name of the group that will be displayed.
159
160   It does this by just calling the List that must have been created earlier.
161*/
162void Model::draw (char* groupName) const
163{
164  PRINTF(4)("drawing the requested 3D-Models if found.\n"); 
165  Group* walker = this->firstGroup;
166  while (walker != NULL)
167    {
168      if (!strcmp(walker->name, groupName))
169        {
170          PRINTF(4)("Drawing model %s\n", walker->name);
171          glCallList (walker->listNumber);
172          return;
173        }
174      walker = walker->next;
175    }
176  PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->name);
177  return;
178}
179
180/**
181   \returns Count of the Models in this File
182*/
183int Model::getGroupCount (void) const
184{
185  return this->groupCount;
186}
187
188//////////
189// INIT //
190//////////
191/**
192   \brief sets a name to the Model
193   \param name The name to set to this Model
194*/
195void Model::setName(const char* name)
196{
197  if (this->name) 
198    delete this->name;
199  if (name)
200    {
201      this->name = new char[strlen(name)+1];
202      strcpy(this->name, name);
203    }
204  else 
205    this->name = NULL;
206}
207
208/**
209   \brief initializes a new Group model
210   \param group the group that should be initialized.
211   \todo Maybe Group should be a Class, because it does a lot of stuff
212   
213*/
214bool Model::initGroup(Group* group)
215{
216  PRINTF(4)("Adding new Group\n");
217  group->name = "";
218  group->faceMode = -1;
219  group->faceCount = 0; 
220  group->next = NULL;
221
222  group->firstFace = new Face;
223  this->initFace (group->firstFace);
224  group->currentFace = group->firstFace;
225}
226
227/**
228   \brief initializes a new Face. (sets default Values)
229   \param face The face to initialize
230*/
231bool Model::initFace (Face* face)
232{
233  face->vertexCount = 0;
234
235  face->firstElem = NULL;
236 
237  face->material = NULL;
238 
239  face->next = NULL;
240
241  return true;
242}
243
244/**
245   \brief finalizes an Model.
246   This funcion is needed, to delete all the Lists, and arrays that are no more needed because they are already imported into openGL. This will be applied at the end of the importing Process.
247*/
248bool Model::cleanup(void)
249{
250  PRINTF(4)("cleaning up the 3D-Model to save Memory.\n");
251
252  if (this->vertices)
253    delete this->vertices;
254  if (this->vTexture)
255    delete this->vTexture;
256  if (this->normals)
257    delete this->normals;
258
259  this->cleanupGroup(this->firstGroup);
260  return true; 
261}
262
263/**
264   \brief Cleans up all groups starting from group.
265   \param group the first Group to clean
266*/
267bool Model::cleanupGroup (Group* group)
268{
269  PRINTF(5)("Cleaning up group\n");
270  if (group->firstFace != NULL)
271    {
272      cleanupFace (group->firstFace);
273      delete group->firstFace;
274    }
275
276  if (group->next !=NULL)
277    cleanupGroup (group->next);
278  return true;
279}
280
281/**
282   \brief Cleans up all Faces starting from face until NULL is reached.
283   \param face the first face to clean.
284*/
285bool Model::cleanupFace (Face* face)
286{
287  PRINTF(5)("Cleaning up Face\n");
288
289  if (face->firstElem != NULL)
290    {
291      this->cleanupFaceElement(face->firstElem);
292      delete face->firstElem;
293    }
294     
295  if (face->next != NULL)
296    {
297      this->cleanupFace (face->next);
298      delete face->next;
299    }
300}
301
302/**
303   \brief Cleans up all FaceElements starting from faceElem.
304   \param faceElem the first FaceElement to clean.
305*/
306bool Model::cleanupFaceElement(FaceElement* faceElem)
307{
308  if (faceElem->next != NULL)
309    {
310      this->cleanupFaceElement (faceElem->next);
311      delete faceElem->next;
312    }
313}
314
315//////////
316// MESH //
317//////////
318/**
319   \brief adds a new Material to the Material List
320   \param material the Material to add
321   \returns the added material
322
323   !! beware the Material will be deleted when the Model gets deleted
324*/
325Material* Model::addMaterial(Material* material)
326{
327  this->materialList->add(material);
328  return material;
329}
330
331/**
332   \brief adds a new Material to the Material List
333   \param material the name of the Material to add
334   \returns the added material
335*/
336Material* Model::addMaterial(const char* materialName)
337{
338 
339  Material* newMat = new Material();
340  newMat->setName(materialName);
341
342  // adding material to the List of materials
343  this->materialList->add(newMat); 
344  return newMat;
345}
346
347Material* Model::findMaterialByName(const char* materialName)
348{
349  tIterator<Material>* tmpIt = this->materialList->getIterator();
350  Material* material = tmpIt->nextElement();
351  while(material)
352    {
353      if (!strcmp(material->getName(), materialName))
354        {
355          delete tmpIt;
356          return material;
357        }
358      material = tmpIt->nextElement();
359    }
360  delete tmpIt;
361  return NULL;
362}
363
364/**
365   \brief parses a group String
366   \param groupString the new Group to create
367
368   This function initializes a new Group.
369   With it you should be able to import .obj-files with more than one Models inside.
370*/
371bool Model::addGroup (const char* groupString)
372{
373  PRINTF(5)("Read Group: %s.\n", groupString);
374  if (this->groupCount != 0 && this->currentGroup->faceCount>0)
375    {
376      //      finalizeGroup(currentGroup);
377      this->currentGroup = this->currentGroup->next = new Group;
378      this->initGroup(this->currentGroup);
379    }
380  // setting the group name if not default.
381  if (strcmp(groupString, "default"))
382    {
383      this->currentGroup->name = new char [strlen(groupString)+1];
384      strcpy(this->currentGroup->name, groupString);
385    }
386  ++this->groupCount;
387}
388
389/**
390   \brief parses a vertex-String
391   \param vertexString The String that will be parsed.
392
393   If a vertex line is found this function will inject it into the vertex-Array
394*/
395bool Model::addVertex (const char* vertexString)
396{
397  float subbuffer1;
398  float subbuffer2;
399  float subbuffer3;
400  sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
401  PRINTF(5)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
402  this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
403  return true;
404}
405
406/**
407   \brief parses a vertex-String
408   \param x the X-coordinate of the Vertex to add.
409   \param y the Y-coordinate of the Vertex to add.
410   \param z the Z-coordinate of the Vertex to add.
411   
412*/
413bool Model::addVertex(float x, float y, float z)
414{
415  PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
416  this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor);
417  return true;
418}
419
420/**
421   \brief parses a vertexNormal-String
422   \param normalString The String that will be parsed.
423
424   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
425*/
426bool Model::addVertexNormal (const char* normalString)
427{
428  float subbuffer1;
429  float subbuffer2;
430  float subbuffer3;
431  sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
432  PRINTF(5)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
433  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
434  return true;
435}
436
437/**
438   \brief adds a VertexNormal.
439   \param x The x coordinate of the Normal.
440   \param y The y coordinate of the Normal.
441   \param z The z coordinate of the Normal.
442
443   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
444*/
445bool Model::addVertexNormal(float x, float y, float z)
446{
447  PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
448  this->normals->addEntry(x, y, z);
449}
450
451/**
452   \brief parses a vertexTextureCoordinate-String
453   \param vTextureString The String that will be parsed.
454
455   If a vertexTextureCoordinate line is found,
456   this function will inject it into the vertexTexture-Array
457*/
458bool Model::addVertexTexture (const char* vTextureString)
459{
460  float subbuffer1;
461  float subbuffer2;
462  sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
463  PRINTF(5)("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2);
464  this->vTexture->addEntry(subbuffer1);
465  this->vTexture->addEntry(subbuffer2);
466  return true;
467}
468
469/**
470   \brief adds a Texture Coordinate
471   \param u The u coordinate of the TextureCoordinate.
472   \param v The y coordinate of the TextureCoordinate.
473
474   If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array
475*/
476bool Model::addVertexTexture(float u, float v)
477{
478  PRINTF(5)("found vertex-Texture %f, %f\n", u, v);
479  this->vTexture->addEntry(u);
480  this->vTexture->addEntry(v);
481}
482
483/**
484   \brief parses a face-string
485   \param faceString The String that will be parsed.
486
487   If a face line is found this function will add it to the glList.
488*/
489bool Model::addFace (const char* faceString)
490{
491  if (this->currentGroup->faceCount >0)
492    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
493  this->initFace (this->currentGroup->currentFace);
494
495  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
496  tmpElem->next = NULL;
497  while(strcmp (faceString, "\0"))
498    {
499      if (this->currentGroup->currentFace->vertexCount>0)
500          tmpElem = tmpElem->next = new FaceElement;
501      tmpElem->next = NULL;
502
503      char tmpValue [50];
504      int tmpLen;
505      char* vertex = NULL;
506      char* texture = NULL;
507      char* normal = NULL;
508
509      sscanf (faceString, "%s", tmpValue);
510      tmpLen = strlen(tmpValue);
511      vertex = tmpValue;
512
513      if ((texture = strstr (vertex, "/")) != NULL)
514        {
515          texture[0] = '\0';
516          texture ++;
517         
518          if ((normal = strstr (texture, "/")) !=NULL)
519            {
520              normal[0] = '\0';
521              normal ++;
522            }     
523        }
524      if (vertex)
525        tmpElem->vertexNumber = atoi(vertex)-1;
526      else
527        tmpElem->vertexNumber = -1;
528      if (texture)
529        tmpElem->texCoordNumber = atoi(texture)-1;
530      else
531        tmpElem->texCoordNumber = -1;
532      if (normal)
533        tmpElem->normalNumber = atoi(normal)-1;
534      else
535        tmpElem->normalNumber = -1;
536
537      faceString += tmpLen;
538      if (strcmp (faceString, "\0"))
539        faceString++;
540      this->currentGroup->currentFace->vertexCount++;
541    }
542
543  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
544}
545
546/**
547   \brief adds a new Face
548   \param faceElemCount the number of Vertices to add to the Face.
549   \param type 0: vertex only, 1: vertex and normal, 2: vertex and Texture, 3 vertex, normal and texture
550*/
551bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
552{
553   if (this->currentGroup->faceCount > 0)
554    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
555  this->initFace (this->currentGroup->currentFace);
556
557  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
558  tmpElem->next = NULL;
559 
560  va_list itemlist;
561  va_start (itemlist, type);
562
563  for (int i = 0; i < faceElemCount; i++)
564    {
565      if (this->currentGroup->currentFace->vertexCount>0)
566          tmpElem = tmpElem->next = new FaceElement;
567      tmpElem->next = NULL;
568
569      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
570      if (type & TEXCOORD)
571        tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
572      if (type & NORMAL)
573        tmpElem->normalNumber = va_arg(itemlist, int) -1;
574      this->currentGroup->currentFace->vertexCount++;
575    }
576  va_end(itemlist);
577
578  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2;
579}
580
581/**
582   \brief Function that selects a material, if changed in the obj file.
583   \param matString the Material that will be set.
584*/
585bool Model::setMaterial(const char* matString)
586{
587  if (this->currentGroup->faceCount > 0)
588    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
589  this->initFace (this->currentGroup->currentFace);
590 
591  this->currentGroup->currentFace->material = material->search(matString);
592
593  if (this->currentGroup->faceCount == 0)
594    this->currentGroup->faceCount ++;
595}
596
597/**
598   \brief Function that selects a material, if changed in the obj file.
599   \param mtl the Material that will be set.
600*/
601bool Model::setMaterial(Material* mtl)
602{
603  if (this->currentGroup->faceCount > 0)
604    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
605  this->initFace (this->currentGroup->currentFace);
606 
607  this->currentGroup->currentFace->material = mtl;
608
609  if (this->currentGroup->faceCount == 0)
610    this->currentGroup->faceCount ++;
611}
612
613/**
614   \brief A routine that is able to create normals.
615
616   The algorithm does the following:
617   1. It calculates creates Vectors for each normale, and sets them to zero.
618   2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
619   3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
620   4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
621*/
622bool Model::buildVertexNormals ()
623{ 
624  PRINTF(4)("Normals are being calculated.\n");
625
626  Vector* normArray = new Vector [vertices->getCount()/3];
627  for (int i=0; i<vertices->getCount()/3;i++)
628    normArray[i] = Vector(.0,.0,.0);
629 
630  int firstTouch;
631  int secondTouch;
632  Vector prevV;
633  Vector nextV;
634  Vector curV;
635
636  Group* tmpGroup = firstGroup;
637  while (tmpGroup)
638    {
639      Face* tmpFace = tmpGroup->firstFace;
640      while (tmpFace)
641        {
642          if (tmpFace->firstElem)
643            {
644              FaceElement* firstElem = tmpFace->firstElem;
645              FaceElement* prevElem;
646              FaceElement* curElem = firstElem;
647              FaceElement* nextElem;
648              FaceElement* lastElem;
649              // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
650              while (curElem)
651                {
652                  prevElem = curElem;
653                  curElem = curElem->next;
654                }
655              lastElem = prevElem;
656             
657              curElem = firstElem;
658              for (int j=0; j<tmpFace->vertexCount; j++)
659                {
660                  if (!(nextElem = curElem->next))
661                    nextElem = firstElem;
662                  curElem->normalNumber = curElem->vertexNumber;
663                 
664                  curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]);
665                  prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
666                  nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV;
667                  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
668
669                  prevElem = curElem;
670                  curElem = curElem->next;
671                }
672            }
673          tmpFace = tmpFace->next;
674        }
675      tmpGroup = tmpGroup->next;
676    }
677
678  for (int i=0; i<vertices->getCount()/3;i++)
679    {
680      normArray[i].normalize();
681      PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
682     
683      this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
684
685    }
686  delete []normArray; 
687}
688
689////////////
690// openGL //
691////////////
692/**
693   \brief reads and includes the Faces/Materials into the openGL state Machine
694*/
695bool Model::importToGL (void)
696{
697
698  // finalize the Arrays
699  this->vertices->finalizeArray();
700  this->vTexture->finalizeArray();
701  if (normals->getCount() == 0) // vertices-Array must be built for this
702    this->buildVertexNormals();
703  this->normals->finalizeArray();
704
705  this->currentGroup = this->firstGroup;
706
707  while (this->currentGroup != NULL)
708    {
709
710      // creating a glList for the Group
711      if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
712        {
713          PRINTF(2)("glList could not be created for this Model\n");
714          return false;
715        }
716      glNewList (this->currentGroup->listNumber, GL_COMPILE);
717
718      // Putting Faces to GL
719      Face* tmpFace = this->currentGroup->firstFace;
720      while (tmpFace != NULL)
721        {
722          if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
723            {
724              if (this->currentGroup->faceMode != -1)
725                glEnd();
726              this->currentGroup->faceMode = 0;
727              Material* tmpMat;
728              if (tmpFace->material != NULL)
729                {
730                  tmpFace->material->select();
731                  PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
732                }
733            }
734
735          else if (tmpFace->vertexCount == 3)
736            {
737              if (this->currentGroup->faceMode != 3)
738                {
739                  if (this->currentGroup->faceMode != -1)
740                    glEnd();
741                  glBegin(GL_TRIANGLES);
742                }
743             
744              this->currentGroup->faceMode = 3;
745              PRINTF(5)("found triag.\n");
746            }
747         
748          else if (tmpFace->vertexCount == 4)
749            {
750              if (this->currentGroup->faceMode != 4)
751                {
752                  if (this->currentGroup->faceMode != -1)
753                    glEnd();
754                  glBegin(GL_QUADS);
755                }
756              this->currentGroup->faceMode = 4;
757              PRINTF(5)("found quad.\n");
758            }
759         
760          else if (tmpFace->vertexCount > 4)
761            {
762              if (this->currentGroup->faceMode != -1)
763                glEnd();
764              glBegin(GL_POLYGON);
765              PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
766              this->currentGroup->faceMode = tmpFace->vertexCount;
767            }
768         
769          FaceElement* tmpElem = tmpFace->firstElem;
770          while (tmpElem != NULL)
771            {
772              //      PRINTF(2)("%s\n", tmpElem->value);
773              this->addGLElement(tmpElem);
774              tmpElem = tmpElem->next;
775            }
776          tmpFace = tmpFace->next;
777        }
778      glEnd();
779      glEndList();
780
781      this->currentGroup = this->currentGroup->next;
782    } 
783}
784
785/**
786   \brief Adds a Face-element (one vertex of a face) with all its information.
787   \param elem The FaceElement to add to the OpenGL-environment.
788
789   It does this by searching:
790   1. The Vertex itself
791   2. The VertexNormale
792   3. The VertexTextureCoordinate
793   merging this information, the face will be drawn.
794*/
795bool Model::addGLElement (FaceElement* elem)
796{
797  PRINTF(5)("importing grafical Element to openGL.\n");
798
799  if (elem->texCoordNumber != -1)
800    glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
801  if (elem->normalNumber != -1)
802    glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
803  if (elem->vertexNumber != -1)
804    glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
805
806}
807
808/**
809   \brief Includes a default model
810
811   This will inject a Cube, because this is the most basic model.
812*/
813void Model::cubeModel(void)
814{
815  this->addVertex (-0.5, -0.5, 0.5);
816  this->addVertex (0.5, -0.5, 0.5);
817  this->addVertex (-0.5, 0.5, 0.5);
818  this->addVertex (0.5, 0.5, 0.5);
819  this->addVertex (-0.5, 0.5, -0.5);
820  this->addVertex (0.5, 0.5, -0.5);
821  this->addVertex (-0.5, -0.5, -0.5);
822  this->addVertex (0.5, -0.5, -0.5);
823
824  this->addVertexTexture (0.0, 0.0);
825  this->addVertexTexture (1.0, 0.0);
826  this->addVertexTexture (0.0, 1.0);
827  this->addVertexTexture (1.0, 1.0);
828  this->addVertexTexture (0.0, 2.0);
829  this->addVertexTexture (1.0, 2.0);
830  this->addVertexTexture (0.0, 3.0);
831  this->addVertexTexture (1.0, 3.0);
832  this->addVertexTexture (0.0, 4.0);
833  this->addVertexTexture (1.0, 4.0);
834  this->addVertexTexture (2.0, 0.0);
835  this->addVertexTexture (2.0, 1.0);
836  this->addVertexTexture (-1.0, 0.0);
837  this->addVertexTexture (-1.0, 1.0);
838
839  this->addVertexNormal (0.0, 0.0, 1.0);
840  this->addVertexNormal (0.0, 0.0, 1.0);
841  this->addVertexNormal (0.0, 0.0, 1.0);
842  this->addVertexNormal (0.0, 0.0, 1.0);
843  this->addVertexNormal (0.0, 1.0, 0.0);
844  this->addVertexNormal (0.0, 1.0, 0.0);
845  this->addVertexNormal (0.0, 1.0, 0.0);
846  this->addVertexNormal (0.0, 1.0, 0.0);
847  this->addVertexNormal (0.0, 0.0, -1.0);
848  this->addVertexNormal (0.0, 0.0, -1.0);
849  this->addVertexNormal (0.0, 0.0, -1.0);
850  this->addVertexNormal (0.0, 0.0, -1.0);
851  this->addVertexNormal (0.0, -1.0, 0.0);
852  this->addVertexNormal (0.0, -1.0, 0.0);
853  this->addVertexNormal (0.0, -1.0, 0.0);
854  this->addVertexNormal (0.0, -1.0, 0.0);
855  this->addVertexNormal (1.0, 0.0, 0.0);
856  this->addVertexNormal (1.0, 0.0, 0.0);
857  this->addVertexNormal (1.0, 0.0, 0.0);
858  this->addVertexNormal (1.0, 0.0, 0.0);
859  this->addVertexNormal (-1.0, 0.0, 0.0);
860  this->addVertexNormal (-1.0, 0.0, 0.0);
861  this->addVertexNormal (-1.0, 0.0, 0.0);
862  this->addVertexNormal (-1.0, 0.0, 0.0);
863
864  /* normaleLess-testingMode
865  this->addFace ("1 2 4 3");
866  this->addFace ("3 4 6 5");
867  this->addFace ("5 6 8 7");
868  this->addFace ("7 8 2 1");
869  this->addFace ("2 8 6 4");
870  this->addFace ("7 1 3 5");
871  */
872
873  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
874  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
875  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
876  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
877  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
878  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
879
880}
Note: See TracBrowser for help on using the repository browser.