| 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: Patrick Boenzli | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MODEL | 
|---|
| 17 |  | 
|---|
| 18 | #include "model.h" | 
|---|
| 19 | #include "debug.h" | 
|---|
| 20 | #include "glincl.h" | 
|---|
| 21 |  | 
|---|
| 22 | ObjectListDefinition(Model); | 
|---|
| 23 |  | 
|---|
| 24 | /** | 
|---|
| 25 |  * standard constructor | 
|---|
| 26 |  * @todo this constructor is not jet implemented - do it | 
|---|
| 27 | */ | 
|---|
| 28 | Model::Model() | 
|---|
| 29 | { | 
|---|
| 30 |   this->registerObject(this, Model::_objectList); | 
|---|
| 31 |   this->pModelInfo.numVertices = 0; | 
|---|
| 32 |   this->pModelInfo.numTriangles = 0; | 
|---|
| 33 |   this->pModelInfo.numNormals = 0; | 
|---|
| 34 |   this->pModelInfo.numTexCoor = 0; | 
|---|
| 35 |  | 
|---|
| 36 |   this->pModelInfo.pVertices = NULL; | 
|---|
| 37 |   this->pModelInfo.pTriangles = NULL; | 
|---|
| 38 |   this->pModelInfo.pNormals = NULL; | 
|---|
| 39 |   this->pModelInfo.pTexCoor = NULL; | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 | /** | 
|---|
| 44 |  * standard deconstructor | 
|---|
| 45 | */ | 
|---|
| 46 | Model::~Model() | 
|---|
| 47 | { | 
|---|
| 48 |   if( this->pModelInfo.pVertices != NULL) | 
|---|
| 49 |     delete [] this->pModelInfo.pVertices; | 
|---|
| 50 |  | 
|---|
| 51 |   if( this->pModelInfo.pTriangles != NULL) | 
|---|
| 52 |     delete [] this->pModelInfo.pTriangles; | 
|---|
| 53 |  | 
|---|
| 54 |   if( this->pModelInfo.pNormals != NULL) | 
|---|
| 55 |     delete [] this->pModelInfo.pNormals; | 
|---|
| 56 |  | 
|---|
| 57 |   if( this->pModelInfo.pTexCoor != NULL) | 
|---|
| 58 |     delete [] this->pModelInfo.pTexCoor; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 | void Model::draw() const | 
|---|
| 64 | { | 
|---|
| 65 |   const GLfloat* pVertices = NULL; | 
|---|
| 66 |   const GLfloat* pNorm = NULL; | 
|---|
| 67 |  | 
|---|
| 68 |   glBegin(GL_TRIANGLES); | 
|---|
| 69 |   for(unsigned int i = 0; i < this->pModelInfo.numTriangles; ++i) | 
|---|
| 70 |     { | 
|---|
| 71 |       //printf("int i = %i\n", i); | 
|---|
| 72 |       pNorm = &this->pModelInfo.pNormals[this->pModelInfo.pTriangles[i].indexToNormals[0]]; | 
|---|
| 73 |       pVertices = &this->pModelInfo.pVertices[this->pModelInfo.pTriangles[i].indexToVertices[0]]; | 
|---|
| 74 |       glNormal3f(pNorm[0], pNorm[1], pNorm[2]); | 
|---|
| 75 |       glVertex3f(pVertices[0], pVertices[1], pVertices[2]); | 
|---|
| 76 |  | 
|---|
| 77 |       pNorm = &this->pModelInfo.pNormals[this->pModelInfo.pTriangles[i].indexToNormals[1]]; | 
|---|
| 78 |       pVertices = &this->pModelInfo.pVertices[this->pModelInfo.pTriangles[i].indexToVertices[1]]; | 
|---|
| 79 |       glNormal3f(pNorm[0], pNorm[1], pNorm[2]); | 
|---|
| 80 |       glVertex3f(pVertices[0], pVertices[1], pVertices[2]); | 
|---|
| 81 |  | 
|---|
| 82 |       pNorm = &this->pModelInfo.pNormals[this->pModelInfo.pTriangles[i].indexToNormals[2]]; | 
|---|
| 83 |       pVertices = &this->pModelInfo.pVertices[this->pModelInfo.pTriangles[i].indexToVertices[2]]; | 
|---|
| 84 |       glNormal3f(pNorm[0], pNorm[1], pNorm[2]); | 
|---|
| 85 |       glVertex3f(pVertices[0], pVertices[1], pVertices[2]); | 
|---|
| 86 |  | 
|---|
| 87 |     } | 
|---|
| 88 |   glEnd(); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | /** | 
|---|
| 93 |  * adds a mounting point to the model | 
|---|
| 94 |  * @param up up vector | 
|---|
| 95 |  * @param forward forward vector | 
|---|
| 96 |  * @param center center vector | 
|---|
| 97 |  */ | 
|---|
| 98 | void Model::addMountPoint(const Vector& up, const Vector& forward, const Vector& center, const std::string& name) | 
|---|
| 99 | { | 
|---|
| 100 |   mountPointSkeleton mps; | 
|---|
| 101 |   mps.up = up; | 
|---|
| 102 |   mps.forward = forward; | 
|---|
| 103 |   mps.center = center; | 
|---|
| 104 |   mps.name = name; | 
|---|
| 105 |  | 
|---|
| 106 |   this->mountPoints.push_back(mps); | 
|---|
| 107 | } | 
|---|