Changeset 6267 in orxonox.OLD for branches/height_map
- Timestamp:
- Dec 22, 2005, 7:31:35 PM (19 years ago)
- Location:
- branches/height_map/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map/src/lib/graphics/importer/height_map.cc
r6249 r6267 35 35 } 36 36 37 HeightMap::HeightMap(const char* height_map_name = NULL) 37 HeightMap::HeightMap(const char* height_map_name = NULL) 38 38 { 39 39 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 40 40 heightMap = IMG_Load(height_map_name); 41 41 if(heightMap!=NULL) { 42 42 43 43 PRINTF(0)("loading Image %s\n", height_map_name); 44 44 PRINTF(0)("width : %i\n", heightMap->w); … … 49 49 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift); 50 50 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask); 51 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask); 52 } 53 51 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask); 52 } 53 54 54 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name); 55 55 56 56 57 57 generateNormalVectorField(); 58 59 58 59 60 60 //Defines 2 Materials (for testing only!) 61 this->tmp_mat = new Material(); 61 this->tmp_mat = new Material(); 62 62 tmp_mat->setTransparency(1.0); 63 63 tmp_mat->setIllum(0.3); … … 72 72 tmp_mat->specularTexture = NULL; 73 73 74 this->red_mat = new Material(); 74 this->red_mat = new Material(); 75 75 red_mat->setTransparency(1.0); 76 76 red_mat->setIllum(0.3); … … 93 93 heightMap = IMG_Load(height_map_name); 94 94 if(heightMap!=NULL) { 95 95 96 96 PRINTF(0)("loading Image %s\n", height_map_name); 97 97 PRINTF(0)("width : %i\n", heightMap->w); … … 102 102 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift); 103 103 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask); 104 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask); 105 } 106 104 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask); 105 } 106 107 107 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name); 108 108 109 109 110 110 generateNormalVectorField(); 111 112 111 112 113 113 //Defines 2 Materials (for testing only!) 114 this->tmp_mat = new Material("tmp"); 114 this->tmp_mat = new Material("tmp"); 115 115 tmp_mat->setTransparency(1.0); 116 116 tmp_mat->setIllum(0.3); … … 120 120 tmp_mat->setSpecular(0.0,0.00,0.00); 121 121 tmp_mat->setShininess(1.0); 122 123 124 125 126 this->red_mat = new Material("red"); 122 123 124 125 126 this->red_mat = new Material("red"); 127 127 red_mat->setTransparency(1.0); 128 128 red_mat->setIllum(3); … … 136 136 // red_mat->ambientTexture = NULL; 137 137 //red_mat->specularTexture = NULL; 138 138 139 139 if(colour_map_name != NULL) 140 140 { … … 153 153 } 154 154 else PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name); 155 155 156 156 const char* texture_name = "pictures/ground1.tga"; 157 157 tmp_mat->setDiffuseMap(texture_name); … … 164 164 { 165 165 hasColourMap = false; 166 167 166 167 168 168 } 169 169 170 170 // tmp_mat->setAmbientMap(texture_name); 171 171 //tmp_mat->setSpecularMap(texture_name); 172 172 173 173 // red_mat->setDiffuseMap(texture_name); 174 174 // red_mat->setAmbientMap(texture_name); 175 //red_mat->setSpecularMap(texture_name); 175 //red_mat->setSpecularMap(texture_name); 176 176 } 177 178 177 178 179 179 } 180 180 HeightMap::~HeightMap() … … 193 193 tmp_mat->select(); 194 194 195 unsigned char height = 0; 195 unsigned char height = 0; 196 196 int offset = 0; 197 197 int g = 0; … … 201 201 heights = (unsigned char*) heightMap->pixels; 202 202 bool colourChanged = true; 203 204 203 204 205 205 /* 206 206 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 207 207 {} 208 208 SDL_LockSurface(heightMap); 209 210 211 209 210 211 212 212 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 213 213 { 214 214 215 215 tmp_mat->select(); 216 216 217 217 218 218 219 219 int j = 0; 220 220 221 221 222 222 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) … … 235 235 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0); 236 236 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0); 237 tmp_mat->select(); 238 } 239 } 240 241 237 tmp_mat->select(); 238 } 239 } 240 241 242 242 height = heights[j+sampleRate + i*(heightMap->w )]; 243 243 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x); 244 244 this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 245 246 this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 247 248 249 245 246 this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 247 248 249 250 250 } 251 252 253 254 255 256 257 258 259 260 } 261 262 263 251 252 253 254 255 256 257 258 259 260 } 261 262 263 264 264 SDL_UnlockSurface(heightMap); 265 266 265 266 267 267 int cnt = 0; 268 268 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) … … 271 271 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 272 272 { 273 274 this->addIndice(cnt); 273 274 this->addIndice(cnt); 275 275 cnt ++; 276 276 } … … 279 279 this->newStripe(); 280 280 } 281 } 282 283 284 285 281 } 282 283 284 285 286 286 */ 287 288 this->planeModel();287 288 this->planeModel(10.0, 10.0, 20, 20); 289 289 290 290 this->finalize(); … … 294 294 295 295 /* 296 void HeightMap::draw() 296 void HeightMap::draw() 297 297 { 298 298 … … 309 309 glTexCoord2d(1.0,0.0); 310 310 glVertex3f(x-10,getHeight(x-10,y+10)+5.0f ,y+10); // Top Left 311 311 312 312 313 313 glNormal3f(0,1,0); 314 314 glTexCoord2d(1.0,1.0); 315 315 glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left 316 316 317 317 318 318 glNormal3f(0,1,0); 319 319 glTexCoord2d(0.0,0.0); 320 320 glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left 321 321 322 322 323 323 glNormal3f(0,1,0); 324 324 glTexCoord2d(0.0,1.0); 325 325 glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left 326 326 327 327 glEnd(); 328 328 329 329 tmp_mat->select(); 330 330 331 unsigned char height = 0; 331 unsigned char height = 0; 332 332 int offset = 0; 333 333 int g = 0; … … 338 338 339 339 bool colourChanged = true; 340 340 341 341 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 342 342 { 343 343 SDL_LockSurface(heightMap); 344 344 345 glBegin(GL_TRIANGLE_STRIP); 345 glBegin(GL_TRIANGLE_STRIP); 346 346 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 347 347 { … … 349 349 350 350 351 351 352 352 int j = 0; 353 353 354 354 /* 355 355 height = heights[j + i*(heightMap->w )]; … … 361 361 glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left 362 362 363 */ 363 */ 364 364 /* 365 365 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) … … 378 378 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0); 379 379 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0); 380 tmp_mat->select(); 380 tmp_mat->select(); 381 381 } 382 382 } … … 387 387 glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x); 388 388 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 389 390 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 391 389 390 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 391 392 392 height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )]; 393 393 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x); … … 395 395 //glTexCoord2f(0.0,0.0); 396 396 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right 397 397 398 398 } 399 399 else … … 401 401 //red_mat->select(); 402 402 //glEnd(); 403 404 405 406 glBegin(GL_TRIANGLE_STRIP); 407 403 404 405 406 glBegin(GL_TRIANGLE_STRIP); 407 408 408 drawRect(j,i+sampleRate/2,j+sampleRate/2,i); 409 409 glEnd(); 410 410 glBegin(GL_TRIANGLE_STRIP); 411 412 411 412 413 413 drawRect(j+sampleRate/2,i+sampleRate/2,j+sampleRate,i); 414 414 glEnd(); 415 415 glBegin(GL_TRIANGLE_STRIP); 416 417 416 417 418 418 drawRect(j,i+sampleRate,j+sampleRate/2,i+sampleRate/2); 419 419 glEnd(); 420 420 glBegin(GL_TRIANGLE_STRIP); 421 421 drawRect(j+sampleRate/2,i+sampleRate,j+sampleRate,i+sampleRate/2); 422 422 423 423 glEnd(); 424 425 426 427 428 424 425 426 427 428 429 429 //subdivide 430 430 } 431 431 432 432 433 433 } 434 434 j = heightMap->w -sampleRate; 435 436 435 436 437 437 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x); 438 438 //glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0); … … 440 440 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 441 441 glVertex3f(scaleX*(heightMap->h -i),(double)((double)-1000.0),scaleZ*(j+sampleRate)); // Top Right 442 442 443 443 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x); 444 444 glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0); 445 445 446 446 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)-1000.0,scaleZ*(j+sampleRate)); // Bottom Right 447 447 448 449 450 451 452 //glEnd(); 453 448 449 450 451 452 //glEnd(); 453 454 454 } 455 455 SDL_UnlockSurface(heightMap); … … 480 480 for(int j = 0; j < heightMap->w -1 ; j ++) 481 481 { 482 482 483 483 484 484 delta = (int)heights[j + (i+1)*(heightMap->w )] - (int) heights[j + i*(heightMap->w )]; 485 485 Vector a = Vector(-20.0,(float)delta ,0.0f); 486 486 487 487 delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )]; 488 488 Vector b = Vector(0.0f,(float) delta ,20.0); 489 490 489 490 491 491 normalVectorField[i][j] = b.cross(a); 492 492 normalVectorField[i][j].normalize(); 493 494 } 493 494 } 495 495 } 496 496 SDL_UnlockSurface(heightMap); … … 505 505 if(true) 506 506 { 507 507 508 508 height = heights[xTop + yTop*(heightMap->w )]; 509 509 glNormal3f(normalVectorField[yTop][xTop].y,normalVectorField[yTop][xTop].z,normalVectorField[yTop][xTop].x); … … 515 515 glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((xBottom/sampleRate)%8)/8.0+0.125); 516 516 glVertex3f(scaleX*(heightMap->h -(yTop)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Top Left 517 517 518 518 height = heights[xTop + (yBottom)*(heightMap->w )]; 519 519 glNormal3f(normalVectorField[yBottom][xTop].y,normalVectorField[yBottom][xTop].z,normalVectorField[yBottom][xTop].x); 520 520 glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((yBottom/sampleRate)%8)/8.0); 521 521 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Bottom Right 522 522 523 523 height = heights[xBottom + (yBottom)*(heightMap->w )]; 524 524 glNormal3f(normalVectorField[yBottom][xBottom].y,normalVectorField[yBottom][xBottom].z,normalVectorField[yBottom][xBottom].x); … … 526 526 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Bottom Left 527 527 528 528 529 529 530 530 } … … 533 533 // subdivide 534 534 } 535 535 536 536 } 537 537 … … 541 541 542 542 int height = 0; 543 543 544 544 for(int i= xTopRight; i < xBottomLeft ; i+= sampleRate) 545 545 { 546 546 547 547 glBegin(GL_TRIANGLES); 548 548 549 549 height = heights[yBottomLeft + (i + sampleRate)*(heightMap->w )]; 550 550 glNormal3f(0,1,0); 551 551 glVertex3f(scaleX*(heightMap->h -i-sampleRate),scaleY*height,scaleZ*(yBottomLeft)); 552 552 553 553 height = heights[yBottomLeft + i*(heightMap->w )]; 554 554 glNormal3f(0,1,0); 555 glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft)); 556 555 glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft)); 556 557 557 height = heights[yBottomLeft + (i + sampleRate/2)*(heightMap->w )]; 558 558 glNormal3f(0,1,0); 559 glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft)); 560 561 562 559 glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft)); 560 561 562 563 563 glEnd(); 564 565 566 567 564 565 566 567 568 568 } 569 569 for(int j= yBottomLeft; j < yTopRight; j+= sampleRate) … … 572 572 height = heights[j + (xBottomLeft+sampleRate)*(heightMap->w )]; 573 573 glNormal3f(-1,0,0); 574 glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j)); 575 574 glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j)); 575 576 576 height = heights[j + sampleRate/2 + (xBottomLeft + sampleRate)*(heightMap->w )]; 577 577 glNormal3f(-1,0,0); 578 glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2)); 579 578 glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2)); 579 580 580 height = heights[j + sampleRate + (xBottomLeft + sampleRate)*(heightMap->w )]; 581 581 glNormal3f(-1,0,0); 582 glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate)); 583 582 glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate)); 583 584 584 glEnd(); 585 585 } … … 597 597 { 598 598 int xInt = (int)x / scaleX; x -= (float)xInt*scaleX; xInt = heightMap->h - xInt; 599 int yInt = (int)y / scaleZ; y -= (float)yInt*scaleZ; 599 int yInt = (int)y / scaleZ; y -= (float)yInt*scaleZ; 600 600 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w ) return 0.0f; 601 601 float height = heights[yInt + (xInt)*heightMap->w]*scaleY; -
branches/height_map/src/lib/graphics/importer/vertex_array_model.cc
r6266 r6267 181 181 // finalize the Arrays 182 182 this->newStripe(); 183 184 /*185 glEnableClientState(GL_VERTEX_ARRAY |186 GL_TEXTURE_COORD_ARRAY |187 GL_NORMAL_ARRAY);188 */189 190 183 this->bFinalized = true; 191 184 } 185 192 186 193 187 … … 201 195 * This will inject a Cube, because this is the most basic model. 202 196 */ 203 void VertexArrayModel::planeModel() 204 { 205 GLuint sizeX = 20; 206 GLuint sizeY = 20; 207 197 void VertexArrayModel::planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY) 198 { 208 199 GLuint i, j; 209 for (i = 0; i < sizeY; i++)210 { 211 for (j = 0; j < sizeX; j++)200 for (i = 0; i < resolutionY; i++) 201 { 202 for (j = 0; j < resolutionX; j++) 212 203 { 213 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);204 this->addVertex((float)i - (float)sizeY/2.0, 0.0, (float)j - (float)sizeX/2.0); 214 205 this->addNormal(0.0, 1, 0.0); 215 this->addTexCoor((float)i/(float) sizeY, (float)j/(float)sizeY);206 this->addTexCoor((float)i/(float)resolutionY, (float)j/(float)resolutionY); 216 207 this->addColor((float)i/20.0, 0.0, (float)j/20.0); 217 208 } 218 209 } 219 210 220 for (i = 0; i < sizeY-1; i++)221 { 222 for (j = 0; j < sizeX; j++)223 { 224 this->addIndice( sizeY*i + j );225 this->addIndice( sizeY*(i+1) + j );211 for (i = 0; i < resolutionY-1; i++) 212 { 213 for (j = 0; j < resolutionX; j++) 214 { 215 this->addIndice( resolutionY*i + j ); 216 this->addIndice( resolutionY*(i+1) + j ); 226 217 } 227 218 this->newStripe(); … … 231 222 #include <cmath> 232 223 224 /** 225 * @brief builds a Triangle Stripped sphere 226 * @param radius: radius 227 * @param loops: the count of loops 228 * @param segmentsPerLoop how many Segments per loop 229 */ 233 230 void VertexArrayModel::spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop) 234 231 { … … 283 280 284 281 285 282 /** 283 * @brief print out some nice debug information about this VertexArrayModel. 284 */ 286 285 void VertexArrayModel::debug() const 287 286 { -
branches/height_map/src/lib/graphics/importer/vertex_array_model.h
r6265 r6267 45 45 46 46 // 47 void planeModel( );47 void planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY); 48 48 void spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop); 49 49 -
branches/height_map/src/story_entities/world.cc
r6266 r6267 393 393 394 394 VertexArrayModel* mod = new VertexArrayModel; 395 mod-> spiralSphere( 10,0,0);395 mod->planeModel(10.0, 10.0, 20, 20); 396 396 mod->finalize(); 397 397 mod->debug();
Note: See TracChangeset
for help on using the changeset viewer.