commit 413437934d5a32dca7dcf34b41c22a2819868c6b parent 8220f91135fdf3fc9aa69c2c7ebb5271ef79cdff Author: Michael Savage <mikejsavage@gmail.com> Date: Mon Nov 7 22:58:00 +0200 m4 in mod_btt Diffstat:
mod_btt.cc | | | 25 | +++++++++---------------- |
diff --git a/mod_btt.cc b/mod_btt.cc @@ -124,8 +124,6 @@ static glm::vec3 angles_to_vector_xy( const glm::vec3 & angles ) { // } // } -static const glm::mat4 P( glm::perspective( glm::radians( 120.0f ), ( float ) WIDTH / ( float ) HEIGHT, NEAR_PLANE_DEPTH, FAR_PLANE_DEPTH ) ); - static float * horizons; static UB ub_fs, ub_vs; @@ -189,6 +187,12 @@ extern "C" GAME_INIT( game_init ) { skybox_init( &game->skybox ); } +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; +} + struct FSData { v2 dimensions; float sun; @@ -218,18 +222,7 @@ extern "C" GAME_FRAME( game_frame ) { game->pos += sideways * speed * dt * ( float ) lr; game->pos.z += dz * 50.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 ); FSData fs_data = { }; fs_data.dimensions = v2( game->hm.width, game->hm.height ); @@ -252,7 +245,7 @@ extern "C" GAME_FRAME( game_frame ) { immediate_arrow( &imm, origin, direction, 2, white ); } glUseProgram( game->test_outline_shader ); - glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, glm::value_ptr( VP ) ); + glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, ( float * ) &VP ); immediate_render( &imm, game->test_outline_at_position, game->test_outline_at_colour ); glUseProgram( 0 ); @@ -262,7 +255,7 @@ extern "C" GAME_FRAME( game_frame ) { // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // glUseProgram( game->test_outline_shader ); - // glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, glm::value_ptr( VP ) ); + // glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, ( float * ) &VP ); // immediate_render( &imm, game->test_outline_at_position, game->test_outline_at_colour ); // glUseProgram( 0 ); // glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );