medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 8220f91135fdf3fc9aa69c2c7ebb5271ef79cdff
parent 0e4ee1a441fa49cbc54b8d3ceb87d8263ad980e8
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon Nov  7 22:55:45 +0200

m4 in bsp.cc/hm.cc

Diffstat:
bsp.cc | 21+++++++--------------
hm.cc | 22+++++++---------------
2 files changed, 14 insertions(+), 29 deletions(-)
diff --git a/bsp.cc b/bsp.cc @@ -319,8 +319,6 @@ glm::vec3 angles_to_vector( const glm::vec3 & angles ) { ); } -static const glm::mat4 P( glm::perspective( glm::radians( 120.0f ), 640.0f / 480.0f, 0.1f, 10000.0f ) ); - static UB test_ub; static Shader texture_shader; @@ -348,6 +346,12 @@ extern "C" GAME_INIT( game_init ) { test_ub = renderer_new_ub(); } +static m4 camera_to_vp( glm::vec3 position, glm::vec3 angles ) { + const m4 P = m4_perspective( 120.0f, ( float ) WIDTH / ( float ) HEIGHT, NEAR_PLANE_DEPTH, 10000.0f ); + + return m4_translation( -GLMV3( position ) ) * m4_rotz( -angles.y ) * m4_rotx( -angles.x ) * P; +} + extern "C" GAME_FRAME( game_frame ) { const int fb = input->keys[ 'w' ] - input->keys[ 's' ]; const int lr = input->keys[ 'a' ] - input->keys[ 'd' ]; @@ -364,18 +368,7 @@ extern "C" GAME_FRAME( game_frame ) { const glm::vec3 sideways = glm::vec3( -cosf( game->angles.y ), sinf( game->angles.y ), 0 ); game->pos += sideways * 100.0f * dt * ( float ) lr; game->pos.z += ( float ) dz * 100.0f * dt; - const glm::mat4 VP = glm::translate( - glm::rotate( - glm::rotate( - P, - game->angles.x, - glm::vec3( 1, 0, 0 ) - ), - game->angles.y, - glm::vec3( 0, 0, 1 ) - ), - -game->pos - ); + m4 VP = camera_to_vp( game->pos, game->angles ); renderer_begin_frame(); renderer_ub_data( test_ub, &VP, sizeof( VP ) ); diff --git a/hm.cc b/hm.cc @@ -106,8 +106,6 @@ static glm::vec3 angles_to_vector_xy( const glm::vec3 & angles ) { return glm::vec3( sin( angles.y ), cos( angles.y ), 0 ); } -static glm::mat4 P( glm::perspective( glm::radians( 120.0f ), 640.0f / 480.0f, 0.1f, 10000.0f ) ); - static WORK_QUEUE_CALLBACK( testwq ) { u32 i = *( u32 * ) data; printf( "work %u called with arena %p\n", i, arena->memory ); @@ -245,6 +243,10 @@ static void draw_string( const GameState * game, glBindTexture( GL_TEXTURE_2D, 0 ); } +static m4 camera_to_view( glm::vec3 position, glm::vec3 angles ) { + return m4_translation( -GLMV3( position ) ) * m4_rotz( -angles.y ) * m4_rotx( -angles.x ); +} + extern "C" GAME_FRAME( game_frame ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); @@ -272,19 +274,9 @@ extern "C" GAME_FRAME( game_frame ) { terrain_update( &game->tm, game->pos ); - const glm::mat4 V = glm::translate( - glm::rotate( - glm::rotate( - glm::mat4(), - game->angles.x, - glm::vec3( 1, 0, 0 ) - ), - game->angles.y, - glm::vec3( 0, 0, 1 ) - ), - -game->pos - ); - const glm::mat4 VP = P * V; + m4 P = m4_perspective( 120.0f, ( float ) WIDTH / ( float ) HEIGHT, NEAR_PLANE_DEPTH, 10000.0f ); + m4 V = camera_to_view( game->pos, game->angles ); + m4 VP = V * P; // TODO: WTF terrain_render( &game->tm, V, VP, game->test_sun, current_time ); skybox_render( &game->skybox, game->angles );