Changeset 6310 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Dec 27, 2005, 12:24:27 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/vertex_array_model.cc
r6309 r6310 64 64 actcBeginInput(tc); 65 65 for(unsigned int i = 0; i < model.getTriangleCount(); i++) 66 actcAddTriangle(tc, model.getTriangles()[i].indexToVertices[0], model.getTriangles()[i].indexToVertices[1], model.getTriangles()[i].indexToVertices[2]); 66 actcAddTriangle(tc, 67 model.getTriangles()[i].indexToVertices[0], 68 model.getTriangles()[i].indexToVertices[1], 69 model.getTriangles()[i].indexToVertices[2]); 67 70 actcEndInput(tc); 68 71 … … 72 75 for (unsigned int i = 0; i < model.getVertexCount(); i+=3) 73 76 this->addVertex(model.getVertexArray()[i], model.getVertexArray()[i+1], model.getVertexArray()[i+2]); 77 for (unsigned int i = 0; i < model.getVertexCount(); i+=3) 78 this->addColor(model.getVertexArray()[i], model.getVertexArray()[i+1], model.getVertexArray()[i+2]); 74 79 for (unsigned int i = 0; i < model.getNormalsCount(); i+=3) 75 80 this->addNormal(model.getNormalsArray()[i], model.getNormalsArray()[i+1], model.getNormalsArray()[i+2]); 76 for (unsigned int i = 0; i < model.getTexCoordCount(); i+=2) 77 this->addTexCoor(model.getTexCoordArray()[i], model.getTexCoordArray()[i+1]); 81 // for (unsigned int i = 0; i < model.getTexCoordCount(); i+=2) 82 // this->addTexCoor(model.getTexCoordArray()[i], model.getTexCoordArray()[i+1]); 83 for (unsigned int i = 0; i < model.getVertexCount(); i+=3) 84 this->addTexCoor(1,2); 78 85 79 86 80 87 int prim; 81 u nsignedint v1, v2, v3;88 uint v1, v2, v3; 82 89 83 90 actcBeginOutput(tc); 84 91 while((prim = actcStartNextPrim(tc, &v1, &v2) != ACTC_DATABASE_EMPTY)) 85 92 { 93 this->newStripe(); 94 86 95 this->addIndice(v1); 87 96 this->addIndice(v2); … … 95 104 printf("%d\n", v3); 96 105 } 97 this->newStripe();98 106 } 99 107 actcEndOutput(tc); 100 108 101 109 this->finalize(); 110 this->debug(); 102 111 } 103 112 … … 129 138 void VertexArrayModel::draw() const 130 139 { 131 PRINTF(4)("drawing the 3D-VertexArrayModels\n"); 132 133 glEnableClientState(GL_VERTEX_ARRAY | 134 GL_TEXTURE_COORD_ARRAY | 135 GL_NORMAL_ARRAY); 136 // glEnableClientState(GL_INDEX_ARRAY); 137 138 glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray()); 139 glNormalPointer(GL_FLOAT, 0, this->normals.getArray()); 140 glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray()); 140 PRINTF(4)("drawing 3D-VertexArrayModel %s\n", this->getName()); 141 glEnableClientState(GL_VERTEX_ARRAY ); 142 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 143 glEnableClientState(GL_NORMAL_ARRAY ); 144 glEnableClientState(GL_COLOR_ARRAY ); 145 146 147 glVertexPointer(3, GL_FLOAT, 0, &this->vertices[0]); 148 glNormalPointer(GL_FLOAT, 0, &this->normals[0]); 149 glTexCoordPointer(2, GL_FLOAT, 0, &this->texCoords[0]); 150 glColorPointer(3, GL_FLOAT, 0, &this->colors[0]); 141 151 142 152 for (GLuint i = 1; i < this->stripes.size(); ++i) 143 153 { 144 glDrawRangeElements(GL_TRIANGLE_STRIP, 145 this->stripes[i-1], 146 this->stripes[i], 147 this->indices.getCount(), 148 GL_UNSIGNED_BYTE, 149 this->indices.getArray()); 154 glDrawElements( GL_TRIANGLE_STRIP, 155 this->stripes[i] - this->stripes[i-1], 156 GL_UNSIGNED_INT, 157 &this->indices[this->stripes[i-1]] ); 150 158 } 151 159 } … … 160 168 void VertexArrayModel::newStripe() 161 169 { 162 this->stripes.push_back(this->vertices.getCount()-1); 170 // no stripes of size 0 171 if (this->stripes.empty() || this->indices.size() != this->stripes.back()) 172 this->stripes.push_back(this->indices.size()); 163 173 } 164 174 … … 172 182 void VertexArrayModel::addVertex(float x, float y, float z) 173 183 { 174 this->vertices.addEntry(x, y, z); 184 this->vertices.push_back(x); 185 this->vertices.push_back(y); 186 this->vertices.push_back(z); 175 187 this->pModelInfo.numVertices++; 176 188 } … … 187 199 void VertexArrayModel::addNormal(float x, float y, float z) 188 200 { 189 this->normals.addEntry(x, y, z); 201 this->normals.push_back(x); 202 this->normals.push_back(y); 203 this->normals.push_back(z); 190 204 this->pModelInfo.numNormals++; 191 205 } … … 193 207 194 208 /** 195 * adds a Texture Coordinate209 * @brief adds a Texture Coordinate 196 210 * @param u The u coordinate of the TextureCoordinate. 197 211 * @param v The y coordinate of the TextureCoordinate. … … 201 215 void VertexArrayModel::addTexCoor(float u, float v) 202 216 { 203 this->texCoords. addEntry(u);204 this->texCoords. addEntry(v);217 this->texCoords.push_back(u); 218 this->texCoords.push_back(v); 205 219 this->pModelInfo.numTexCoor++; 220 } 221 222 /** 223 * @brief adds a new Color 224 * @param r the Red Component of the VertexColor to add. 225 * @param g the Green Component of the VertexColor to add. 226 * @param b the Blue of the VertexColor to add. 227 */ 228 void VertexArrayModel::addColor(float r, float g, float b) 229 { 230 this->colors.push_back(r); 231 this->colors.push_back(g); 232 this->colors.push_back(b); 233 // FIXME 206 234 } 207 235 … … 212 240 * @param type The information Passed with each Vertex 213 241 */ 214 void VertexArrayModel::addIndice(GLu byteindice)215 { 216 this->indices. addEntry(indice);242 void VertexArrayModel::addIndice(GLuint indice) 243 { 244 this->indices.push_back(indice); 217 245 } 218 246 … … 224 252 { 225 253 // finalize the Arrays 226 this->vertices.finalizeArray();227 this->texCoords.finalizeArray();228 this->normals.finalizeArray();229 this->indices.finalizeArray();230 231 254 this->newStripe(); 232 233 /*234 glEnableClientState(GL_VERTEX_ARRAY |235 GL_TEXTURE_COORD_ARRAY |236 GL_NORMAL_ARRAY);237 */238 239 255 this->bFinalized = true; 240 256 } 257 241 258 242 259 … … 246 263 ///////////// 247 264 /** 248 * @brief Includes a default model 249 * 250 * This will inject a Cube, because this is the most basic model. 251 */ 252 void VertexArrayModel::planeModel() 253 { 254 unsigned int i, j; 255 for (i = 0; i < 20; i++) 256 { 257 for (j = 0; j < 20; j++) 258 { 259 this->addVertex(i* 50, .5, (j)*50); 260 this->addNormal(0, 1, 0); 261 this->addTexCoor((float)i/20.0, (float)j/20.0); 262 263 } 264 } 265 for (i = 0; i < 20; i++) 266 { 267 this->addIndice(i); 268 this->addIndice(i+20); 269 } 270 } 265 * @brief Includes a default model 266 * 267 * This will inject a Cube, because this is the most basic model. 268 */ 269 void VertexArrayModel::planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY) 270 { 271 GLuint i, j; 272 for (i = 0; i < resolutionY; i++) 273 { 274 for (j = 0; j < resolutionX; j++) 275 { 276 this->addVertex((float)i - (float)sizeY/2.0, 0.0, (float)j - (float)sizeX/2.0); 277 this->addNormal(0.0, 1, 0.0); 278 this->addTexCoor((float)i/(float)resolutionY, (float)j/(float)resolutionY); 279 this->addColor((float)i/20.0, 0.0, (float)j/20.0); 280 } 281 } 282 283 for (i = 0; i < resolutionY-1; i++) 284 { 285 for (j = 0; j < resolutionX; j++) 286 { 287 this->addIndice( resolutionY*i + j ); 288 this->addIndice( resolutionY*(i+1) + j ); 289 } 290 this->newStripe(); 291 } 292 } 293 294 #include <cmath> 295 296 /** 297 * @brief builds a Triangle Stripped sphere 298 * @param radius: radius 299 * @param loops: the count of loops 300 * @param segmentsPerLoop how many Segments per loop 301 */ 302 void VertexArrayModel::spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop) 303 { 304 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 305 { 306 float theta = 0; 307 float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop; 308 float sinTheta = std::sin(theta); 309 float sinPhi = std::sin(phi); 310 float cosTheta = std::cos(theta); 311 float cosPhi = std::cos(phi); 312 this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 313 this->addNormal(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 314 this->addTexCoor(0,0); /// FIXME 315 this->addColor(.125,.436,.246); ///FIXME 316 } 317 for (unsigned int loopNumber = 0; loopNumber <= loops; ++loopNumber) 318 { 319 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 320 { 321 float theta = (loopNumber * PI / loops) + ((PI * loopSegmentNumber) / (segmentsPerLoop * loops)); 322 if (loopNumber == loops) 323 { 324 theta = PI; 325 } 326 float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop; 327 float sinTheta = std::sin(theta); 328 float sinPhi = std::sin(phi); 329 float cosTheta = std::cos(theta); 330 float cosPhi = std::cos(phi); 331 this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 332 this->addNormal(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 333 this->addTexCoor(0,0); //FIXME 334 this->addColor(.125,.436,.246); 335 336 } 337 } 338 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 339 { 340 this->addIndice(loopSegmentNumber); 341 this->addIndice(segmentsPerLoop + loopSegmentNumber); 342 } 343 for (unsigned int loopNumber = 0; loopNumber < loops; ++loopNumber) 344 { 345 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 346 { 347 this->addIndice( ((loopNumber + 1) * segmentsPerLoop) + loopSegmentNumber); 348 this->addIndice( ((loopNumber + 2) * segmentsPerLoop) + loopSegmentNumber); 349 } 350 } 351 } 352 353 354 /** 355 * @brief print out some nice debug information about this VertexArrayModel. 356 */ 357 void VertexArrayModel::debug() const 358 { 359 PRINT(0)("VertexArrayModel (%s): debug\n", this->getName()); 360 PRINT(0)("Stripes: %d; Indices: %d; Vertices: %d; Normals %d; TextCoords %d; Colors %d\n", 361 this->stripes.size(), 362 this->indices.size(), 363 this->vertices.size()/3, 364 this->normals.size()/3, 365 this->texCoords.size()/2, 366 this->colors.size() )/3; 367 for (GLuint i = 1; i < this->stripes.size(); ++i) 368 { 369 PRINT(0)("Stripe-%d (s:%d:e:%d):: ", i, this->stripes[i-1], this->stripes[i]); 370 for (GLuint j = this->stripes[i-1] ; j < this->stripes[i]; j++) 371 { 372 PRINT(0)("%d->", this->indices[j]); 373 } 374 PRINT(0)("\n"); 375 } 376 } -
trunk/src/lib/graphics/importer/vertex_array_model.h
r6308 r6310 11 11 #include "glincl.h" 12 12 13 #include "array.h"14 13 #include <vector> 15 14 … … 40 39 void addNormal(float x, float y, float z); 41 40 void addTexCoor(float u, float v); 42 void addIndice(GLubyte indice); 41 void addColor(float r, float g, float b); 42 43 void addIndice(GLuint indice); 43 44 44 45 void finalize(); 45 46 46 47 // 47 void planeModel(); 48 void planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY); 49 void spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop); 50 51 void debug() const; 48 52 49 53 private: … … 53 57 bool bFinalized; //!< Sets the Object to be finalized. 54 58 55 tArray<GLfloat> vertices; //!< The Array that handles the Vertices. 56 tArray<GLfloat> normals; //!< The Array that handles the Normals. 57 tArray<GLfloat> texCoords; //!< The Array that handles the VertexTextureCoordinates. 59 std::vector<GLfloat> vertices; //!< The Array that handles the Vertices. 60 std::vector<GLfloat> normals; //!< The Array that handles the Normals. 61 std::vector<GLfloat> texCoords; //!< The Array that handles the VertexTextureCoordinates. 62 std::vector<GLfloat> colors; //!< The Array that handles Colors. 58 63 59 tArray<GLubyte>indices; //!< The Array that tells us what Vertex is connected to which other one.64 std::vector<GLuint> indices; //!< The Array that tells us what Vertex is connected to which other one. 60 65 61 66 std::vector<GLuint> stripes; //!< A lsit of Stripes of this Model.
Note: See TracChangeset
for help on using the changeset viewer.