[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 | ///////////// |
---|
[9869] | 31 | ObjectListDefinition(StaticModel); |
---|
| 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) |
---|
[9869] | 39 | : data(new StaticModelData(modelName)) |
---|
[3398] | 40 | { |
---|
[9869] | 41 | this->registerObject(this, StaticModel::_objectList); |
---|
[4577] | 42 | PRINTF(4)("new 3D-Model is being created\n"); |
---|
[3398] | 43 | this->setName(modelName); |
---|
[9869] | 44 | } |
---|
[3909] | 45 | |
---|
[9869] | 46 | StaticModel::StaticModel(const StaticModel& staticModel) |
---|
| 47 | : data(staticModel.data) |
---|
| 48 | { |
---|
| 49 | this->registerObject(this, StaticModel::_objectList); |
---|
| 50 | this->setName(staticModel.getName()); |
---|
| 51 | this->updateBase(); |
---|
| 52 | } |
---|
[6031] | 53 | |
---|
[4577] | 54 | |
---|
[3398] | 55 | /** |
---|
[6031] | 56 | * @brief deletes an Model. |
---|
| 57 | * |
---|
| 58 | * Looks if any from model allocated space is still in use, and if so deleted it. |
---|
| 59 | */ |
---|
[6021] | 60 | StaticModel::~StaticModel() |
---|
[2847] | 61 | { |
---|
[3548] | 62 | PRINTF(4)("Deleting Model "); |
---|
[3396] | 63 | |
---|
[7732] | 64 | // mark this stuff as beeing deleted |
---|
| 65 | this->pModelInfo.pVertices = NULL; |
---|
| 66 | this->pModelInfo.pNormals = NULL; |
---|
| 67 | this->pModelInfo.pTexCoor = NULL; |
---|
[9869] | 68 | this->pModelInfo.pTriangles = NULL; |
---|
[2847] | 69 | } |
---|
| 70 | |
---|
[9869] | 71 | StaticModel& StaticModel::operator=(const StaticModel& model) |
---|
[3398] | 72 | { |
---|
[9869] | 73 | this->data = model.data; |
---|
| 74 | this->updateBase(); |
---|
| 75 | return *this; |
---|
| 76 | }; |
---|
[3916] | 77 | |
---|
[3398] | 78 | |
---|
[5790] | 79 | /** |
---|
[9869] | 80 | * @brief Finalizes an Object. This can be done outside of the Class. |
---|
[5790] | 81 | */ |
---|
[9869] | 82 | void StaticModel::finalize() |
---|
[5790] | 83 | { |
---|
[9869] | 84 | data->finalize(); |
---|
| 85 | this->updateBase(); |
---|
[5790] | 86 | } |
---|
| 87 | |
---|
[9869] | 88 | void StaticModel::acquireData(const StaticModelData::Pointer& data) |
---|
[2748] | 89 | { |
---|
[9869] | 90 | this->data = data; |
---|
| 91 | this->updateBase(); |
---|
[2748] | 92 | } |
---|
[2754] | 93 | |
---|
[10089] | 94 | |
---|
| 95 | |
---|
[2842] | 96 | /** |
---|
[10089] | 97 | * extract the mount points from this file: looking at each group and checking if the group realy is a mountpoint marker |
---|
| 98 | * if so get place and orientation |
---|
| 99 | */ |
---|
| 100 | void StaticModel::extractMountPoints() |
---|
| 101 | { |
---|
| 102 | |
---|
| 103 | // go through all groups and check if they are mounts |
---|
| 104 | const ModelGroup* groupPtr = this->data->getModelGroup(); |
---|
| 105 | for( ; groupPtr != NULL; groupPtr = groupPtr->next) |
---|
| 106 | { |
---|
[10090] | 107 | //PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str()); |
---|
| 108 | |
---|
[10089] | 109 | // get the name of this group and check if it's a mout point identifier |
---|
| 110 | std::string groupName = groupPtr->name; |
---|
| 111 | if( groupName.find("MP.", 0) != std::string::npos) |
---|
[10090] | 112 | { |
---|
| 113 | PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str()); |
---|
| 114 | |
---|
| 115 | } |
---|
[10089] | 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /** |
---|
[6031] | 122 | * @brief adds a new Face |
---|
[4836] | 123 | * @param faceElemCount the number of Vertices to add to the Face. |
---|
| 124 | * @param type The information Passed with each Vertex |
---|
[3400] | 125 | */ |
---|
[6021] | 126 | bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...) |
---|
[3400] | 127 | { |
---|
[3418] | 128 | va_list itemlist; |
---|
| 129 | va_start (itemlist, type); |
---|
[9869] | 130 | bool retVal = this->data->addFace(faceElemCount, type, itemlist); |
---|
[3418] | 131 | va_end(itemlist); |
---|
[9869] | 132 | return retVal; |
---|
[3400] | 133 | } |
---|
| 134 | |
---|
[9869] | 135 | void StaticModel::updateBase() |
---|
[3063] | 136 | { |
---|
[9869] | 137 | // write out the modelInfo data used for the collision detection! |
---|
| 138 | this->pModelInfo.pVertices = &this->data->getVertices()[0]; |
---|
| 139 | this->pModelInfo.numVertices = this->data->getVertices().size(); |
---|
| 140 | this->pModelInfo.pNormals = &this->data->getNormals()[0]; |
---|
| 141 | this->pModelInfo.numNormals = this->data->getNormals().size(); |
---|
| 142 | this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0]; |
---|
| 143 | this->pModelInfo.numTexCoor = this->data->getTexCoords().size(); |
---|
[4577] | 144 | |
---|
[9869] | 145 | this->pModelInfo.pTriangles = this->data->getTrianglesExt(); |
---|
| 146 | this->pModelInfo.numTriangles = this->data->getTriangles().size(); |
---|
[3801] | 147 | } |
---|
| 148 | |
---|
[4577] | 149 | |
---|
[3066] | 150 | /** |
---|
[9869] | 151 | * Includes a default model |
---|
[6031] | 152 | * |
---|
[9869] | 153 | * This will inject a Cube, because this is the most basic model. |
---|
[6031] | 154 | */ |
---|
[6021] | 155 | void StaticModel::cubeModel() |
---|
[2821] | 156 | { |
---|
[3656] | 157 | this->addVertex (-0.5, -0.5, 0.5); |
---|
| 158 | this->addVertex (0.5, -0.5, 0.5); |
---|
| 159 | this->addVertex (-0.5, 0.5, 0.5); |
---|
| 160 | this->addVertex (0.5, 0.5, 0.5); |
---|
| 161 | this->addVertex (-0.5, 0.5, -0.5); |
---|
| 162 | this->addVertex (0.5, 0.5, -0.5); |
---|
| 163 | this->addVertex (-0.5, -0.5, -0.5); |
---|
| 164 | this->addVertex (0.5, -0.5, -0.5); |
---|
[2967] | 165 | |
---|
[3656] | 166 | this->addVertexTexture (0.0, 0.0); |
---|
| 167 | this->addVertexTexture (1.0, 0.0); |
---|
| 168 | this->addVertexTexture (0.0, 1.0); |
---|
| 169 | this->addVertexTexture (1.0, 1.0); |
---|
| 170 | this->addVertexTexture (0.0, 2.0); |
---|
| 171 | this->addVertexTexture (1.0, 2.0); |
---|
| 172 | this->addVertexTexture (0.0, 3.0); |
---|
| 173 | this->addVertexTexture (1.0, 3.0); |
---|
| 174 | this->addVertexTexture (0.0, 4.0); |
---|
| 175 | this->addVertexTexture (1.0, 4.0); |
---|
| 176 | this->addVertexTexture (2.0, 0.0); |
---|
| 177 | this->addVertexTexture (2.0, 1.0); |
---|
| 178 | this->addVertexTexture (-1.0, 0.0); |
---|
| 179 | this->addVertexTexture (-1.0, 1.0); |
---|
[3081] | 180 | |
---|
[3656] | 181 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 182 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 183 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 184 | this->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 185 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 186 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 187 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 188 | this->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 189 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 190 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 191 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 192 | this->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 193 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 194 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 195 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 196 | this->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 197 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 198 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 199 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 200 | this->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 201 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 202 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 203 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 204 | this->addVertexNormal (-1.0, 0.0, 0.0); |
---|
[2821] | 205 | |
---|
[4112] | 206 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3); |
---|
| 207 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7); |
---|
| 208 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11); |
---|
| 209 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15); |
---|
| 210 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19); |
---|
| 211 | this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23); |
---|
[2821] | 212 | } |
---|