155 |
- (coord_t) normalAtPosition: (map_coord_t)position |
- (coord_t) normalAtPosition: (map_coord_t)position |
156 |
{ |
{ |
157 |
if (_normalsData) |
if (_normalsData) |
158 |
{ |
return ((const coord_t *)[_normalsData bytes]) |
159 |
const unsigned width = [self width]; |
[position.x + position.z * _xLength]; |
|
const unsigned height = [self height]; |
|
|
|
|
|
return ((const coord_t *)[_normalsData bytes]) |
|
|
[MOD(position.x, width) + MOD(position.z, height) * width]; |
|
|
} |
|
160 |
else |
else |
161 |
{ |
{ |
162 |
const real_t h1 = [self heightAtPosition: MakeMapCoord (position.x + 1, |
const real_t h1 = [self heightAtPosition: MakeMapCoord (position.x + 1, |
176 |
} |
} |
177 |
|
|
178 |
/** |
/** |
179 |
* Returns the color for a given height. |
* Returns the color of the given position with a given height. |
180 |
*/ |
*/ |
181 |
- (color_t) colorForHeight: (int)height |
- (color_t) colorAtPosition: (map_coord_t)position |
182 |
|
withHeight: (int)height |
183 |
{ |
{ |
184 |
NSParameterAssert (height >= 0); |
NSParameterAssert (height >= 0); |
185 |
NSParameterAssert (height < COLORS_SIZE); |
NSParameterAssert (height < COLORS_SIZE); |
186 |
|
|
187 |
|
color_t color = _colors[height]; |
188 |
|
|
189 |
return _colors[height]; |
if (_shadows) |
190 |
} |
{ |
191 |
|
float shadow = (float) ([_shadows shadowAtPoint: position] >> 3); |
|
#define SHADOW_FACTOR 2.2f |
|
192 |
|
|
193 |
/** |
if (shadow > 1.0) |
194 |
* Returns the color of the given position. |
return MakeColor |
195 |
*/ |
(color.red / shadow, color.green / shadow, color.blue / shadow); |
196 |
- (color_t) colorAtPosition: (map_coord_t)position |
else |
197 |
{ |
return MakeColor (color.red, color.green, color.blue); |
198 |
u_int8_t height = [self heightAtPosition: position]; |
} |
|
|
|
|
clamp_t r = _colors[height].red; |
|
|
clamp_t g = _colors[height].green; |
|
|
clamp_t b = _colors[height].blue; |
|
|
|
|
|
if (_shadows && [_shadows shadowAtPoint: position]) |
|
|
return MakeColor (r / SHADOW_FACTOR, g / SHADOW_FACTOR, b / SHADOW_FACTOR); |
|
199 |
else |
else |
200 |
return MakeColor (r, g, b); |
return MakeColor (color.red, color.green, color.blue); |
201 |
} |
} |
202 |
|
|
203 |
/** |
/** |
208 |
- (void) setShadows: (NSString *)shadows |
- (void) setShadows: (NSString *)shadows |
209 |
{ |
{ |
210 |
NSParameterAssert (shadows); |
NSParameterAssert (shadows); |
|
NSParameterAssert ([shadows length] != 0); |
|
211 |
|
|
212 |
|
TEST_RELEASE (_shadows); |
213 |
_shadows = [[MapShadows alloc] initWithShadowsImageName: shadows]; |
_shadows = [[MapShadows alloc] initWithShadowsImageName: shadows]; |
214 |
} |
} |
215 |
|
|