Makes GameView::GetCamera constant
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled

This commit is contained in:
Vladislav Belov 2026-06-28 17:57:26 +02:00
parent e0d131854d
commit 0538e95793
No known key found for this signature in database
GPG key ID: 353545E45DB9CCB3
9 changed files with 88 additions and 48 deletions

View file

@ -191,11 +191,16 @@ CObjectManager& CGameView::GetObjectManager()
return m->ObjectManager; return m->ObjectManager;
} }
CCamera& CGameView::GetCamera() const CCamera& CGameView::GetCamera() const
{ {
return m->ViewCamera; return m->ViewCamera;
} }
void CGameView::SetCamera(const CCamera& camera)
{
m->ViewCamera = camera;
}
CCinemaManager* CGameView::GetCinema() CCinemaManager* CGameView::GetCinema()
{ {
return &m->CinemaManager; return &m->CinemaManager;

View file

@ -78,7 +78,9 @@ public:
#undef DECLARE_BOOLEAN_SETTING #undef DECLARE_BOOLEAN_SETTING
CCamera& GetCamera(); const CCamera& GetCamera() const;
void SetCamera(const CCamera& camera);
CCinemaManager* GetCinema(); CCinemaManager* GetCinema();
CObjectManager& GetObjectManager(); CObjectManager& GetObjectManager();

View file

@ -867,10 +867,12 @@ void CXMLReader::ReadCamera(XMBElement parent)
if (m_MapReader.pGameView) if (m_MapReader.pGameView)
{ {
m_MapReader.pGameView->GetCamera().m_Orientation.SetXRotation(declination); CCamera camera{m_MapReader.pGameView->GetCamera()};
m_MapReader.pGameView->GetCamera().m_Orientation.RotateY(rotation); camera.m_Orientation.SetXRotation(declination);
m_MapReader.pGameView->GetCamera().m_Orientation.Translate(translation); camera.m_Orientation.RotateY(rotation);
m_MapReader.pGameView->GetCamera().UpdateFrustum(); camera.m_Orientation.Translate(translation);
camera.UpdateFrustum();
m_MapReader.pGameView->SetCamera(camera);
} }
} }
@ -1631,10 +1633,12 @@ int CMapReader::ParseCamera()
if (pGameView) if (pGameView)
{ {
pGameView->GetCamera().m_Orientation.SetXRotation(declination); CCamera camera{pGameView->GetCamera()};
pGameView->GetCamera().m_Orientation.RotateY(rotation); camera.m_Orientation.SetXRotation(declination);
pGameView->GetCamera().m_Orientation.Translate(translation); camera.m_Orientation.RotateY(rotation);
pGameView->GetCamera().UpdateFrustum(); camera.m_Orientation.Translate(translation);
camera.UpdateFrustum();
pGameView->SetCamera(camera);
} }
return 0; return 0;

View file

@ -141,11 +141,12 @@ void CTouchInput::OnFingerMotion(int id, int x, int y)
if (m_State == STATE_PANNING && id == 0) if (m_State == STATE_PANNING && id == 0)
{ {
CCamera& camera{g_Game->GetView()->GetCamera()}; CCamera camera{g_Game->GetView()->GetCamera()};
auto [origin, dir] = camera.BuildCameraRay(x, y); auto [origin, dir] = camera.BuildCameraRay(x, y);
dir *= m_PanDist / dir.Y; dir *= m_PanDist / dir.Y;
camera.GetOrientation().Translate(m_PanFocus - dir - origin); camera.GetOrientation().Translate(m_PanFocus - dir - origin);
camera.UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
} }
if (m_State == STATE_ZOOMING && id == 1) if (m_State == STATE_ZOOMING && id == 1)
@ -154,11 +155,12 @@ void CTouchInput::OnFingerMotion(int id, int x, int y)
float newDist = (m_Pos[id] - m_Pos[1 - id]).Length(); float newDist = (m_Pos[id] - m_Pos[1 - id]).Length();
float zoomDist = (newDist - oldDist) * -0.005f * m_PanDist; float zoomDist = (newDist - oldDist) * -0.005f * m_PanDist;
CCamera& camera{g_Game->GetView()->GetCamera()}; CCamera camera{g_Game->GetView()->GetCamera()};
CVector3D dir{camera.BuildCameraRay(m_Pos[0].X, m_Pos[0].Y).direction}; CVector3D dir{camera.BuildCameraRay(m_Pos[0].X, m_Pos[0].Y).direction};
dir *= zoomDist; dir *= zoomDist;
camera.GetOrientation().Translate(dir); camera.GetOrientation().Translate(dir);
camera.UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
m_PanFocus = camera.GetWorldCoordinates(m_Pos[0].X, m_Pos[0].Y, true); m_PanFocus = camera.GetWorldCoordinates(m_Pos[0].X, m_Pos[0].Y, true);
m_PanDist = (m_PanFocus - camera.GetOrientation().GetTranslation()).Y; m_PanDist = (m_PanFocus - camera.GetOrientation().GetTranslation()).Y;

View file

@ -887,7 +887,9 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent)
oldCamera.GetFOV(), aspectRatio, oldCamera.GetNearPlane(), oldCamera.GetFarPlane(), oldCamera.GetFOV(), aspectRatio, oldCamera.GetNearPlane(), oldCamera.GetFarPlane(),
tiles, tileX, tileY); tiles, tileX, tileY);
} }
g_Game->GetView()->GetCamera().SetProjection(projection); CCamera camera{g_Game->GetView()->GetCamera()};
camera.SetProjection(projection);
g_Game->GetView()->SetCamera(camera);
Renderer::Backend::ISwapChain* swapChain{g_VideoMode.GetOrCreateSwapChain()}; Renderer::Backend::ISwapChain* swapChain{g_VideoMode.GetOrCreateSwapChain()};
if (!swapChain || !swapChain->IsValid()) if (!swapChain || !swapChain->IsValid())
@ -919,7 +921,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent)
g_Renderer.Resize(g_xres, g_yres); g_Renderer.Resize(g_xres, g_yres);
SViewPort vp = { 0, 0, g_xres, g_yres }; SViewPort vp = { 0, 0, g_xres, g_yres };
g_Game->GetView()->SetViewport(vp); g_Game->GetView()->SetViewport(vp);
g_Game->GetView()->GetCamera().SetProjectionFromCamera(oldCamera); g_Game->GetView()->SetCamera(oldCamera);
} }
if (tex_write(&t, filename) == INFO::OK) if (tex_write(&t, filename) == INFO::OK)

View file

@ -95,14 +95,14 @@ MESSAGEHANDLER(Scroll)
static CVector3D targetPos; static CVector3D targetPos;
static float targetDistance = 0.f; static float targetDistance = 0.f;
CMatrix3D& camera = g_Game->GetView()->GetCamera().m_Orientation; CCamera camera{g_Game->GetView()->GetCamera()};
static CVector3D lastCameraPos = camera.GetTranslation(); static CVector3D lastCameraPos{camera.m_Orientation.GetTranslation()};
// Ensure roughly correct motion when dragging is combined with other // Ensure roughly correct motion when dragging is combined with other
// movements. // movements.
if (lastCameraPos != camera.GetTranslation()) if (lastCameraPos != camera.m_Orientation.GetTranslation())
targetPos += camera.GetTranslation() - lastCameraPos; targetPos += camera.m_Orientation.GetTranslation() - lastCameraPos;
// General operation: // General operation:
// //
@ -118,7 +118,7 @@ MESSAGEHANDLER(Scroll)
if (msg->type == eScrollType::FROM) if (msg->type == eScrollType::FROM)
{ {
targetPos = msg->pos->GetWorldSpace(); targetPos = msg->pos->GetWorldSpace();
targetDistance = (targetPos - camera.GetTranslation()).Length(); targetDistance = (targetPos - camera.m_Orientation.GetTranslation()).Length();
} }
else if (msg->type == eScrollType::TO) else if (msg->type == eScrollType::TO)
{ {
@ -126,14 +126,15 @@ MESSAGEHANDLER(Scroll)
msg->pos->GetScreenSpace(x, y); msg->pos->GetScreenSpace(x, y);
auto [origin, dir] = g_Game->GetView()->GetCamera().BuildCameraRay((int)x, (int)y); auto [origin, dir] = g_Game->GetView()->GetCamera().BuildCameraRay((int)x, (int)y);
dir *= targetDistance; dir *= targetDistance;
camera.Translate(targetPos - dir - origin); camera.m_Orientation.Translate(targetPos - dir - origin);
g_Game->GetView()->GetCamera().UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
} }
else else
{ {
debug_warn(L"Scroll: Invalid type"); debug_warn(L"Scroll: Invalid type");
} }
lastCameraPos = camera.GetTranslation(); lastCameraPos = camera.m_Orientation.GetTranslation();
} }
MESSAGEHANDLER(SmoothZoom) MESSAGEHANDLER(SmoothZoom)
@ -152,7 +153,7 @@ MESSAGEHANDLER(RotateAround)
static CVector3D focusPos; static CVector3D focusPos;
static float lastX = 0.f, lastY = 0.f; static float lastX = 0.f, lastY = 0.f;
CMatrix3D& camera = g_Game->GetView()->GetCamera().m_Orientation; CCamera camera{g_Game->GetView()->GetCamera()};
if (msg->type == eRotateAroundType::FROM) if (msg->type == eRotateAroundType::FROM)
{ {
@ -169,24 +170,25 @@ MESSAGEHANDLER(RotateAround)
float rotY = 6.f * (x-lastX) / g_Renderer.GetWidth(); float rotY = 6.f * (x-lastX) / g_Renderer.GetWidth();
CQuaternion q0, q1; CQuaternion q0, q1;
q0.FromAxisAngle(camera.GetLeft(), -rotX); q0.FromAxisAngle(camera.m_Orientation.GetLeft(), -rotX);
q1.FromAxisAngle(CVector3D(0.f, 1.f, 0.f), rotY); q1.FromAxisAngle(CVector3D(0.f, 1.f, 0.f), rotY);
CQuaternion q = q0*q1; CQuaternion q = q0*q1;
CVector3D origin = camera.GetTranslation(); CVector3D origin = camera.m_Orientation.GetTranslation();
CVector3D offset = q.Rotate(origin - focusPos); CVector3D offset = q.Rotate(origin - focusPos);
q *= camera.GetRotation(); q *= camera.m_Orientation.GetRotation();
q.Normalize(); // to avoid things blowing up when turning upside-down, for some reason I don't understand q.Normalize(); // to avoid things blowing up when turning upside-down, for some reason I don't understand
q.ToMatrix(camera); q.ToMatrix(camera.m_Orientation);
// Make sure up is still pointing up, regardless of any rounding errors. // Make sure up is still pointing up, regardless of any rounding errors.
// (Maybe this distorts the camera in other ways, but at least the errors // (Maybe this distorts the camera in other ways, but at least the errors
// are far less noticeable to me.) // are far less noticeable to me.)
camera._21 = 0.f; // (_21 = Y component returned by GetLeft()) camera.m_Orientation._21 = 0.f; // (_21 = Y component returned by GetLeft())
camera.Translate(focusPos + offset); camera.m_Orientation.Translate(focusPos + offset);
g_Game->GetView()->GetCamera().UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
lastX = x; lastX = x;
lastY = y; lastY = y;
@ -200,7 +202,7 @@ MESSAGEHANDLER(RotateAround)
MESSAGEHANDLER(LookAt) MESSAGEHANDLER(LookAt)
{ {
// TODO: different camera depending on msg->view // TODO: different camera depending on msg->view
CCamera& camera = AtlasView::GetView_Actor()->GetCamera(); CCamera camera{AtlasView::GetView_Actor()->GetCamera()};
CVector3D tgt = msg->target->GetWorldSpace(); CVector3D tgt = msg->target->GetWorldSpace();
CVector3D eye = msg->pos->GetWorldSpace(); CVector3D eye = msg->pos->GetWorldSpace();
@ -225,6 +227,8 @@ MESSAGEHANDLER(LookAt)
camera.m_Orientation.Translate(-eye); camera.m_Orientation.Translate(-eye);
camera.UpdateFrustum(); camera.UpdateFrustum();
AtlasView::GetView_Actor()->SetCamera(camera);
} }
QUERYHANDLER(GetView) QUERYHANDLER(GetView)
@ -272,9 +276,9 @@ MESSAGEHANDLER(ToggleBirdsEyeView)
static float declination{0.f}; static float declination{0.f};
CCamera& camera = AtlasView::GetView_Game()->GetCamera(); CCamera camera{AtlasView::GetView_Game()->GetCamera()};
CMatrix3D& orientation = camera.GetOrientation(); CMatrix3D& orientation{camera.GetOrientation()};
CVector3D focus = camera.GetFocus(); const CVector3D focus{camera.GetFocus()};
if (!g_BirdEyeView) if (!g_BirdEyeView)
{ {
@ -298,6 +302,7 @@ MESSAGEHANDLER(ToggleBirdsEyeView)
orientation.Translate(focus + offset); orientation.Translate(focus + offset);
camera.UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
g_BirdEyeView = !g_BirdEyeView; g_BirdEyeView = !g_BirdEyeView;
} }

View file

@ -52,11 +52,10 @@ bool InputProcessor::ProcessInput(GameLoopState* state)
if (! g_Game) if (! g_Game)
return false; return false;
CCamera& camera{g_Game->GetView()->GetCamera()}; CCamera camera{g_Game->GetView()->GetCamera()};
CVector3D leftwards = camera.m_Orientation.GetLeft(); const CVector3D leftwards{camera.m_Orientation.GetLeft()};
const CVector3D inwards{camera.m_Orientation.GetIn()};
CVector3D inwards = camera.m_Orientation.GetIn();
// Calculate a vector pointing forwards, parallel to the ground // Calculate a vector pointing forwards, parallel to the ground
CVector3D forwards = inwards; CVector3D forwards = inwards;
@ -119,7 +118,10 @@ bool InputProcessor::ProcessInput(GameLoopState* state)
} }
if (moved) if (moved)
{
camera.UpdateFrustum(); camera.UpdateFrustum();
g_Game->GetView()->SetCamera(camera);
}
return moved; return moved;
} }

View file

@ -94,20 +94,26 @@ void AtlasViewActor::Update(float realFrameLength)
void AtlasViewActor::Render() void AtlasViewActor::Render()
{ {
SViewPort vp = { 0, 0, g_xres, g_yres }; SViewPort vp = { 0, 0, g_xres, g_yres };
CCamera& camera = GetCamera(); CCamera camera{GetCamera()};
camera.SetViewPort(vp); camera.SetViewPort(vp);
camera.SetPerspectiveProjection(2.f, 512.f, DEGTORAD(20.f)); camera.SetPerspectiveProjection(2.f, 512.f, DEGTORAD(20.f));
camera.UpdateFrustum(); camera.UpdateFrustum();
SetCamera(camera);
m_ActorViewer->Render(); m_ActorViewer->Render();
Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas); Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas);
} }
CCamera& AtlasViewActor::GetCamera() const CCamera& AtlasViewActor::GetCamera() const
{ {
return m_Camera; return m_Camera;
} }
void AtlasViewActor::SetCamera(const CCamera& camera)
{
m_Camera = camera;
}
CSimulation2* AtlasViewActor::GetSimulation2() CSimulation2* AtlasViewActor::GetSimulation2()
{ {
return m_ActorViewer->GetSimulation2(); return m_ActorViewer->GetSimulation2();
@ -229,7 +235,9 @@ void AtlasViewGame::Update(float realFrameLength)
// Cinematic motion should be independent of simulation update, so we can // Cinematic motion should be independent of simulation update, so we can
// preview the cinematics by themselves // preview the cinematics by themselves
g_Game->GetView()->GetCinema()->Update(realFrameLength, g_Game->GetView()->GetCamera()); CCamera camera{g_Game->GetView()->GetCamera()};
g_Game->GetView()->GetCinema()->Update(realFrameLength, camera);
g_Game->GetView()->SetCamera(camera);
} }
void AtlasViewGame::Render() void AtlasViewGame::Render()
@ -239,10 +247,11 @@ void AtlasViewGame::Render()
return; return;
SViewPort vp = { 0, 0, g_xres, g_yres }; SViewPort vp = { 0, 0, g_xres, g_yres };
CCamera& camera = GetCamera(); CCamera camera{GetCamera()};
camera.SetViewPort(vp); camera.SetViewPort(vp);
camera.SetProjectionFromCamera(g_Game->GetView()->GetCamera()); camera.SetProjectionFromCamera(g_Game->GetView()->GetCamera());
camera.UpdateFrustum(); camera.UpdateFrustum();
SetCamera(camera);
g_Renderer.RenderFrame(false); g_Renderer.RenderFrame(false);
Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas); Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas);
@ -335,11 +344,16 @@ void AtlasViewGame::SetParam(const std::wstring& name, const std::wstring& value
} }
} }
CCamera& AtlasViewGame::GetCamera() const CCamera& AtlasViewGame::GetCamera() const
{ {
return g_Game->GetView()->GetCamera(); return g_Game->GetView()->GetCamera();
} }
void AtlasViewGame::SetCamera(const CCamera& camera)
{
g_Game->GetView()->SetCamera(camera);
}
bool AtlasViewGame::GetSmoothFramerate() const bool AtlasViewGame::GetSmoothFramerate() const
{ {
if (g_Game->GetView()->GetCinema()->IsPlaying()) if (g_Game->GetView()->GetCinema()->IsPlaying())

View file

@ -46,7 +46,8 @@ public:
virtual void Render() { }; virtual void Render() { };
virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext&) { }; virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext&) { };
virtual void DrawOverlays(CCanvas2D& /*canvas*/) { }; virtual void DrawOverlays(CCanvas2D& /*canvas*/) { };
virtual CCamera& GetCamera() = 0; virtual const CCamera& GetCamera() const = 0;
virtual void SetCamera(const CCamera& camera) = 0;
virtual CSimulation2* GetSimulation2() { return NULL; } virtual CSimulation2* GetSimulation2() { return NULL; }
virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj) { return (entity_id_t)obj; } virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj) { return (entity_id_t)obj; }
virtual bool GetSmoothFramerate() const { return false; } virtual bool GetSmoothFramerate() const { return false; }
@ -74,9 +75,10 @@ public:
class AtlasViewNone : public AtlasView class AtlasViewNone : public AtlasView
{ {
public: public:
virtual CCamera& GetCamera() { return dummyCamera; } virtual const CCamera& GetCamera() const { return m_DummyCamera; }
virtual void SetCamera(const CCamera& camera) { m_DummyCamera = camera; }
private: private:
CCamera dummyCamera; CCamera m_DummyCamera;
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -95,7 +97,8 @@ public:
virtual void Render(); virtual void Render();
virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext& deviceCommandContext); virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext& deviceCommandContext);
virtual void DrawOverlays(CCanvas2D& canvas); virtual void DrawOverlays(CCanvas2D& canvas);
virtual CCamera& GetCamera(); virtual const CCamera& GetCamera() const;
virtual void SetCamera(const CCamera& camera);
virtual CSimulation2* GetSimulation2(); virtual CSimulation2* GetSimulation2();
virtual bool GetSmoothFramerate() const; virtual bool GetSmoothFramerate() const;
virtual void SetSmoothFramerate(const bool enabled); virtual void SetSmoothFramerate(const bool enabled);
@ -139,7 +142,8 @@ public:
virtual void Update(float realFrameLength); virtual void Update(float realFrameLength);
virtual void Render(); virtual void Render();
virtual CCamera& GetCamera(); virtual const CCamera& GetCamera() const;
virtual void SetCamera(const CCamera& camera);
virtual CSimulation2* GetSimulation2(); virtual CSimulation2* GetSimulation2();
virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj); virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj);
virtual bool GetSmoothFramerate() const; virtual bool GetSmoothFramerate() const;