unsmooth editor camera panning
This commit is contained in:
parent
3d7f6eddfe
commit
d84e12d598
@ -669,8 +669,8 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
frame->edit_camera_zoom *= PowF32(zoom_rate, -last_frame->zooms);
|
frame->edit_camera_zoom *= PowF32(zoom_rate, -last_frame->zooms);
|
||||||
frame->edit_camera_zoom = ClampF32(frame->edit_camera_zoom, min_zoom, max_zoom);
|
frame->edit_camera_zoom = ClampF32(frame->edit_camera_zoom, min_zoom, max_zoom);
|
||||||
// Offset edit camera based on cursor if panning / zooming
|
// Offset edit camera based on cursor if panning / zooming
|
||||||
b32 is_zooming = last_frame->zooms != 0 && (frame->edit_camera_zoom != last_frame->edit_camera_zoom);
|
b32 should_zoom = last_frame->zooms != 0 && (frame->edit_camera_zoom != last_frame->edit_camera_zoom);
|
||||||
if (last_frame->is_editing && (is_zooming || (frame->is_panning && last_frame->is_panning)))
|
if (last_frame->is_editing && (should_zoom || (frame->is_panning && last_frame->is_panning)))
|
||||||
{
|
{
|
||||||
Xform last_frame_edit_to_ui_xf = Zi;
|
Xform last_frame_edit_to_ui_xf = Zi;
|
||||||
Xform edit_to_ui_xf = Zi;
|
Xform edit_to_ui_xf = Zi;
|
||||||
@ -710,17 +710,33 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
|
|
||||||
// Create world <-> ui xforms
|
// Create world <-> ui xforms
|
||||||
{
|
{
|
||||||
f32 lerp_ratio = 15.0 * frame->dt;
|
|
||||||
if (last_frame->tick == 0)
|
if (last_frame->tick == 0)
|
||||||
{
|
{
|
||||||
lerp_ratio = 1;
|
frame->camera_lerp_ratio = 1;
|
||||||
}
|
}
|
||||||
else if (frame->is_editing)
|
else if (frame->is_editing)
|
||||||
{
|
{
|
||||||
lerp_ratio = 30.0 * frame->dt;
|
b32 is_zooming = AbsF32(target_camera_zoom - last_frame->camera_zoom) > 0.001;
|
||||||
|
if (frame->is_panning && !is_zooming)
|
||||||
|
{
|
||||||
|
// When panning & not zooming, we want camera interpolation to be
|
||||||
|
// instant (no smoothing). However, the transition to non
|
||||||
|
// interpolation must be smooth.
|
||||||
|
frame->camera_lerp_ratio += last_frame->camera_lerp_ratio + (5 * frame->dt);
|
||||||
|
frame->camera_lerp_ratio = MinF32(frame->camera_lerp_ratio, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
frame->camera_lerp_ratio = 30.0 * frame->dt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
frame->camera_pos = LerpVec2(last_frame->camera_pos, target_camera_pos, lerp_ratio);
|
else
|
||||||
frame->camera_zoom = LerpF32(last_frame->camera_zoom, target_camera_zoom, lerp_ratio);
|
{
|
||||||
|
frame->camera_lerp_ratio = 15.0 * frame->dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
frame->camera_pos = LerpVec2(last_frame->camera_pos, target_camera_pos, frame->camera_lerp_ratio);
|
||||||
|
frame->camera_zoom = LerpF32(last_frame->camera_zoom, target_camera_zoom, frame->camera_lerp_ratio);
|
||||||
{
|
{
|
||||||
f32 camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->camera_zoom);
|
f32 camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->camera_zoom);
|
||||||
frame->world_to_ui_xf = XformFromScale(VEC2(camera_scale, camera_scale));
|
frame->world_to_ui_xf = XformFromScale(VEC2(camera_scale, camera_scale));
|
||||||
@ -1513,15 +1529,14 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
{
|
{
|
||||||
S_Cmd *cmd = V_PushSimCmd(S_CmdKind_Spawn);
|
S_Cmd *cmd = V_PushSimCmd(S_CmdKind_Spawn);
|
||||||
S_Ent *ent = &cmd->ent;
|
S_Ent *ent = &cmd->ent;
|
||||||
|
*ent = *S_EntFromKey(&V.lookup, V.player_key);
|
||||||
ent->key = V.player_key;
|
ent->key = V.player_key;
|
||||||
ent->move_speed = 0.1;
|
ent->move_speed = 0.1;
|
||||||
{
|
ent->local_shape = S_ShapeFromDesc(
|
||||||
ent->local_shape = S_ShapeFromDesc(
|
.mass = 10,
|
||||||
.mass = 10,
|
.count = 1,
|
||||||
.count = 1,
|
.radius = 0.3,
|
||||||
.radius = 0.3,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
ent->xf = XformFromPos(frame->world_cursor);
|
ent->xf = XformFromPos(frame->world_cursor);
|
||||||
ent->has_weapon = 1;
|
ent->has_weapon = 1;
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@ -234,6 +234,7 @@ Struct(V_Frame)
|
|||||||
f32 edit_camera_zoom;
|
f32 edit_camera_zoom;
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
|
f32 camera_lerp_ratio;
|
||||||
Vec2 camera_pos;
|
Vec2 camera_pos;
|
||||||
f32 camera_zoom;
|
f32 camera_zoom;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user