feat(ui): add CSimpleCamera::SetGxProjectionAndView

This commit is contained in:
fallenoak 2026-02-17 07:02:15 -06:00
parent 7d491570e4
commit 4628b7d831
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "ui/simple/CSimpleCamera.hpp" #include "ui/simple/CSimpleCamera.hpp"
#include "gx/Transform.hpp"
#include "model/Model2.hpp" #include "model/Model2.hpp"
#include <tempest/Math.hpp> #include <tempest/Math.hpp>
@ -107,6 +108,25 @@ void CSimpleCamera::SetNearZ(float nearZ) {
this->m_nearZ = 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 { C3Vector CSimpleCamera::Up() const {
return { this->m_facing.c0, this->m_facing.c1, this->m_facing.c2 }; return { this->m_facing.c0, this->m_facing.c1, this->m_facing.c2 };
} }

View File

@ -2,6 +2,7 @@
#define UI_SIMPLE_C_SIMPLE_CAMERA_HPP #define UI_SIMPLE_C_SIMPLE_CAMERA_HPP
#include <tempest/Matrix.hpp> #include <tempest/Matrix.hpp>
#include <tempest/Rect.hpp>
#include <tempest/Vector.hpp> #include <tempest/Vector.hpp>
class CM2Scene; class CM2Scene;
@ -22,6 +23,7 @@ class CSimpleCamera {
void SetFacing(float yaw, float pitch, float roll); void SetFacing(float yaw, float pitch, float roll);
void SetFarZ(float farZ); void SetFarZ(float farZ);
void SetFieldOfView(float fov); void SetFieldOfView(float fov);
void SetGxProjectionAndView(const CRect& projRect);
void SetNearZ(float nearZ); void SetNearZ(float nearZ);
protected: protected: