173 |
/** |
/** |
174 |
* Initialize the shadow field from a sun position. |
* Initialize the shadow field from a sun position. |
175 |
* The sun must be beyond the map. |
* The sun must be beyond the map. |
|
* The values are between 9 and 17 if we have to make a shadow , |
|
|
* or <= 8 if no shadows. |
|
|
* (bit shift >> 3 to have value between 1.125 and 2.125) |
|
176 |
*/ |
*/ |
177 |
- (void) _initWithSun: (coord_t)sun |
- (void) _initWithSun: (coord_t)sun |
178 |
{ |
{ |
179 |
/* FIXME - test sun position */ |
/* FIXME - test sun position */ |
180 |
/* calculs are faster with a sun height > 256 */ |
NSParameterAssert (sun.y > 256); |
|
NSParameterAssert (sun.y >= 0); |
|
181 |
|
|
182 |
int x, z; |
int z; |
|
for (z = 0; z < _zLength; z++) |
|
|
for (x = 0; x < _xLength; x++) |
|
|
{ |
|
|
*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 0; |
|
|
} |
|
|
|
|
|
int x_, z_; |
|
183 |
for (z = 0; z < _zLength; z++) |
for (z = 0; z < _zLength; z++) |
184 |
{ |
{ |
185 |
|
int x; |
186 |
for (x = 0; x < _xLength; x++) |
for (x = 0; x < _xLength; x++) |
187 |
{ |
{ |
188 |
coord_t pos |
coord_t pos |
190 |
|
|
191 |
if ([self _bresenham3DFromPoint: pos |
if ([self _bresenham3DFromPoint: pos |
192 |
toPoint: sun]) |
toPoint: sun]) |
193 |
{ |
*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 1; |
194 |
if (*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] <= 8) |
else |
195 |
*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] += 8; |
*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 0; |
|
|
|
|
for (x_ = -1; x_ <= 1; x_++) |
|
|
for (z_ = -1; z_ <= 1; z_++) |
|
|
*[self _shadowFieldAtPosition: |
|
|
MakeMapCoord (MOD (x + x_, _xLength), |
|
|
MOD (z + z_, _zLength))] += 1; |
|
|
} |
|
196 |
} |
} |
197 |
|
|
198 |
double val = (double) z / (double) _zLength * 100.0; |
double val = (double) z / (double) _zLength * 100.0; |
239 |
[self _initWithSun: sun]; |
[self _initWithSun: sun]; |
240 |
} |
} |
241 |
|
|
|
RELEASE(_land); |
|
242 |
return self; |
return self; |
243 |
} |
} |
244 |
|
|
245 |
- (void) dealloc |
- (void) dealloc |
246 |
{ |
{ |
247 |
|
RELEASE(_land); |
248 |
RELEASE(_image); |
RELEASE(_image); |
249 |
|
|
250 |
[super dealloc]; |
[super dealloc]; |
251 |
} |
} |
252 |
|
|
253 |
/** |
/** |
254 |
* Return a value between 9 and 17 if we have to make a shadow for the |
* Return YES if we have to make a shadow for the position. |
|
* position, or 0 if no shadows. |
|
|
* (bit shift >> 3 to have value between 1.125 and 2.125) |
|
255 |
* The position parameter must be contained in the map coordinates. |
* The position parameter must be contained in the map coordinates. |
256 |
*/ |
*/ |
257 |
- (u_int8_t) shadowAtPoint: (map_coord_t)position |
- (BOOL) shadowAtPoint: (map_coord_t)position |
258 |
{ |
{ |
259 |
return *[self _shadowFieldAtPosition: position]; |
return *[self _shadowFieldAtPosition: position]; |
260 |
} |
} |