[4577] | 1 | /* |
---|
[2823] | 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: ... |
---|
[4793] | 14 | |
---|
| 15 | 2005-07-06: (Patrick) added new function buildTriangleList() |
---|
[2823] | 16 | */ |
---|
| 17 | |
---|
[3590] | 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER |
---|
| 19 | |
---|
[6021] | 20 | #include "static_model.h" |
---|
[3427] | 21 | |
---|
[8362] | 22 | #include "debug.h" |
---|
[3418] | 23 | #include <stdarg.h> |
---|
[3398] | 24 | |
---|
[2776] | 25 | |
---|
[4022] | 26 | |
---|
[9406] | 27 | |
---|
[4022] | 28 | ///////////// |
---|
| 29 | /// MODEL /// |
---|
| 30 | ///////////// |
---|
[9715] | 31 | ObjectListDefinition(StaticModel); |
---|
[9684] | 32 | |
---|
[2842] | 33 | /** |
---|
[6031] | 34 | * @brief Creates a 3D-Model. |
---|
| 35 | * |
---|
| 36 | * assigns it a Name and a Type |
---|
| 37 | */ |
---|
[7221] | 38 | StaticModel::StaticModel(const std::string& modelName) |
---|
[9830] | 39 | : data(new StaticModelData(modelName)) |
---|
[3398] | 40 | { |
---|
[9684] | 41 | this->registerObject(this, StaticModel::_objectList); |
---|
[4577] | 42 | PRINTF(4)("new 3D-Model is being created\n"); |
---|
[3398] | 43 | this->setName(modelName); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
[6031] | 47 | * @brief deletes an Model. |
---|
| 48 | * |
---|
| 49 | * Looks if any from model allocated space is still in use, and if so deleted it. |
---|
| 50 | */ |
---|
[6021] | 51 | StaticModel::~StaticModel() |
---|
[2847] | 52 | { |
---|
[3548] | 53 | PRINTF(4)("Deleting Model "); |
---|
[3396] | 54 | |
---|
[7732] | 55 | // mark this stuff as beeing deleted |
---|
| 56 | this->pModelInfo.pVertices = NULL; |
---|
| 57 | this->pModelInfo.pNormals = NULL; |
---|
| 58 | this->pModelInfo.pTexCoor = NULL; |
---|
[9830] | 59 | this->pModelInfo.pTriangles = NULL; |
---|
[2847] | 60 | } |
---|
| 61 | |
---|
[2842] | 62 | /** |
---|
[6031] | 63 | * @brief Finalizes an Object. This can be done outside of the Class. |
---|
| 64 | */ |
---|
[6021] | 65 | void StaticModel::finalize() |
---|
[3398] | 66 | { |
---|
[9830] | 67 | data->finalize(); |
---|
[3916] | 68 | |
---|
[7711] | 69 | // write out the modelInfo data used for the collision detection! |
---|
[9830] | 70 | this->pModelInfo.pVertices = &this->data->getVertices()[0]; |
---|
| 71 | this->pModelInfo.numVertices = this->data->getVertices().size(); |
---|
| 72 | this->pModelInfo.pNormals = &this->data->getNormals()[0]; |
---|
| 73 | this->pModelInfo.numNormals = this->data->getNormals().size(); |
---|
| 74 | this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0]; |
---|
| 75 | this->pModelInfo.numTexCoor = this->data->getTexCoords().size(); |
---|
[3398] | 76 | |
---|
[9830] | 77 | this->pModelInfo.pTriangles = this->data->getTrianglesExt(); |
---|
| 78 | this->pModelInfo.numTriangles = this->data->getTriangles().size(); |
---|
[3398] | 79 | } |
---|
| 80 | |
---|
[5790] | 81 | /** |
---|
[6031] | 82 | * @brief adds a new Face |
---|
[4836] | 83 | * @param faceElemCount the number of Vertices to add to the Face. |
---|
| 84 | * @param type The information Passed with each Vertex |
---|
[3400] | 85 | */ |
---|
[6021] | 86 | bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...) |
---|
[3400] | 87 | { |
---|
[3418] | 88 | va_list itemlist; |
---|
| 89 | va_start (itemlist, type); |
---|
[9830] | 90 | bool retVal = this->data->addFace(faceElemCount, type, itemlist); |
---|
[3418] | 91 | va_end(itemlist); |
---|
[9830] | 92 | return retVal; |
---|
[3400] | 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
[9830] | 96 | * Includes a default model |
---|
[6031] | 97 | * |
---|
[9830] | 98 | * This will inject a Cube, because this is the most basic model. |
---|
[6031] | 99 | */ |
---|
[6021] | 100 | void StaticModel::cubeModel() |
---|
[2821] | 101 | { |
---|
[3656] | 102 | this->addVertex (-0.5, -0.5, 0.5); |
---|
| 103 | this->addVertex (0.5, -0.5, 0.5); |
---|
| 104 | this->addVertex (-0.5, 0.5, 0.5); |
---|
| 105 | this->addVertex (0.5, 0.5, 0.5); |
---|
| 106 | this->addVertex (-0.5, 0.5, -0.5); |
---|
| 107 | this->addVertex (0.5, 0.5, -0.5); |
---|
| 108 | this->addVertex (-0.5, -0.5, -0.5); |
---|
| 109 | this->addVertex (0.5, -0.5, -0.5); |
---|
[2967] | 110 | |
---|
[3656] | 111 | this->addVertexTexture (0.0, 0.0); |
---|
| 112 | this->addVertexTexture (1.0, 0.0); |
---|
| 113 | this->addVertexTexture (0.0, 1.0); |
---|
| 114 | this->addVertexTexture (1.0, 1.0); |
---|
| 115 | this->addVertexTexture (0.0, 2.0); |
---|
| 116 | this->addVertexTexture (1.0, 2.0); |
---|
| 117 | this->addVertexTexture (0.0, 3.0); |
---|
| 118 | this->addVertexTexture (1.0, 3.0); |
---|
| 119 | this->addVertexTexture (0.0, 4.0); |
---|
| 120 | this->addVertexTexture (1.0, 4.0); |
---|
| 121 | this->addVertexTexture (2.0, 0.0); |
---|
| 122 | this->addVertexTexture (2.0, 1.0); |
---|
| 123 | this->addVertexTexture (-1.0, 0.0); |
---|
| 124 | this->addVertexTexture (-1.0, 1.0); |
---|
[3081] | 125 | |
---|
[3656] | 126 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 127 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 128 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 129 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 130 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 131 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 132 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 133 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 134 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 135 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 136 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 137 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 138 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 139 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 140 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 141 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 142 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 143 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 144 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 145 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 146 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 147 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 148 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 149 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
[2821] | 150 | |
---|
[4112] | 151 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3); |
---|
| 152 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7); |
---|
| 153 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11); |
---|
| 154 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15); |
---|
| 155 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19); |
---|
| 156 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23); |
---|
[2821] | 157 | } |
---|