medfall

A super great game engine
Log | Files | Refs

commit ba92576d28dcd3ea95618146a94edea2238c9f28
parent c5e787c1e575530aea9437ea49bf5b128be44f71
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Jul  1 21:05:27 +0300

Fix collision detection

Diffstat:
heightmap.cc | 20++++++++++++--------
heightmap.h | 1+
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/heightmap.cc b/heightmap.cc @@ -35,13 +35,18 @@ void heightmap_destroy( Heightmap * hm ) { } v3 Heightmap::point( u32 x, u32 y ) const { - return v3( checked_cast< float >( x ), checked_cast< float >( y ), pixels[ y * width + x ] / 256.0f ); + float h = heightmap_height( this, x, y ); + return v3( checked_cast< float >( x ), checked_cast< float >( y ), h ); } float heightmap_height( const Heightmap * hm, u32 x, u32 y ) { + return heightmap_height_u16( hm, x, y ) / 256.0f; +} + +u16 heightmap_height_u16( const Heightmap * hm, u32 x, u32 y ) { ASSERT( x < hm->width ); ASSERT( y < hm->height ); - return hm->pixels[ y * hm->width + x ] / 256.0f; + return hm->pixels[ y * hm->width + x ]; } float Heightmap::bilerp_height( float x, float y ) const { @@ -186,11 +191,10 @@ static void heightmap_build_quadtree_node( HeightmapQuadTree * qt, size_t node_i if( aabb.maxs.x - aabb.mins.x == 1 || aabb.maxs.y - aabb.mins.y == 1 ) { u32 x = aabb.mins.x; u32 y = aabb.mins.y; - // TODO: this needs changing for 16bit heights - u16 a = heightmap_height( qt->hm, x, y ); - u16 b = heightmap_height( qt->hm, x + 1, y ); - u16 c = heightmap_height( qt->hm, x, y + 1 ); - u16 d = heightmap_height( qt->hm, x + 1, y + 1 ); + u16 a = heightmap_height_u16( qt->hm, x, y ); + u16 b = heightmap_height_u16( qt->hm, x + 1, y ); + u16 c = heightmap_height_u16( qt->hm, x, y + 1 ); + u16 d = heightmap_height_u16( qt->hm, x + 1, y + 1 ); qt->nodes[ node_idx ].min_z = min( a, b, c, d ); qt->nodes[ node_idx ].max_z = max( a, b, c, d ); @@ -225,7 +229,7 @@ HeightmapQuadTree heightmap_build_quadtree( const Heightmap * hm, array< Heightm qt.nodes = nodes; memset( qt.nodes.ptr(), 0, qt.nodes.num_bytes() ); - AABBu32 aabb( v3u32( 0, 0, 0 ), v3u32( qt.dim, qt.dim, 255 ) ); + AABBu32 aabb( v3u32( 0, 0, 0 ), v3u32( qt.dim, qt.dim, U16_MAX ) ); heightmap_build_quadtree_node( &qt, 0, aabb ); return qt; diff --git a/heightmap.h b/heightmap.h @@ -22,6 +22,7 @@ struct OffsetHeightmap { void heightmap_init( Heightmap * hm, u16 * pixels, u32 width, u32 height ); float heightmap_height( const Heightmap * hm, u32 x, u32 y ); +u16 heightmap_height_u16( const Heightmap * hm, u32 x, u32 y ); void heightmap_destroy( Heightmap * hm ); struct HeightmapQuadTreeNode {