Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/height_map/src/lib/graphics/importer/height_map.cc @ 5989

Last change on this file since 5989 was 5989, checked in by bottac, 18 years ago

Branch height_map loads now heightmapHello.bmp from your data-directory.
You might need an old revision of data for this branch. I use revision 110.

  • Property svn:executable set to *
File size: 2.7 KB
Line 
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"
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
28
29HeightMap::HeightMap() : Model()
30{
31       
32}
33
34HeightMap::HeightMap(const char* height_map_name = NULL) : Model()
35{
36   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
37        heightMap =  IMG_Load(height_map_name);
38            if(heightMap!=NULL) {
39                 PRINTF(0)("loading Image %s\n", height_map_name);
40                 PRINTF(0)("width : %i\n", heightMap->w);
41                 PRINTF(0)("hight : %i\n", heightMap->h);
42                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
43
44               
45                }
46                 
47            else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
48}
49
50
51HeightMap::~HeightMap()
52{
53        delete heightMap;
54}
55
56void HeightMap::load()
57{
58 long height = 0; 
59 int offset = 0;
60 char *  bmp = (char*) heightMap->pixels;
61
62  if(heightMap != NULL /* && heightMap->format->BitsPerPixel == 8 */)
63        {
64                SDL_LockSurface(heightMap);
65                for(int i = 0 ; i < heightMap->; i +=1)
66                        {
67                        for(int j = 0; j < heightMap->w   ;  j += 1)
68                        {
69
70                                // get local hight from heightMap
71
72                               
73                               
74                                        offset = bmp[j + i*(heightMap->w )];
75                                        height = (unsigned int)heightMap->format->palette->colors[offset].r +
76                                            (unsigned int)heightMap->format->palette->colors[offset].g +
77                                         (unsigned int) heightMap->format->palette->colors[offset].b ;
78                                       
79                                       
80                                this->addVertex( 20*(heightMap->h - i) , (( height)/15) - 30 ,20*j);
81                        }       
82                        }
83SDL_UnlockSurface(heightMap);
84
85int c = (heightMap->w) ;
86int g = 0;
87
88                for(int i = 0; i < (heightMap->w)  -1  ; i += 1)
89                        {
90                                for(int j = 0; j < (heightMap->h)/1 - 1; j++)
91                                {
92                                //this->addFace (3, VERTEX_ONLY,j+1+i*c ,j + (i+1)*c, j + i*c );
93                               
94                                //this->addFace (3, VERTEX_ONLY,j + (i+1)*c +1 ,j + (i+1)*c,j+i*c +1 );                         
95                                 this->addFace (4 ,VERTEX_ONLY,j+i*c,j+(i+1)*,j + (i+1)*c +1, j +i*c+1 );
96                                        }
97                               
98                       
99                               
100                        }
101               
102
103        }
104  else
105        { 
106  //this->setName("HardCore");
107  this->addVertex (-0.5, -0.5, 0.5);
108  this->addVertex (0.5, -0.5, 0.5);
109  this->addVertex (-0.5, 0.5, 0.5);
110  this->addVertex (0.5, 0.5, 0.5);
111  this->addVertex (-0.5, 0.5, -0.5);
112  this->addVertex (0.5, 0.5, -0.5);
113  this->addVertex (-0.5, -0.5, -0.5);
114  this->addVertex (0.5, -0.5, -0.5);
115       
116
117
118
119  this->addFace (3, VERTEX_ONLY, 4, 3, 2);
120
121        }
122      this->finalize();
123
124
125}
Note: See TracBrowser for help on using the repository browser.