23 |
|
|
24 |
#include <stdio.h> |
#include <stdio.h> |
25 |
|
|
26 |
|
#include <Foundation/NSDictionary.h> |
27 |
|
#include <Foundation/NSString.h> |
28 |
|
#include <Foundation/NSException.h> |
29 |
|
#include <Foundation/NSPathUtilities.h> |
30 |
|
|
31 |
#include "Common/Camera.h" |
#include "Common/Camera.h" |
32 |
#include "Map/MapDisplay.h" |
#include "Map/MapDisplay.h" |
33 |
|
#include "Map/MapShadows.h" |
34 |
#include "MapRandom.h" |
#include "MapRandom.h" |
35 |
#include "MapModel.h" |
#include "MapModel.h" |
36 |
|
|
66 |
initWithContentsOfFile: mapName]; |
initWithContentsOfFile: mapName]; |
67 |
|
|
68 |
[self _initCamera]; |
[self _initCamera]; |
69 |
|
|
70 |
|
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile: mapName]; |
71 |
|
|
72 |
|
NSString *path = [mapName stringByDeletingLastPathComponent]; |
73 |
|
if ([[dic objectForKey: @"shadows"] length] != 0) |
74 |
|
_shadowsName = [path stringByAppendingPathComponent: |
75 |
|
[dic objectForKey: @"shadows"]]; |
76 |
|
else |
77 |
|
_shadowsName = [dic objectForKey: @"shadows"]; |
78 |
|
|
79 |
|
_shadows = [[MapShadows alloc] initWithShadowsImageName: _shadowsName]; |
80 |
} |
} |
81 |
|
|
82 |
- (void) openMapWithXLength: (int)xLength |
- (void) openMapWithXLength: (int)xLength |
84 |
andMaxHeight: (int)maxHeight |
andMaxHeight: (int)maxHeight |
85 |
{ |
{ |
86 |
TEST_RELEASE (_map); |
TEST_RELEASE (_map); |
87 |
|
printf("open MapRandom \n"); |
88 |
|
|
89 |
_map = [[MapDisplay alloc] initWithWidth: xLength |
_map = [[MapDisplay alloc] initWithWidth: xLength |
90 |
height: zLength]; |
height: zLength]; |
93 |
andMaxHeight: maxHeight]; |
andMaxHeight: maxHeight]; |
94 |
|
|
95 |
[self _initCamera]; |
[self _initCamera]; |
96 |
|
|
97 |
|
_shadowsName = [NSString string]; |
98 |
|
_shadows = nil; |
99 |
|
} |
100 |
|
|
101 |
|
- (void) dealloc |
102 |
|
{ |
103 |
|
printf("dealloc MapModel \n"); |
104 |
|
TEST_RELEASE (_camera); |
105 |
|
TEST_RELEASE (_map); |
106 |
|
TEST_RELEASE (_shadows); |
107 |
|
|
108 |
|
[super dealloc]; |
109 |
} |
} |
110 |
|
|
111 |
/** |
/** |
162 |
eye.y = (double) (MAX([_map width],[_map height]) + 550) |
eye.y = (double) (MAX([_map width],[_map height]) + 550) |
163 |
/ tan(DEGTORAD (50.0)); |
/ tan(DEGTORAD (50.0)); |
164 |
eye.z = (double) ([_map height]) / 2.0; |
eye.z = (double) ([_map height]) / 2.0; |
165 |
|
double aspect = [_camera aspect]; |
166 |
|
|
167 |
TEST_RELEASE (_camera); |
TEST_RELEASE (_camera); |
168 |
_camera = |
_camera = |
169 |
[[Camera alloc] initWithFovy: 50.0 |
[[Camera alloc] initWithFovy: 50.0 |
170 |
aspect: 1.0 |
aspect: aspect |
171 |
zNear: 5.0 |
zNear: 5.0 |
172 |
zFar: 100000.0 |
zFar: 100000.0 |
173 |
eye: eye |
eye: eye |
186 |
coord_t eye = [_camera eye]; |
coord_t eye = [_camera eye]; |
187 |
coord_t center = [_camera center]; |
coord_t center = [_camera center]; |
188 |
double h = [_map heightAtPosition: MakeMapCoord (eye.x, eye.z)]; |
double h = [_map heightAtPosition: MakeMapCoord (eye.x, eye.z)]; |
189 |
|
double aspect = [_camera aspect]; |
190 |
if (eye.y < h + 5.0) |
if (eye.y < h + 5.0) |
191 |
{ |
{ |
192 |
TEST_RELEASE (_camera); |
TEST_RELEASE (_camera); |
193 |
|
|
194 |
_camera = |
_camera = |
195 |
[[Camera alloc] initWithFovy: 50.0 |
[[Camera alloc] initWithFovy: 50.0 |
196 |
aspect: 1.0 |
aspect: aspect |
197 |
zNear: 5.0 |
zNear: 5.0 |
198 |
zFar: 255.0 |
zFar: 255.0 |
199 |
eye: MakeCoord (eye.x, h + 5.0, eye.z) |
eye: MakeCoord (eye.x, h + 5.0, eye.z) |
202 |
} |
} |
203 |
} |
} |
204 |
|
|
205 |
- (void) dealloc |
/** |
206 |
|
* Displays or not the shadows. |
207 |
|
*/ |
208 |
|
- (void) enableShadows: (BOOL)shadows |
209 |
{ |
{ |
210 |
printf("dealloc MapModel \n"); |
if ((_shadows != nil) && [_shadowsName length] != 0) |
211 |
TEST_RELEASE (_camera); |
{ |
212 |
TEST_RELEASE (_map); |
printf ("enableShadows\n"); |
213 |
|
if (shadows) |
214 |
|
[_map setShadows: _shadowsName]; |
215 |
|
else |
216 |
|
[_map setShadows: [NSString string]]; |
217 |
|
} |
218 |
|
} |
219 |
|
|
220 |
[super dealloc]; |
- (void) computeShadowsWithSun: (coord_t)sun |
221 |
|
{ |
222 |
|
NSParameterAssert (_map); |
223 |
|
TEST_RELEASE (_shadows); |
224 |
|
_shadows = [[MapShadows alloc] initWithLand: _map |
225 |
|
sun: sun]; |
226 |
|
|
227 |
|
_shadowsName = @"saveShadows.tiff"; |
228 |
|
[_shadows saveWithShadowsImageName: _shadowsName]; |
229 |
|
[_map setShadows: _shadowsName]; |
230 |
|
} |
231 |
|
|
232 |
|
- (BOOL) saveWithShadowsImageName: (NSString *)shadows |
233 |
|
{ |
234 |
|
NSParameterAssert (_shadows); |
235 |
|
|
236 |
|
return [_shadows saveWithShadowsImageName: shadows]; |
237 |
} |
} |
238 |
|
|
239 |
- (Camera *) getCamera |
- (Camera *) getCamera |