Skip to content

Commit

Permalink
avoid abrupt camera movements in fps camera
Browse files Browse the repository at this point in the history
fixes #18
  • Loading branch information
malytomas committed Oct 19, 2022
1 parent e7a37fc commit e52d492
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sources/libsimple/fpsCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace cage
VariableSmoothingBuffer<Real, 2> wheelSmoother;
Vec2 mouseMoveAccum;
Real wheelAccum;
Real currentScaling = 1;

Entity *ent = nullptr;
bool keysPressedArrows[6] = {}; // wsadeq
Expand All @@ -40,7 +41,7 @@ namespace cage
updateListener.attach(controlThread().update);
}

const Vec2i centerMouse()
Vec2i centerMouse()
{
auto w = engineWindow();
Vec2i pt2 = w->resolution();
Expand All @@ -66,8 +67,9 @@ namespace cage
{
if (!mouseEnabled(in.buttons))
return false;
Vec2i pt2 = centerMouse();
mouseMoveAccum += Vec2(pt2 - in.position);
const Vec2 pt2 = Vec2(centerMouse() - in.position);
if (length(pt2) < 150 * currentScaling)
mouseMoveAccum += pt2;
return false;
}

Expand Down Expand Up @@ -141,6 +143,7 @@ namespace cage
{
if (!ent)
return;
currentScaling = engineWindow()->contentScaling();
TransformComponent &t = ent->value<TransformComponent>();

// orientation
Expand Down

0 comments on commit e52d492

Please sign in to comment.