/[hegemonie]/hegemonie/Map/Display/MapDisplay.m
ViewVC logotype

Diff of /hegemonie/Map/Display/MapDisplay.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by daniel, Tue Sep 2 09:39:45 2003 UTC revision 1.20 by dam, Wed Sep 3 20:56:02 2003 UTC
# Line 46  struct vertex_t { Line 46  struct vertex_t {
46  @interface MapDisplayTemp : NSObject  @interface MapDisplayTemp : NSObject
47  {  {
48  @public  @public
49    float            maxProjHeight;    real_t            maxProjHeight;
50    
51    struct vertex_t *currentRay;    struct vertex_t *currentRay;
52    unsigned         currentRayLength;    unsigned         currentRayLength;
# Line 157  _fill_vertices_array (MapColors *map, co Line 157  _fill_vertices_array (MapColors *map, co
157  {  {
158    map_coord_t map_pos = MakeMapCoord (pos.x, pos.z);    map_coord_t map_pos = MakeMapCoord (pos.x, pos.z);
159    color_t color = [map colorForHeight: pos.y];    color_t color = [map colorForHeight: pos.y];
160    coord_t normal = {0.0f, 1.0f, 0.0f};//[map normalAtPosition: map_pos]; /* FIXME - interpolate */    coord_t normal = [map normalAtPosition: map_pos]; /* FIXME - interpolate */
161    
162    vertice[0] = color.red;    vertice[0] = color.red;
163    vertice[1] = color.green;    vertice[1] = color.green;
# Line 315  _vertices_add (MapColors *map, struct ma Line 315  _vertices_add (MapColors *map, struct ma
315   * This function uses the OpenGL current model view, projection, and viewport   * This function uses the OpenGL current model view, projection, and viewport
316   * matrices.   * matrices.
317   */   */
318  static inline float  static inline real_t
319  _project_point (const coord_t point)  _project_point (const coord_t point)
320  {  {
321    GLdouble winX, winY, winZ;    GLdouble winX, winY, winZ;
# Line 334  _project_point (const coord_t point) Line 334  _project_point (const coord_t point)
334    return winY;    return winY;
335  }  }
336    
 #define HEIGHT(_l,_k) \  
   heightField[MOD(_l, width) \  
               + MOD(_k, height) * width]  
   
337  /**  /**
338   * Returns the height at the given position using bilinear interpolation   * Returns the height at the given position using bilinear interpolation
339   * between the near map heights.   * between the near map heights.
340   */   */
341  static inline float  static inline real_t
342  _height_at_position (const float x, const float z,  _interpolate_height_at_position (const struct map_terrain_t *terrain,
343                       const u_int8_t *heightField,                                   const real_t x, const real_t z)
                      const unsigned width, const unsigned height)  
344  {  {
345    int l = floor (x);    int l = floor (x);
346    int k = floor (z);    int k = floor (z);
347    const float a = x - l;    const real_t a = x - l;
348    const float b = z - k;    const real_t b = z - k;
349    
350    return (1.0f - a) * (1.0f - b) * HEIGHT(l, k)    return (1.0f - a) * (1.0f - b)
351           + a * (1.0f - b) * HEIGHT(l + 1, k)                      * map_height_at_position (terrain, MakeMapCoord(l, k))
352           + (1.0f - a) * b * HEIGHT(l, k + 1)           + a * (1.0f - b) * map_height_at_position (terrain,
353           + a * b * HEIGHT(l + 1, k + 1);                                                      MakeMapCoord(l + 1, k))
354             + (1.0f - a) * b * map_height_at_position (terrain,
355                                                        MakeMapCoord(l, k + 1))
356             + a * b * map_height_at_position (terrain,
357                                               MakeMapCoord (l + 1, k + 1));
358  }  }
359    
360  /**  /**
361   * Returns the current ray step. This steps goes up with the distance.   * Returns the current ray step. This steps goes up with the distance.
362   */   */
363  static inline float  static inline real_t
364  _calc_step (const float step, const float t)  _calc_step (const real_t step, const clamp_t t)
365  {  {
366    if (t < 0.25f)    if (t < 0.25f)
367      return step;      return step;
# Line 381  _calc_step (const float step, const floa Line 380  _calc_step (const float step, const floa
380   * continue.   * continue.
381   */   */
382  static inline BOOL  static inline BOOL
383  _reach_point (const float x, const float z,  _reach_point (const struct map_terrain_t *terrain,
384                const u_int8_t *heightField,                const real_t x, const real_t z,
               const unsigned width, const unsigned height,  
385                MapDisplayTemp *tmp)                MapDisplayTemp *tmp)
386  {  {
387    const coord_t point    const coord_t point
388      = MakeCoord (x,_height_at_position (x, z, heightField, width, height), z);      = MakeCoord (x, _interpolate_height_at_position (terrain, x, z), z);
389    const float projHeight = _project_point (point);    const real_t projHeight = _project_point (point);
390    const BOOL keepPoint = projHeight > tmp->maxProjHeight - 5.0f;    const BOOL keepPoint = projHeight > tmp->maxProjHeight - 5.0f;
391    
392    if (projHeight > tmp->maxProjHeight) /* keep point */    if (projHeight > tmp->maxProjHeight) /* keep point */
# Line 411  _reach_point (const float x, const float Line 409  _reach_point (const float x, const float
409   */   */
410  - (void) _surfFromPoint: (coord_t)start  - (void) _surfFromPoint: (coord_t)start
411                  toPoint: (coord_t)end                  toPoint: (coord_t)end
412                   length: (float)length                   length: (real_t)length
413  {  {
414  //   const float length =  sqrt (SQUARE(start.z - end.z)  //   const real_t length =  sqrt (SQUARE(start.z - end.z)
415  //                            + SQUARE(start.x - end.x));  //                            + SQUARE(start.x - end.x));
416    const float step = 1.0f / length;    const real_t step = 1.0f / length;
   const unsigned width = [self width];  
   const unsigned height = [self height];  
   const u_int8_t *heightField = [self heightField];  
417        
418    [_tmp startRayWithLength: ceil (length)];    [_tmp startRayWithLength: ceil (length)];
419    
420    float t;    clamp_t t;
421    for (t = 0.0f; t <= 1.0f; t += _calc_step (step, t)) /* FIXME */    for (t = 0.0f; t <= 1.0f; t += _calc_step (step, t)) /* FIXME */
422      {      {
423        const float x = start.x + t * (end.x - start.x);        const real_t x = start.x + t * (end.x - start.x);
424        const float z = start.z + t * (end.z - start.z);        const real_t z = start.z + t * (end.z - start.z);
425    
426        if (!_reach_point (x, z, heightField, width, height, _tmp))        if (!_reach_point ((struct map_terrain_t *)self, x, z, _tmp))
427          break;          break;
428      }      }
429    

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26