Changeset 6262 in orxonox.OLD for branches/height_map/src/lib
- Timestamp:
- Dec 22, 2005, 6:38:54 PM (19 years ago)
- Location:
- branches/height_map/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map/src/lib/graphics/importer/vertex_array_model.cc
r6261 r6262 75 75 76 76 77 glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray()); 78 glNormalPointer(GL_FLOAT, 0, this->normals.getArray()); 79 glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray()); 80 glColorPointer(3, GL_FLOAT, 0, this->colors.getArray()); 81 82 for (GLuint i = 1; i < this->stripes.size(); ++i) 83 { 84 glDrawElements(GL_TRIANGLE_STRIP, this->stripes[i] - this->stripes[i-1], GL_UNSIGNED_BYTE, this->indices.getArray()+this->stripes[i-1]); 85 // glDrawRangeElements(GL_TRIANGLE_STRIP, 86 // this->stripes[i-1], 87 // this->stripes[i], 88 // this->indices.getCount(), 89 // GL_UNSIGNED_BYTE, 90 // this->indices.getArray()); 77 glVertexPointer(3, GL_FLOAT, 0, &this->vertices[0]); 78 glNormalPointer(GL_FLOAT, 0, &this->normals[0]); 79 glTexCoordPointer(2, GL_FLOAT, 0, &this->texCoords[0]); 80 glColorPointer(3, GL_FLOAT, 0, &this->colors[0]); 81 82 for (GLuint i = 1; ++i < this->stripes.size(); ++i) 83 { 84 glDrawElements( GL_TRIANGLES, 85 this->stripes[i] - this->stripes[i-1], 86 GL_UNSIGNED_BYTE, 87 &this->indices[this->stripes[i-1]] ); 91 88 } 92 89 glEnable(GL_LIGHTING); … … 102 99 void VertexArrayModel::newStripe() 103 100 { 104 this->stripes.push_back(this->indices.getCount()); 101 // no stripes of size 0 102 if (this->stripes.empty() || this->indices.size() != this->stripes.back()) 103 this->stripes.push_back(this->indices.size()); 105 104 } 106 105 … … 114 113 void VertexArrayModel::addVertex(float x, float y, float z) 115 114 { 116 this->vertices.addEntry(x, y, z); 115 this->vertices.push_back(x); 116 this->vertices.push_back(y); 117 this->vertices.push_back(z); 117 118 this->pModelInfo.numVertices++; 118 119 } … … 129 130 void VertexArrayModel::addNormal(float x, float y, float z) 130 131 { 131 this->normals.addEntry(x, y, z); 132 this->normals.push_back(x); 133 this->normals.push_back(y); 134 this->normals.push_back(z); 132 135 this->pModelInfo.numNormals++; 133 136 } … … 143 146 void VertexArrayModel::addTexCoor(float u, float v) 144 147 { 145 this->texCoords. addEntry(u);146 this->texCoords. addEntry(v);148 this->texCoords.push_back(u); 149 this->texCoords.push_back(v); 147 150 this->pModelInfo.numTexCoor++; 148 151 } … … 156 159 void VertexArrayModel::addColor(float r, float g, float b) 157 160 { 158 this->colors.addEntry(r, g, b); 161 this->colors.push_back(r); 162 this->colors.push_back(g); 163 this->colors.push_back(b); 159 164 // FIXME 160 165 } … … 168 173 void VertexArrayModel::addIndice(GLubyte indice) 169 174 { 170 this->indices. addEntry(indice);175 this->indices.push_back(indice); 171 176 } 172 177 … … 178 183 { 179 184 // finalize the Arrays 180 this->vertices.finalizeArray();181 this->texCoords.finalizeArray();182 this->normals.finalizeArray();183 this->colors.finalizeArray();184 this->indices.finalizeArray();185 186 185 this->newStripe(); 187 188 for (int i = 0 ; i < this->stripes.size(); i++)189 {190 printf("== %d ==\n", stripes[i]);191 192 }193 186 194 187 /* … … 213 206 void VertexArrayModel::planeModel() 214 207 { 215 unsigned int sizeX = 20, sizeY = 10;208 unsigned int sizeX = 20, sizeY = 20; 216 209 217 210 unsigned int i, j; … … 220 213 for (j = 0; j < sizeX; j++) 221 214 { 222 this->addVertex((float)i - sizeY/2.0, sin(-(float)i/(float)sizeY*5.0) * cos((float)j/(float)sizeX*5.0) * 10.0 , (float)(j) -sizeX/2.0);223 this->addNormal( (float)i/(float)sizeY, 1, (float)j/(float)sizeX);215 this->addVertex((float)i - (float)sizeY/2.0, sin((float)i/(float)sizeY*5.0)*cos((float)j/(float)sizeX*5.0)*5.0, (float)j - (float)sizeX/2.0); 216 this->addNormal(0.0, 1, 0.0); 224 217 this->addTexCoor((float)i/(float)sizeY, (float)j/(float)sizeY); 225 218 this->addColor((float)i/20.0, 0.0, (float)j/20.0); … … 231 224 for (j = 0; j < sizeX; j++) 232 225 { 233 this->addIndice(sizeX*i + j); 234 this->addIndice(sizeX*(i+1) + j); 235 } 236 if (i < sizeY -1 ) 237 this->newStripe(); 238 } 239 } 226 this->addIndice(sizeY*i + j); 227 this->addIndice(sizeY*(i+1) + j); 228 } 229 this->debug(); 230 this->newStripe(); 231 } 232 } 233 234 #include <cmath> 235 236 void VertexArrayModel::spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop) 237 { 238 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 239 { 240 float theta = 0; 241 float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop; 242 float sinTheta = std::sin(theta); 243 float sinPhi = std::sin(phi); 244 float cosTheta = std::cos(theta); 245 float cosPhi = std::cos(phi); 246 this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 247 this->addNormal(1,1,1); 248 this->addTexCoor(0,0); 249 this->addColor(.125,.436,.246); 250 } 251 for (unsigned int loopNumber = 0; loopNumber <= loops; ++loopNumber) 252 { 253 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 254 { 255 float theta = (loopNumber * PI / loops) + ((PI * loopSegmentNumber) / (segmentsPerLoop * loops)); 256 if (loopNumber == loops) 257 { 258 theta = PI; 259 } 260 float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop; 261 float sinTheta = std::sin(theta); 262 float sinPhi = std::sin(phi); 263 float cosTheta = std::cos(theta); 264 float cosPhi = std::cos(phi); 265 this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta); 266 this->addNormal(1,1,1); 267 this->addTexCoor(0,0); 268 this->addColor(.125,.436,.246); 269 270 } 271 } 272 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 273 { 274 this->addIndice(loopSegmentNumber); 275 this->addIndice(segmentsPerLoop + loopSegmentNumber); 276 } 277 for (unsigned int loopNumber = 0; loopNumber < loops; ++loopNumber) 278 { 279 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 280 { 281 this->addIndice( ((loopNumber + 1) * segmentsPerLoop) + loopSegmentNumber); 282 this->addIndice( ((loopNumber + 2) * segmentsPerLoop) + loopSegmentNumber); 283 } 284 } 285 } 286 287 288 289 void VertexArrayModel::debug() const 290 { 291 PRINT(0)("VertexArrayModel (%s): debug\n", this->getName()); 292 PRINT(0)("Stripes: %d; Indices: %d; Vertices: %d; Normals %d; TextCoords %d; Colors %d\n", 293 this->stripes.size(), 294 this->indices.size(), 295 this->vertices.size()/3, 296 this->normals.size()/3, 297 this->texCoords.size()/2, 298 this->colors.size() )/3; 299 for (GLuint i = 1; i < this->stripes.size(); ++i) 300 { 301 PRINT(0)("Stripe-%d ::", i); 302 for (GLuint j = this->stripes[i-1] ; j < this->stripes[i]; j++) 303 { 304 PRINT(0)("%d->", this->indices[j]); 305 } 306 PRINT(0)("\n"); 307 } 308 } -
branches/height_map/src/lib/graphics/importer/vertex_array_model.h
r6259 r6262 47 47 // 48 48 void planeModel(); 49 void spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop); 50 51 void debug() const; 49 52 50 53 private: … … 54 57 bool bFinalized; //!< Sets the Object to be finalized. 55 58 56 tArray<GLfloat>vertices; //!< The Array that handles the Vertices.57 tArray<GLfloat>normals; //!< The Array that handles the Normals.58 tArray<GLfloat>texCoords; //!< The Array that handles the VertexTextureCoordinates.59 tArray<GLfloat>colors; //!< The Array that handles Colors.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. 60 63 61 tArray<GLubyte>indices; //!< The Array that tells us what Vertex is connected to which other one.64 std::vector<GLubyte> indices; //!< The Array that tells us what Vertex is connected to which other one. 62 65 63 66 std::vector<GLuint> stripes; //!< A lsit of Stripes of this Model.
Note: See TracChangeset
for help on using the changeset viewer.