Skip to content

Commit

Permalink
Configurable cockpit camera smoothing
Browse files Browse the repository at this point in the history
- Allow the user to enable/disable smoothing by changing a config setting. Not exposed to the UI yet.
  • Loading branch information
sturnclaw committed Jan 27, 2023
1 parent 598231e commit 657e967
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ship/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ InternalCameraController::InternalCameraController(RefCountedPtr<CameraContext>
m_origFov(camera->GetFovAng()),
m_zoomPct(1),
m_zoomPctTo(1),
m_viewOrient(matrix3x3d::Identity())
m_viewOrient(matrix3x3d::Identity()),
m_smoothing(false)
{
Reset();
}
Expand Down Expand Up @@ -106,8 +107,13 @@ void InternalCameraController::Reset()

void InternalCameraController::Update()
{
AnimationCurves::Approach(m_rotX, m_rotToX, Pi::GetFrameTime(), 15.f);
AnimationCurves::Approach(m_rotY, m_rotToY, Pi::GetFrameTime(), 15.f);
if (m_smoothing) {
AnimationCurves::Approach(m_rotX, m_rotToX, Pi::GetFrameTime(), 13.f);
AnimationCurves::Approach(m_rotY, m_rotToY, Pi::GetFrameTime(), 13.f);
} else {
m_rotX = m_rotToX;
m_rotY = m_rotToY;
}

m_viewOrient =
matrix3x3d::RotateY(-m_rotY) *
Expand All @@ -126,6 +132,11 @@ void InternalCameraController::getRots(double &rX, double &rY)
rY = m_rotY;
}

void InternalCameraController::SetSmoothingEnabled(bool enabled)
{
m_smoothing = enabled;
}

void InternalCameraController::SetMode(Mode m)
{
if (m >= MODE_MAX) return;
Expand Down
5 changes: 5 additions & 0 deletions src/ship/CameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class InternalCameraController : public MoveableCameraController {
Type GetType() const override { return INTERNAL; }
const char *GetName() const override { return m_name; }

void SetSmoothingEnabled(bool enabled);
bool GetSmoothingEnabled() const { return m_smoothing; }

void SetMode(Mode m);
Mode GetMode() const { return m_mode; }

Expand Down Expand Up @@ -134,6 +137,8 @@ class InternalCameraController : public MoveableCameraController {
float m_zoomPct;
float m_zoomPctTo;
matrix3x3d m_viewOrient;

bool m_smoothing;
};

// Zoomable, rotatable orbit camera, always looks at the ship
Expand Down
4 changes: 4 additions & 0 deletions src/ship/ShipViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void ShipViewController::Init()
m_flybyCameraController.reset(new FlyByCameraController(m_cameraContext, Pi::player));
SetCamType(m_camType); //set the active camera

// setup camera smoothing
// TODO: expose this via UI once setting/updating config values from Lua is nicer
m_internalCameraController->SetSmoothingEnabled(Pi::config->Int("CameraSmoothing", 0));

std::string headtrackingIP = Pi::config->String("HeadtrackingIP", "");
int port = Pi::config->Int("HeadtrackingPort", 4242);

Expand Down

0 comments on commit 657e967

Please sign in to comment.