Changeset 6249 in orxonox.OLD for branches/height_map/src/lib
- Timestamp:
- Dec 21, 2005, 4:24:50 PM (19 years ago)
- Location:
- branches/height_map/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map/src/lib/graphics/importer/height_map.cc
r6227 r6249 21 21 #include "state.h" 22 22 #include "resource_manager.h" 23 24 23 #include "debug.h" 25 24 … … 88 87 } 89 88 90 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) 89 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel() 91 90 { 92 91 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); … … 187 186 { 188 187 189 }190 191 192 void HeightMap::draw()193 {194 195 188 this->camera = State::getCamera(); 196 189 this->camCoords = this->camera->getAbsCoor(); 197 190 float x = this->camCoords.x + 300; 198 191 float y = this->camCoords.z + 100; 199 200 // Draw a red rectangle to test getHeight201 202 red_mat->select();203 glBegin(GL_TRIANGLE_STRIP);204 glNormal3f(0,1,0);205 glTexCoord2d(1.0,0.0);206 glVertex3f(x-10,getHeight(x-10,y+10)+5.0f ,y+10); // Top Left207 208 209 glNormal3f(0,1,0);210 glTexCoord2d(1.0,1.0);211 glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left212 213 214 glNormal3f(0,1,0);215 glTexCoord2d(0.0,0.0);216 glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left217 218 219 glNormal3f(0,1,0);220 glTexCoord2d(0.0,1.0);221 glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left222 223 glEnd();224 192 225 193 tmp_mat->select(); … … 232 200 float old_b = 0.0f; 233 201 heights = (unsigned char*) heightMap->pixels; 234 235 202 bool colourChanged = true; 236 203 204 205 /* 206 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 207 {} 208 SDL_LockSurface(heightMap); 209 210 211 212 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 213 { 214 215 tmp_mat->select(); 216 217 218 219 int j = 0; 220 221 222 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 223 { 224 if(true) 225 { 226 float r = (float)colours[3*j+2 + 3*i*(heightMap->w )]; 227 float g = (float)colours[3*j+1 + 3*i*(heightMap->w)]; 228 float b = (float)colours[3*j+0 + 3*i*(heightMap->w)]; 229 colourChanged = old_r != r || old_g != g || old_b != b; 230 old_r = r; 231 old_g = g; 232 old_b = b; 233 if(colourChanged) 234 { 235 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0); 236 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0); 237 tmp_mat->select(); 238 } 239 } 240 241 242 height = heights[j+sampleRate + i*(heightMap->w )]; 243 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x); 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 250 } 251 252 253 254 255 256 257 258 259 260 } 261 262 263 264 SDL_UnlockSurface(heightMap); 265 266 267 int cnt = 0; 268 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 269 { 270 271 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 272 { 273 274 this->addIndice(cnt); 275 cnt ++; 276 } 277 if(i%2 == 1) 278 { 279 this->newStripe(); 280 } 281 } 282 283 284 285 286 */ 287 288 this->planeModel(); 289 290 this->finalize(); 291 292 293 } 294 295 /* 296 void HeightMap::draw() 297 { 298 299 this->camera = State::getCamera(); 300 this->camCoords = this->camera->getAbsCoor(); 301 float x = this->camCoords.x + 300; 302 float y = this->camCoords.z + 100; 303 304 // Draw a red rectangle to test getHeight 305 306 red_mat->select(); 307 glBegin(GL_TRIANGLE_STRIP); 308 glNormal3f(0,1,0); 309 glTexCoord2d(1.0,0.0); 310 glVertex3f(x-10,getHeight(x-10,y+10)+5.0f ,y+10); // Top Left 311 312 313 glNormal3f(0,1,0); 314 glTexCoord2d(1.0,1.0); 315 glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left 316 317 318 glNormal3f(0,1,0); 319 glTexCoord2d(0.0,0.0); 320 glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left 321 322 323 glNormal3f(0,1,0); 324 glTexCoord2d(0.0,1.0); 325 glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left 326 327 glEnd(); 328 329 tmp_mat->select(); 330 331 unsigned char height = 0; 332 int offset = 0; 333 int g = 0; 334 float old_r = 0.0f; 335 float old_g = 0.0f; 336 float old_b = 0.0f; 337 heights = (unsigned char*) heightMap->pixels; 338 339 bool colourChanged = true; 340 237 341 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 238 342 { 239 343 SDL_LockSurface(heightMap); 240 344 241 345 glBegin(GL_TRIANGLE_STRIP); 242 346 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 243 347 { … … 245 349 246 350 247 glBegin(GL_TRIANGLE_STRIP);351 248 352 int j = 0; 249 353 … … 256 360 glNormal3f(normalVectorField[i+2][j].y,normalVectorField[i+2][j].z,normalVectorField[i+2][j].x); 257 361 glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left 258 */ 259 260 362 363 */ 364 /* 261 365 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 262 366 { … … 277 381 } 278 382 } 279 280 if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000) > 1100 )*/){ //subdivide??281 383 */ 384 //if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000) > 1100 )*/){ //subdivide?? 385 /* 282 386 height = heights[j+sampleRate + i*(heightMap->w )]; 283 387 glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x); 284 388 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 285 ///glTexCoord2f(1.0,1.0);389 286 390 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 287 391 … … 292 396 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right 293 397 294 295 296 /*297 height = heights[j+2 + (i+2)*(heightMap->w )];298 glNormal3f(normalVectorField[i+2][j+2].y,normalVectorField[i+2][j+2].z,normalVectorField[i+2][j+2].x);299 glVertex3f(20*(heightMap->h -(i+2)),(double)((double)(height)/1-300),20*(j+2)); // Bottom Right300 301 302 height = heights[j + i*(heightMap->w )];303 glNormal3f(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);304 glVertex3f(20*(heightMap->h -(i)),(double)((double)(height)/1-300),20*(j)); // Top Left305 306 */307 g=j;308 309 310 398 } 311 399 else … … 335 423 glEnd(); 336 424 337 /*glBegin(GL_TRIANGLE_STRIP); 338 339 height = heights[j+sampleRate + i*(heightMap->w )]; 340 glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x); 341 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 342 343 344 height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )]; 425 426 427 428 429 //subdivide 430 } 431 432 433 } 434 j = heightMap->w -sampleRate; 435 436 345 437 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x); 346 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right 347 */ 348 349 350 351 //subdivide 352 } 353 354 355 356 } 357 glEnd(); 438 //glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0); 439 //glTexCoord2f(0.0,0.0); 440 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 441 glVertex3f(scaleX*(heightMap->h -i),(double)((double)-1000.0),scaleZ*(j+sampleRate)); // Top Right 442 443 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x); 444 glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0); 445 446 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)-1000.0,scaleZ*(j+sampleRate)); // Bottom Right 447 448 449 450 451 452 //glEnd(); 358 453 359 454 } 360 455 SDL_UnlockSurface(heightMap); 361 362 } 363 364 365 /* int c = (heightMap->w)/4 ; // One line 366 for(int i = 0; i < (heightMap->w)/4 -4 ; i ++) 367 { 368 for(int j = 0; j < (heightMap->h)/4 - 4; j++) 369 { 370 371 this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j+1+i*c , j + i*c ); 372 this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j + (i+1)*c +1 ,j+i*c +1 ); 373 374 375 } 376 377 378 379 } 380 456 glEnd(); 457 } 458 459 } 381 460 */ 382 }383 384 461 void HeightMap::generateNormalVectorField() 385 462 { -
branches/height_map/src/lib/graphics/importer/height_map.h
r6227 r6249 14 14 15 15 16 #include " model.h"16 #include "vertex_array_model.h" 17 17 18 #define sampleRate 218 #define sampleRate 4 19 19 20 20 class SDL_Surface; … … 24 24 class Texture; 25 25 26 class HeightMap : public Model26 class HeightMap : public VertexArrayModel 27 27 { 28 28 public: 29 void draw(); 29 30 30 void load(); 31 31 void load(int Mode); -
branches/height_map/src/lib/graphics/importer/vertex_array_model.cc
r6038 r6249 71 71 GL_TEXTURE_COORD_ARRAY | 72 72 GL_NORMAL_ARRAY); 73 //glEnableClientState(GL_INDEX_ARRAY);73 glEnableClientState(GL_INDEX_ARRAY); 74 74 75 75 glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray()); … … 77 77 glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray()); 78 78 79 for (GLuint i = 1; i < this->stripes.size(); ++i) 79 glDrawElements(GL_TRIANGLE_STRIP, this->indices.getCount(), GL_UNSIGNED_BYTE, this->indices.getArray()); 80 /* for (GLuint i = 1; i < this->stripes.size(); ++i) 80 81 { 81 82 glDrawRangeElements(GL_TRIANGLE_STRIP, … … 85 86 GL_UNSIGNED_BYTE, 86 87 this->indices.getArray()); 87 } 88 }*/ 88 89 } 89 90 … … 194 195 for (j = 0; j < 20; j++) 195 196 { 196 this->addVertex( i* 50, .5, (j)*50);197 this->addVertex((float)i, .5, (float)(j)); 197 198 this->addNormal(0, 1, 0); 198 199 this->addTexCoor((float)i/20.0, (float)j/20.0);
Note: See TracChangeset
for help on using the changeset viewer.