fp: Get camera fix

This commit is contained in:
doyle 2023-10-01 14:38:31 +11:00
parent e5282f7706
commit f258886d68
3 changed files with 13 additions and 5 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit cc7ef01f28ee6a09f7811c58480e9a94a1667d42 Subproject commit d58010b431d3ed7ee0076f3195f1d2a8ccc4a220

View File

@ -1424,7 +1424,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
Dqn_Profiler_ZoneScopeWithIndex("FP_Render", FP_ProfileZone_FPRender); Dqn_Profiler_ZoneScopeWithIndex("FP_Render", FP_ProfileZone_FPRender);
TELY_PlatformInput *input = &platform->input; TELY_PlatformInput *input = &platform->input;
Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform); Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform);
Dqn_V2 world_mouse_p = Dqn_M2x3_MulV2(model_view, input->mouse_p); Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos;
// NOTE: Draw tiles ============================================================================ // NOTE: Draw tiles ============================================================================
Dqn_usize tile_count_x = DQN_CAST(Dqn_usize)(platform->core.window_size.w / game->tile_size); Dqn_usize tile_count_x = DQN_CAST(Dqn_usize)(platform->core.window_size.w / game->tile_size);
@ -1670,7 +1670,7 @@ void TELY_DLL_FrameUpdate(void *user_data)
Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform); Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform);
TELY_Render_PushTransform(renderer, model_view); TELY_Render_PushTransform(renderer, model_view);
Dqn_V2 world_mouse_p = Dqn_M2x3_MulV2(model_view, input->mouse_p); Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos;
// ============================================================================================= // =============================================================================================

View File

@ -23,15 +23,23 @@ static bool operator!=(FP_GameEntityHandle const &lhs, FP_GameEntityHandle const
return result; return result;
} }
// TODO(doyle): Use this
struct FP_GameCameraM2x3
{
Dqn_M2x3 model_view;
Dqn_M2x3 view_model;
};
static Dqn_M2x3 FP_Game_CameraModelViewM2x3(FP_GameCamera camera, TELY_Platform *platform) static Dqn_M2x3 FP_Game_CameraModelViewM2x3(FP_GameCamera camera, TELY_Platform *platform)
{ {
Dqn_M2x3 result = Dqn_M2x3_Identity(); Dqn_M2x3 result = Dqn_M2x3_Identity();
if (platform) { if (platform) {
Dqn_V2 rotate_origin = camera.world_pos - (Dqn_V2_InitV2I(platform->core.window_size) * .5f); Dqn_V2 center_offset = Dqn_V2_InitV2I(platform->core.window_size) * .5f;
Dqn_V2 rotate_origin = -camera.world_pos - center_offset;
result = Dqn_M2x3_Mul(result, Dqn_M2x3_Translate(rotate_origin)); result = Dqn_M2x3_Mul(result, Dqn_M2x3_Translate(rotate_origin));
result = Dqn_M2x3_Mul(result, Dqn_M2x3_Rotate(camera.rotate_rads)); result = Dqn_M2x3_Mul(result, Dqn_M2x3_Rotate(camera.rotate_rads));
result = Dqn_M2x3_Mul(result, Dqn_M2x3_Scale(camera.scale)); result = Dqn_M2x3_Mul(result, Dqn_M2x3_Scale(camera.scale));
result = Dqn_M2x3_Mul(result, Dqn_M2x3_Translate(-rotate_origin + camera.world_pos)); result = Dqn_M2x3_Mul(result, Dqn_M2x3_Translate(center_offset));
} }
return result; return result;
} }