Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/height_map.cc @ 6452

Last change on this file since 6452 was 6100, checked in by bensch, 18 years ago

orxonox/trunk: copied the heightMap to the trunk, and adapted to partly new framework

  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[5942]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer:
13*/
14
15#include "height_map.h"
16#include "model.h"
[5967]17#include "texture.h"
18#include "vector.h"
[5942]19
[5967]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
28
[6100]29HeightMap::HeightMap() : StaticModel()
[5942]30{
[5967]31       
[5942]32}
33
[6100]34HeightMap::HeightMap(const char* height_map_name = NULL) : StaticModel()
[5967]35{
[5976]36   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
[5990]37   heightMap =  IMG_Load(height_map_name);
38   if(heightMap!=NULL) {
39       
[5967]40                 PRINTF(0)("loading Image %s\n", height_map_name);
41                 PRINTF(0)("width : %i\n", heightMap->w);
42                 PRINTF(0)("hight : %i\n", heightMap->h);
43                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
[5990]44                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
45                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
46                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
47                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
48                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);           
[5967]49                }
50                 
[5990]51     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
[5967]52}
53
54
55HeightMap::~HeightMap()
56{
57        delete heightMap;
58}
59
[5942]60void HeightMap::load()
61{
[5993]62 unsigned char height = 0; 
[5967]63 int offset = 0;
[5993]64
[5967]65 char *  bmp = (char*) heightMap->pixels;
66
[5990]67  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
[5967]68        {
[5990]69        SDL_LockSurface(heightMap);
[5993]70        for(int i = 0 ; i < heightMap->; i +=2)
[5990]71        {
[5993]72            for(int j = 0; j < heightMap->w   ;  j += 2)
[5990]73            {
74                // get local hight from heightMap
75                // This seems to work only on 8-Bit Grayscale-Bitmaps
76                height = bmp[j + i*(heightMap->w )];
77               
78                       
79                /*height = heightMap->format->palette->colors[offset].r +
80                           heightMap->format->palette->colors[offset].g +
81                           heightMap->format->palette->colors[offset].b ; */
[5976]82                                       
[5993]83                               
[6099]84                this->addVertex( 20*(heightMap->h - i) , (( (double)height)/0.3)-1200  ,20*j);
[5990]85             } 
86        }
87        SDL_UnlockSurface(heightMap);
[5980]88
[5993]89
90
91        int c = (heightMap->w)/2 ; // One line
92        for(int i = 0; i < (heightMap->w)/2  -2  ; i ++)
[5990]93        {
[5993]94            for(int j = 0; j < (heightMap->h)/2 - 2; j++)
[5990]95            {
96                 
97                /* Two Triangles or ...*/ 
98               
[6099]99                //this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j+1+i*c , j + i*c );
100                //this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j + (i+1)*c +1 ,j+i*c +1 );                         
[5990]101                                 
102                /* ... one square*/
[5980]103
[6099]104                this->addFace (4 ,VERTEX_ONLY,j+i*c,j+(i+1)*,j + (i+1)*c +1, j +i*c+1 );
[5990]105            }
[5967]106                               
[5980]107                       
108                               
[5990]109        }
[5967]110               
111
[5990]112        }//if
[5967]113  else
114        { 
[5990]115
116  //make a cube
117  this->setName("HardCore");
[5942]118  this->addVertex (-0.5, -0.5, 0.5);
119  this->addVertex (0.5, -0.5, 0.5);
120  this->addVertex (-0.5, 0.5, 0.5);
121  this->addVertex (0.5, 0.5, 0.5);
122  this->addVertex (-0.5, 0.5, -0.5);
123  this->addVertex (0.5, 0.5, -0.5);
124  this->addVertex (-0.5, -0.5, -0.5);
125  this->addVertex (0.5, -0.5, -0.5);
[5967]126       
[5942]127
128
129
[5967]130  this->addFace (3, VERTEX_ONLY, 4, 3, 2);
[5942]131
[5967]132        }
[5942]133      this->finalize();
134
135
136}
Note: See TracBrowser for help on using the repository browser.