fp: Add camera smoothing movement

This commit is contained in:
doyle 2023-10-17 23:49:20 +11:00
parent 46bf26a7c3
commit 0044b05130
2 changed files with 16 additions and 12 deletions

View File

@ -1995,8 +1995,8 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
if (entity->flags & FP_GameEntityFlag_CameraTracking) {
FP_GameCamera *camera = &game->play.camera;
camera->world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) * camera->scale;
FP_GameCamera *camera = &game->play.camera;
camera->world_pos_target = FP_Game_CalcEntityWorldPos(game, entity->handle) * camera->scale;
}
FP_GamePlaceableBuilding placeable_building = PLACEABLE_BUILDINGS[game->play.build_mode_building_index];
@ -2290,11 +2290,12 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
}
// NOTE: Camera ================================================================================
FP_GamePlay *play = &game->play;
FP_GameCamera *camera = &play->camera;
if (!FP_Game_IsNilEntityHandle(game, game->play.clicked_entity)) {
Dqn_V2 window_size = Dqn_V2_InitV2I(platform->core.window_size);
FP_GamePlay *play = &game->play;
FP_GameCamera *camera = &play->camera;
camera->scale = window_size / camera->size;
Dqn_V2 camera_size_screen = camera->size * camera->scale;
@ -2302,12 +2303,13 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
Dqn_V2 map_screen_size = map_world_size * camera->scale;
Dqn_V2 half_map_screen_size = map_screen_size * .5f;
camera->world_pos.x = DQN_MIN(camera->world_pos.x, half_map_screen_size.w - (camera_size_screen.w * .5f));
camera->world_pos.x = DQN_MAX(camera->world_pos.x, -half_map_screen_size.w + (camera_size_screen.w * .5f));
camera->world_pos.y = DQN_MAX(camera->world_pos.y, -half_map_screen_size.h + (camera_size_screen.h * .5f));
camera->world_pos.y = DQN_MIN(camera->world_pos.y, half_map_screen_size.h - (camera_size_screen.h * .5f));
camera->world_pos_target.x = DQN_MIN(camera->world_pos_target.x, half_map_screen_size.w - (camera_size_screen.w * .5f));
camera->world_pos_target.x = DQN_MAX(camera->world_pos_target.x, -half_map_screen_size.w + (camera_size_screen.w * .5f));
camera->world_pos_target.y = DQN_MAX(camera->world_pos_target.y, -half_map_screen_size.h + (camera_size_screen.h * .5f));
camera->world_pos_target.y = DQN_MIN(camera->world_pos_target.y, half_map_screen_size.h - (camera_size_screen.h * .5f));
}
camera->world_pos += (camera->world_pos_target - camera->world_pos) * (5.f * DQN_CAST(Dqn_f32)input->delta_s);
Dqn_Profiler_EndZone(update_zone);
}
@ -3600,8 +3602,8 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer,
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " F9 %s god mode", game->play.god_mode ? "Disable" : "Enable"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " F10 %s noclip", player->flags & FP_GameEntityFlag_NoClip ? "Disable" : "Enable"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " F11 Building inventory +1"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " F12 %s by enemies", player->faction == FP_GameEntityFaction_Nil ? "Attacked" : "Ignored"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " 1 %s HUD", game->play.debug_hide_hud ? "Show" : "Hide"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, " 2 %s by enemies", player->faction == FP_GameEntityFaction_Nil ? "Attacked" : "Ignored"); draw_p.y += TELY_Render_FontHeight(renderer, assets);
TELY_Render_PopFont(renderer);
TELY_Render_PopColourV4(renderer);
@ -3656,14 +3658,15 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer,
player->inventory.kennels += 1;
}
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F12)) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_1))
game->play.debug_hide_hud = !game->play.debug_hide_hud;
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_2)) {
player->faction = player->faction == FP_GameEntityFaction_Nil
? FP_GameEntityFaction_Friendly
: FP_GameEntityFaction_Nil;
}
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_1))
game->play.debug_hide_hud = !game->play.debug_hide_hud;
}
}

View File

@ -257,6 +257,7 @@ struct FP_GameCamera
{
Dqn_V2 size;
Dqn_V2 world_pos;
Dqn_V2 world_pos_target;
Dqn_f32 rotate_rads;
Dqn_V2 scale;
};