From: hgn Date: Mon, 30 Jan 2023 08:14:06 +0000 (+0000) Subject: automatic camera inversing across portals X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;ds=sidebyside;h=2f1dca88d325b4eebd030232c694627f5791ebce;p=carveJwlIkooP6JGAAIwe30JlM.git automatic camera inversing across portals --- diff --git a/player_device_skate.h b/player_device_skate.h index 566bead..13f6398 100644 --- a/player_device_skate.h +++ b/player_device_skate.h @@ -1199,6 +1199,8 @@ VG_STATIC void player_skate_update( player_interface *player, m4x3_mulv( gate->transport, s->state.cog, s->state.cog ); m3x3_mulv( gate->transport, s->state.cog_v, s->state.cog_v ); m3x3_mulv( gate->transport, s->state.throw_v, s->state.throw_v ); + m4x3_mulv( gate->transport, s->state.posl, s->state.posl ); + m3x3_mulv( gate->transport, s->state.vl, s->state.vl ); #if 0 mixedcam_transport( &s->state.cam, gate ); diff --git a/player_interface.h b/player_interface.h index e0830c1..93c699e 100644 --- a/player_interface.h +++ b/player_interface.h @@ -40,14 +40,9 @@ struct player_interface k_camera_mode_thirdperson } camera_mode; - float camera_type_blend; - /* TODO: have an automated system for crossing the thirdperson camera - * across portal boundaries. if it fails the check with the gate plane, then - * transform root_co and root_q, as well as final camera, BACK across the - * division, using the inverse of the transport matrix - */ + teleport_gate *gate_waiting; int device_blend; float device_blend_time; @@ -296,7 +291,7 @@ VG_STATIC void player_apply_transport_to_cam( m4x3f transport ) PLAYER_DEVICE_API void player_pass_gate( player_interface *player, teleport_gate *gate ) { - + player->gate_waiting = gate; } VG_STATIC void player_post_update( player_interface *player ) @@ -357,6 +352,37 @@ VG_STATIC void player_pre_render( player_interface *player ) float t = player->camera_type_blend; camera_lerp( &player->dev.cam_1st, &player->dev.cam_3rd, t, &player->cam ); + if( player->gate_waiting ) + { + /* construct plane equation for reciever gate */ + v4f plane; + v3_copy( player->gate_waiting->recv_to_world[2], plane ); + plane[3] = v3_dot( plane, player->gate_waiting->recv_to_world[3] ); + + /* check camera polarity */ + if( v3_dot( player->cam.pos, plane ) < plane[3] ) + { + vg_success( "Plane cleared\n" ); + player_apply_transport_to_cam( player->gate_waiting->transport ); + player->gate_waiting = NULL; + } + else + { + /* de-transform camera and player back */ + m4x3f inverse; + m4x3_invert_affine( player->gate_waiting->transport, inverse ); + m4x3_mulv( inverse, player->cam.pos, player->cam.pos ); + + /* TODO: Find robust method for this */ + v3f fwd_dir = { cosf(player->cam.angles[0]), + 0.0f, + sinf(player->cam.angles[0])}; + m3x3_mulv( inverse, fwd_dir, fwd_dir ); + player->cam.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] ); + + skeleton_apply_transform( sk, inverse ); + } + } #if 0 v3_copy( player->dev.cam_1st.pos, player->cam.pos );