From 4628b7d831b694d8fedf9673f0c58c5795a120bd Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 17 Feb 2026 07:02:15 -0600 Subject: [PATCH] feat(ui): add CSimpleCamera::SetGxProjectionAndView --- src/ui/simple/CSimpleCamera.cpp | 20 ++++++++++++++++++++ src/ui/simple/CSimpleCamera.hpp | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/ui/simple/CSimpleCamera.cpp b/src/ui/simple/CSimpleCamera.cpp index 0164145..8a35c2f 100644 --- a/src/ui/simple/CSimpleCamera.cpp +++ b/src/ui/simple/CSimpleCamera.cpp @@ -1,4 +1,5 @@ #include "ui/simple/CSimpleCamera.hpp" +#include "gx/Transform.hpp" #include "model/Model2.hpp" #include @@ -107,6 +108,25 @@ void CSimpleCamera::SetNearZ(float nearZ) { this->m_nearZ = nearZ; } +void CSimpleCamera::SetGxProjectionAndView(const CRect& projRect) { + // Projection + + this->m_aspect = (projRect.maxX - projRect.minX) / (projRect.maxY - projRect.minY); + + C44Matrix projMat; + GxuXformCreateProjection_Exact(this->m_fov * 0.6f, this->m_aspect, this->m_nearZ, this->m_farZ, projMat); + + GxXformSetProjection(projMat); + + // View + + C3Vector eye; + C44Matrix viewMat; + GxuXformCreateLookAtSgCompat(eye, this->Forward(), this->Up(), viewMat); + + GxXformSetView(viewMat); +} + C3Vector CSimpleCamera::Up() const { return { this->m_facing.c0, this->m_facing.c1, this->m_facing.c2 }; } diff --git a/src/ui/simple/CSimpleCamera.hpp b/src/ui/simple/CSimpleCamera.hpp index 2f2fdda..e39cea6 100644 --- a/src/ui/simple/CSimpleCamera.hpp +++ b/src/ui/simple/CSimpleCamera.hpp @@ -2,6 +2,7 @@ #define UI_SIMPLE_C_SIMPLE_CAMERA_HPP #include +#include #include class CM2Scene; @@ -22,6 +23,7 @@ class CSimpleCamera { void SetFacing(float yaw, float pitch, float roll); void SetFarZ(float farZ); void SetFieldOfView(float fov); + void SetGxProjectionAndView(const CRect& projRect); void SetNearZ(float nearZ); protected: