Changeset 5967 in orxonox.OLD for branches/height_map/src/lib
- Timestamp:
- Dec 7, 2005, 4:15:30 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
r5942 r5967 15 15 #include "height_map.h" 16 16 #include "model.h" 17 #include "texture.h" 18 #include "vector.h" 19 20 #include "debug.h" 21 22 // INCLUDING SDL_Image 23 #ifdef HAVE_SDL_IMAGE_H 24 #include <SDL_image.h> 25 #else 26 #include <SDL/SDL_image.h> 27 #endif 17 28 18 29 HeightMap::HeightMap() : Model() 19 30 { 31 32 } 33 34 HeightMap::HeightMap(const char* height_map_name = NULL) : Model() 35 { 36 heightMap = IMG_Load(height_map_name); 37 if(heightMap!=NULL) { 38 PRINTF(0)("loading Image %s\n", height_map_name); 39 PRINTF(0)("width : %i\n", heightMap->w); 40 PRINTF(0)("hight : %i\n", heightMap->h); 41 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel); 42 43 44 } 45 46 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name); 47 } 48 49 50 HeightMap::~HeightMap() 51 { 52 delete heightMap; 20 53 } 21 54 22 55 void HeightMap::load() 23 56 { 24 25 this->setName("HardCore"); 57 int height = 0; 58 int offset = 0; 59 char * bmp = (char*) heightMap->pixels; 60 61 if(heightMap != NULL /* && heightMap->format->BitsPerPixel == 8 */) 62 { 63 for(int i = 0; i < heightMap->h; i += 8) 64 { 65 for(int j = 0; j < heightMap->w; j += 8) 66 { 67 68 // get local hight from heightMap 69 70 71 SDL_LockSurface(heightMap); 72 height = bmp[j + i*heightMap->w]; 73 //height = heightMap->format->palette->colors[offset]; 74 SDL_UnlockSurface(heightMap); 75 this->addVertex(heightMap->h - i , height ,heightMap->w - j); 76 } 77 } 78 79 for(int i = 0; i < (heightMap->h * heightMap->w) / 64 - heightMap->w /8 ; i ++) 80 { 81 this->addFace (3, VERTEX_ONLY, i,i+1 ,i + (heightMap->w / 8) ); 82 83 this->addFace (3, VERTEX_ONLY, i+1,i + (heightMap->w / 8) ,i + (heightMap->w / 8) +1 ); 84 } 85 86 87 } 88 else 89 { 90 //this->setName("HardCore"); 26 91 this->addVertex (-0.5, -0.5, 0.5); 27 92 this->addVertex (0.5, -0.5, 0.5); … … 32 97 this->addVertex (-0.5, -0.5, -0.5); 33 98 this->addVertex (0.5, -0.5, -0.5); 99 34 100 35 this->addVertexTexture (0.0, 0.0);36 this->addVertexTexture (1.0, 0.0);37 this->addVertexTexture (0.0, 1.0);38 this->addVertexTexture (1.0, 1.0);39 this->addVertexTexture (0.0, 2.0);40 this->addVertexTexture (1.0, 2.0);41 this->addVertexTexture (0.0, 3.0);42 this->addVertexTexture (1.0, 3.0);43 this->addVertexTexture (0.0, 4.0);44 this->addVertexTexture (1.0, 4.0);45 this->addVertexTexture (2.0, 0.0);46 this->addVertexTexture (2.0, 1.0);47 this->addVertexTexture (-1.0, 0.0);48 this->addVertexTexture (-1.0, 1.0);49 101 50 this->addVertexNormal (0.0, 0.0, 1.0);51 this->addVertexNormal (0.0, 0.0, 1.0);52 this->addVertexNormal (0.0, 0.0, 1.0);53 this->addVertexNormal (0.0, 0.0, 1.0);54 this->addVertexNormal (0.0, 1.0, 0.0);55 this->addVertexNormal (0.0, 1.0, 0.0);56 this->addVertexNormal (0.0, 1.0, 0.0);57 this->addVertexNormal (0.0, 1.0, 0.0);58 this->addVertexNormal (0.0, 0.0, -1.0);59 this->addVertexNormal (0.0, 0.0, -1.0);60 this->addVertexNormal (0.0, 0.0, -1.0);61 this->addVertexNormal (0.0, 0.0, -1.0);62 this->addVertexNormal (0.0, -1.0, 0.0);63 this->addVertexNormal (0.0, -1.0, 0.0);64 this->addVertexNormal (0.0, -1.0, 0.0);65 this->addVertexNormal (0.0, -1.0, 0.0);66 this->addVertexNormal (1.0, 0.0, 0.0);67 this->addVertexNormal (1.0, 0.0, 0.0);68 this->addVertexNormal (1.0, 0.0, 0.0);69 this->addVertexNormal (1.0, 0.0, 0.0);70 this->addVertexNormal (-1.0, 0.0, 0.0);71 this->addVertexNormal (-1.0, 0.0, 0.0);72 this->addVertexNormal (-1.0, 0.0, 0.0);73 this->addVertexNormal (-1.0, 0.0, 0.0);74 102 75 this->addFace (3, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2); 76 this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7); 77 this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11); 78 this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15); 79 this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19); 80 this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23); 103 this->addFace (3, VERTEX_ONLY, 4, 3, 2); 81 104 105 } 82 106 this->finalize(); 83 107 -
branches/height_map/src/lib/graphics/importer/height_map.h
r5942 r5967 13 13 */ 14 14 15 15 16 #include "model.h" 16 17 17 18 class SDL_Surface; 19 class Vector; 18 20 19 21 class HeightMap : public Model … … 21 23 public: 22 24 void load(); 25 void load(const char*, int); 23 26 HeightMap(); 27 HeightMap(const char*); 28 ~HeightMap(); 29 30 private: 31 SDL_Surface* heightMap; 32 24 33 }; -
branches/height_map/src/lib/graphics/importer/model.h
r5790 r5967 134 134 inline unsigned int getTexCoordCount() const { return this->texCoordCount; }; 135 135 136 /** @returns the Count of Faces of this Model */136 /** @returns the Count of loadFaces of this Model */ 137 137 inline unsigned int getFaceCount() const { return this->faceCount; }; 138 138
Note: See TracChangeset
for help on using the changeset viewer.