Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5967 in orxonox.OLD for branches/height_map


Ignore:
Timestamp:
Dec 7, 2005, 4:15:30 PM (19 years ago)
Author:
bottac
Message:

changes in height_map.cc

Location:
branches/height_map/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/height_map/src/lib/graphics/importer/height_map.cc

    r5942 r5967  
    1515#include "height_map.h"
    1616#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
    1728
    1829HeightMap::HeightMap() : Model()
    1930{
     31       
     32}
     33
     34HeightMap::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
     50HeightMap::~HeightMap()
     51{
     52        delete heightMap;
    2053}
    2154
    2255void HeightMap::load()
    2356{
    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");
    2691  this->addVertex (-0.5, -0.5, 0.5);
    2792  this->addVertex (0.5, -0.5, 0.5);
     
    3297  this->addVertex (-0.5, -0.5, -0.5);
    3398  this->addVertex (0.5, -0.5, -0.5);
     99       
    34100
    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);
    49101
    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);
    74102
    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);
    81104
     105        }
    82106      this->finalize();
    83107
  • branches/height_map/src/lib/graphics/importer/height_map.h

    r5942 r5967  
    1313*/
    1414
     15
    1516#include "model.h"
    1617
    17 
     18class SDL_Surface;
     19class Vector;
    1820
    1921class HeightMap : public Model
     
    2123public:
    2224void load();
     25void load(const char*, int);
    2326HeightMap();
     27HeightMap(const char*);
     28~HeightMap();
     29
     30private:
     31SDL_Surface* heightMap;
     32
    2433};
  • branches/height_map/src/lib/graphics/importer/model.h

    r5790 r5967  
    134134  inline unsigned int getTexCoordCount() const { return this->texCoordCount; };
    135135
    136   /** @returns the Count of Faces of this Model */
     136  /** @returns the Count of loadFaces of this Model */
    137137  inline unsigned int getFaceCount() const { return this->faceCount; };
    138138
  • branches/height_map/src/world_entities/terrain.cc

    r5940 r5967  
    4242  // this->loadParams(root);
    4343
    44  HeightMap * hm = new HeightMap();
     44 HeightMap * hm = new HeightMap("/home/bottac/svn/data/pictures/heightmapHello.bmp");
     45
    4546 hm->load();
    4647 this->model=hm;
Note: See TracChangeset for help on using the changeset viewer.