medfall

A super great game engine
Log | Files | Refs

commit 15db347c7e71f657c8dc3f660193e5f2bc6bb4be
parent 8d9917332526c3f791c64c5b4354f3d6689226d0
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun,  5 Nov 2017 09:48:28 +0200

Remove all the dodgy offsets

Diffstat:
clipmap.cc | 24++++++++++++------------
shaders/clipmap.glsl | 2+-
2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -191,7 +191,7 @@ GAME_INIT( game_init ) { clipmap.tile = renderer_new_mesh( mesh_config ); } - game->pos = v3( 0, 0, 100 ); + game->pos = v3( 2048, 2048, 100 ); game->pitch = 0; game->yaw = 45; game->sun_angle = 0.3f; @@ -211,8 +211,8 @@ static void draw_qt( MinMaxu32 aabb, const array< HeightmapQuadTreeNode > nodes, return; } - v3 mins = v3( aabb.mins.x, aabb.mins.y, aabb.mins.z / 256.0f ) - v3( 2048.0f, 2048.0f, 0 ); - v3 maxs = v3( aabb.maxs.x, aabb.maxs.y, aabb.maxs.z / 256.0f ) - v3( 2048.0f, 2048.0f, 0 ); + v3 mins = v3( aabb.mins.x, aabb.mins.y, aabb.mins.z / 256.0f ); + v3 maxs = v3( aabb.maxs.x, aabb.maxs.y, aabb.maxs.z / 256.0f ); immediate_aabb( mins, maxs, v4( 0, 0, 1, 1 ) ); for( size_t i = 0; i < 4; i++ ) { @@ -333,10 +333,10 @@ GAME_FRAME( game_frame ) { if( game->on_ground ) { const float step_height = 0.1f; - v3 low_start = game->pos + v3( 2048, 2048, 0 ); + v3 low_start = game->pos; v3 low_end = low_start + game->velocity * remaining_t; - v3 high_start = game->pos + v3( 2048, 2048, 0 ) + v3( 0, 0, step_height ); + v3 high_start = game->pos + v3( 0, 0, step_height ); v3 high_end = high_start + game->velocity * remaining_t; float low_t; @@ -359,7 +359,7 @@ GAME_FRAME( game_frame ) { if( high_t > low_t ) { if( high_hit ) { - game->pos = high_start + game->velocity * high_t * remaining_t - v3( 2048, 2048, 0 ); + game->pos = high_start + game->velocity * high_t * remaining_t; remaining_t = ( 1.0f - high_t ) * remaining_t; } else { @@ -371,7 +371,7 @@ GAME_FRAME( game_frame ) { } else { if( low_hit ) { - game->pos = low_start + game->velocity * low_t * remaining_t - v3( 2048, 2048, 0 ); + game->pos = low_start + game->velocity * low_t * remaining_t; remaining_t = ( 1.0f - low_t ) * remaining_t; } else { @@ -388,7 +388,7 @@ GAME_FRAME( game_frame ) { bool step_down_hit = segment_vs_quadtree( &clipmap.quadtree, step_down_start, step_down_end, &step_down_t, NULL ); - game->pos = lerp( step_down_start, step_down_t, step_down_end ) - v3( 2048, 2048, 0 ); + game->pos = lerp( step_down_start, step_down_t, step_down_end ); game->on_ground = step_down_hit; } } @@ -399,7 +399,7 @@ GAME_FRAME( game_frame ) { const float gravity = -30.0f; game->velocity += v3( 0, 0, gravity ) * remaining_t; - v3 start = game->pos + v3( 2048, 2048, 0 ); + v3 start = game->pos; v3 end = start + game->velocity * remaining_t; float t; v3 normal; @@ -414,7 +414,7 @@ GAME_FRAME( game_frame ) { remaining_t = ( 1.0f - t ) * remaining_t; } else { - game->pos = end - v3( 2048, 2048, 0 ); + game->pos = end; remaining_t = 0; } } @@ -474,7 +474,7 @@ GAME_FRAME( game_frame ) { { float t; v3 normal; - if( ray_vs_quadtree( &clipmap.quadtree, Ray3( game->pos + v3( 2048, 2048, 0 ), forward ), &t, &normal ) ) { + if( ray_vs_quadtree( &clipmap.quadtree, Ray3( game->pos, forward ), &t, &normal ) ) { v3 impact = game->pos + forward * t; immediate_arrow( impact, normal, 16, v4( 0, 1, 1, 1 ) ); } @@ -533,7 +533,7 @@ GAME_FRAME( game_frame ) { PROFILE_BLOCK( "Update fireballs" ); for( size_t i = 0; i < fireballs.elems.n; i++ ) { Fireball * fireball = &fireballs.elems[ i ]; - Ray3 ray( fireball->pos + v3( 2048.0f, 2048.0f, 0 ), fireball->velocity * dt ); + Ray3 ray( fireball->pos, fireball->velocity * dt ); float t; v3 normal; diff --git a/shaders/clipmap.glsl b/shaders/clipmap.glsl @@ -33,7 +33,7 @@ out VSOut v2f; void main() { vec2 xy = offset + position.xy * scale + camera_pos.xy; vec2 snapped_xy = floor( xy / scale ) * scale; - vec2 uv = snapped_xy / textureSize( heightmap, 0 ) + 0.5; + vec2 uv = snapped_xy / textureSize( heightmap, 0 ); float z = 256.0 * texture( heightmap, uv ).r + texture( heightmap, uv ).g; v2f.view_position = V * vec4( snapped_xy, z, 1.0 );