medfall

A super great game engine
Log | Files | Refs

commit ae6b996e81ba9c8abb259b4ec82112e8190e3aa0
parent fd7f9735c5ebf983b5f8cae9270e3b48b3c51e56
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 26 Nov 2017 12:12:17 +0200

Move the xy plane intersection into ray_vs_terrain

Diffstat:
clipmap.cc | 12++++++------
heightmap.cc | 11++++++++---
heightmap.h | 3++-
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -674,12 +674,12 @@ GAME_FRAME( game_frame ) { float high_t = -1; v3 low_normal, high_normal; - bool low_hit = segment_vs_quadtree( clipmap.quadtree, low_start, low_end, &low_t, &low_normal ); + bool low_hit = segment_vs_terrain( clipmap.quadtree, low_start, low_end, &low_t, &low_normal ); bool high_hit = false; - bool step_up_hit = segment_vs_quadtree( clipmap.quadtree, low_start, high_start, NULL, NULL ); + bool step_up_hit = segment_vs_terrain( clipmap.quadtree, low_start, high_start, NULL, NULL ); if( !step_up_hit ) { - high_hit = segment_vs_quadtree( clipmap.quadtree, high_start, high_end, &high_t, &high_normal ); + high_hit = segment_vs_terrain( clipmap.quadtree, high_start, high_end, &high_t, &high_normal ); } v3 step_down_start; @@ -715,7 +715,7 @@ GAME_FRAME( game_frame ) { float step_down_t; v3 step_down_end = step_down_start - v3( 0, 0, step_down_distance ); - bool step_down_hit = segment_vs_quadtree( clipmap.quadtree, step_down_start, step_down_end, &step_down_t, NULL ); + bool step_down_hit = segment_vs_terrain( clipmap.quadtree, step_down_start, step_down_end, &step_down_t, NULL ); game->pos = lerp( step_down_start, step_down_t, step_down_end ); game->on_ground = step_down_hit; @@ -731,7 +731,7 @@ GAME_FRAME( game_frame ) { v3 end = start + game->velocity * remaining_t; float t; v3 normal; - bool hit = segment_vs_quadtree( clipmap.quadtree, start, end, &t, &normal ); + bool hit = segment_vs_terrain( clipmap.quadtree, start, end, &t, &normal ); if( hit ) { // TODO: check normal is flat enough, otherwise stay in the air game->on_ground = true; @@ -950,7 +950,7 @@ GAME_FRAME( game_frame ) { float t; v3 normal; - if( segment_vs_quadtree( clipmap.quadtree, fireball->pos, end, &t, &normal ) ) { + if( segment_vs_terrain( clipmap.quadtree, fireball->pos, end, &t, &normal ) ) { Explosion * explosion = explosions.acquire(); explosion->pos = lerp( fireball->pos, t, end ); explosion->created_at = current_time; diff --git a/heightmap.cc b/heightmap.cc @@ -248,14 +248,19 @@ bool ray_vs_quadtree( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xno v3u32 maxs = v3u32( qt.heightmap.w, qt.heightmap.h, qt.nodes[ 0 ].max_z ); MinMaxu32 aabb( mins, maxs ); + return ray_vs_quadtree_node( qt, 0, aabb, ray, t, xnormal, max_dist ); +} + +bool ray_vs_terrain( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xnormal, float max_dist ) { float dont_care_t; v3 dont_care_normal; + if( t == NULL ) t = &dont_care_t; if( xnormal == NULL ) xnormal = &dont_care_normal; - bool hit_quadtree = ray_vs_quadtree_node( qt, 0, aabb, ray, t, xnormal, max_dist ); + bool hit_quadtree = ray_vs_quadtree( qt, ray, t, xnormal, max_dist ); if( hit_quadtree ) return true; @@ -263,7 +268,7 @@ bool ray_vs_quadtree( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xno return ray_vs_plane( ray.origin, ray.dir, *xnormal, 0, t ); } -bool segment_vs_quadtree( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ) { +bool segment_vs_terrain( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ) { if( t != NULL ) *t = 1.0f; @@ -274,7 +279,7 @@ bool segment_vs_quadtree( const QuadTree & qt, const v3 & start, const v3 & end, float l = length( end - start ); float absolute_t; - bool ok = ray_vs_quadtree( qt, ray, &absolute_t, xnormal, l ); + bool ok = ray_vs_terrain( qt, ray, &absolute_t, xnormal, l ); if( !ok || absolute_t >= l ) return false; diff --git a/heightmap.h b/heightmap.h @@ -21,6 +21,7 @@ u16 heightmap_height_u16( const array2d< u16 > hm, u32 x, u32 y ); v3 heightmap_point( const array2d< u16 > hm, u32 x, u32 y ); bool ray_vs_quadtree( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xnormal, float max_dist = FLT_MAX ); -bool segment_vs_quadtree( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ); +bool ray_vs_terrain( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xnormal, float max_dist = FLT_MAX ); +bool segment_vs_terrain( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ); void bc5_to_heightmap( MemoryArena * arena, array2d< u16 > hm, u8 * bc5 );