Changeset 4093 in orxonox.OLD for orxonox/branches/heightMap/src/lib/graphics/importer
- Timestamp:
- May 6, 2005, 8:19:01 PM (20 years ago)
- Location:
- orxonox/branches/heightMap/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/heightMap/src/lib/graphics/importer/heightmap.cc
r4090 r4093 16 16 this->setName(fileName); 17 17 18 this->import(fileName );18 this->import(fileName, displaylistResolution, vertexResolution); 19 19 20 //this->finalize();20 this->finalize(); 21 21 } 22 22 … … 25 25 } 26 26 27 bool Heightmap::import (const char* fileName )27 bool Heightmap::import (const char* fileName, int displaylistResolution, int vertexResolution) 28 28 { 29 29 PRINTF(4)("preparing to read in file: %s\n", fileName); … … 32 32 this->bitmap = IMG_Load(fileName); 33 33 34 // how many pixels wide is a display list? 35 int pixPerDLSide = displaylistResolution * vertexResolution; 36 37 int howManyListsWide = bitmap->w / pixPerDLSide + 1; 38 int howManyListsHigh = bitmap->h / pixPerDLSide + 1; 34 39 40 // calculated pixel dimensions of one display list. usually equals pixPerDLSide, but at the end of the picture 41 // this needs to be shorter, that we do not make a segfault 42 int width = pixPerDLSide; 43 int height = pixPerDLSide; 35 44 36 45 for (int i=0; i<howManyListsWide; i++) 46 { 47 for (int j=0; j<howManyListsHigh; j++) 48 { 49 // catch out of image access in x-direction 50 if ( (j+1)*pixPerDLSide - 1 >= bitmap->w ) width = bitmap->w - j*pixPerDLSide; 51 else width = pixPerDLSide; 52 // y-direction 53 if ( (i+1)*pixPerDLSide - 1 >= bitmap->h ) height = bitmap->h - i*pixPerDLSide; 54 else height = pixPerDLSide; 55 56 this->readIntoGroup(j*pixPerDLSide,i*pixPerDLSide,width,height,vertexResolution); 57 } 58 } 37 59 38 60 return true; 39 61 } 40 62 63 void Heightmap::readIntoGroup(int left, int top,int width, int height, int vertexResolution) 64 { 65 //this->newGroup(); 66 67 for (int z=top; z < top+height; z++) 68 { 69 for (int x=left; x < left+width; x++) 70 { 71 this->addVertex(x,this->getHeightAt(x,z),z); 72 } 73 } 74 } 75 76 float Heightmap::getHeightAt(int x, int z) 77 { 78 Uint8 index; 79 SDL_Color color; 80 81 SDL_LockSurface(bitmap); 82 83 index = *((Uint8*)bitmap->pixels + z * bitmap->pitch + x * bitmap->format->BytesPerPixel); 84 color = bitmap->format->palette->colors[index]; 85 86 SDL_UnlockSurface(bitmap); 87 88 // return the red component, because in a grayscale pic, r,g and b are all the same value 89 return (GLint)color.r; 90 } -
orxonox/branches/heightMap/src/lib/graphics/importer/heightmap.h
r4090 r4093 16 16 17 17 private: 18 bool import (const char* fileName); 18 bool Heightmap::import (const char* fileName, int displaylistResolution, int vertexResolution); 19 void Heightmap::readIntoGroup(int left, int top,int width, int height, int vertexResolution); 20 21 float Heightmap::getHeightAt(int x, int z); 19 22 20 23 // holds the loaded pixels
Note: See TracChangeset
for help on using the changeset viewer.