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 | |
---|
29 | HeightMap::HeightMap() : Model() |
---|
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; |
---|
53 | } |
---|
54 | |
---|
55 | void HeightMap::load() |
---|
56 | { |
---|
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 += 2) |
---|
64 | { |
---|
65 | for(int j = 0; j < heightMap->w; j += 2) |
---|
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 , ((long)( height) / 10) - 15 ,heightMap->w - j); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | for(int i = 0; i < (heightMap->h * heightMap->w) / 4 - heightMap->w /2 -1 ; i ++) |
---|
80 | { |
---|
81 | this->addFace (3, VERTEX_ONLY, i,i+1 ,i + (heightMap->w / 2) ); |
---|
82 | |
---|
83 | this->addFace (3, VERTEX_ONLY, i+1,i + (heightMap->w / 2) ,i + (heightMap->w / 2) +1 ); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | //this->setName("HardCore"); |
---|
91 | this->addVertex (-0.5, -0.5, 0.5); |
---|
92 | this->addVertex (0.5, -0.5, 0.5); |
---|
93 | this->addVertex (-0.5, 0.5, 0.5); |
---|
94 | this->addVertex (0.5, 0.5, 0.5); |
---|
95 | this->addVertex (-0.5, 0.5, -0.5); |
---|
96 | this->addVertex (0.5, 0.5, -0.5); |
---|
97 | this->addVertex (-0.5, -0.5, -0.5); |
---|
98 | this->addVertex (0.5, -0.5, -0.5); |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | this->addFace (3, VERTEX_ONLY, 4, 3, 2); |
---|
104 | |
---|
105 | } |
---|
106 | this->finalize(); |
---|
107 | |
---|
108 | |
---|
109 | } |
---|