Compare commits

..

5 Commits

Author SHA1 Message Date
Alex Tiernan-Berry
4d30d108b0
Merge 0573235a70 into b3c07f0607 2026-02-17 13:29:22 +00:00
fallenoak
b3c07f0607
fix(ui): const correctness for CSimpleCamera::FOV 2026-02-17 07:15:14 -06:00
fallenoak
6bcaec1fe7
fix(ui): use FOV getter in CSimpleCamera::SetGxProjectionAndView 2026-02-17 07:06:31 -06:00
fallenoak
4628b7d831
feat(ui): add CSimpleCamera::SetGxProjectionAndView 2026-02-17 07:02:15 -06:00
fallenoak
7d491570e4
feat(ui): add CSimpleCamera::GetScene
Some checks failed
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Has been cancelled
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Has been cancelled
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Has been cancelled
2026-02-15 21:02:06 -06:00
2 changed files with 38 additions and 4 deletions

View File

@ -1,4 +1,6 @@
#include "ui/simple/CSimpleCamera.hpp" #include "ui/simple/CSimpleCamera.hpp"
#include "gx/Transform.hpp"
#include "model/Model2.hpp"
#include <tempest/Math.hpp> #include <tempest/Math.hpp>
namespace { namespace {
@ -52,7 +54,7 @@ void BuildBillboardMatrix(const C3Vector& direction, C33Matrix& rotation) {
} }
CSimpleCamera::CSimpleCamera(float nearZ, float farZ, float fov) { CSimpleCamera::CSimpleCamera(float nearZ, float farZ, float fov) {
this->float10 = 0.0f; this->m_scene = nullptr;
this->m_nearZ = nearZ; this->m_nearZ = nearZ;
this->m_farZ = farZ; this->m_farZ = farZ;
@ -62,7 +64,7 @@ CSimpleCamera::CSimpleCamera(float nearZ, float farZ, float fov) {
this->SetFacing(0.0f, 0.0f, 0.0f); this->SetFacing(0.0f, 0.0f, 0.0f);
} }
float CSimpleCamera::FOV() { float CSimpleCamera::FOV() const {
return this->m_fov; return this->m_fov;
} }
@ -70,6 +72,14 @@ C3Vector CSimpleCamera::Forward() const {
return { this->m_facing.a0, this->m_facing.a1, this->m_facing.a2 }; return { this->m_facing.a0, this->m_facing.a1, this->m_facing.a2 };
} }
CM2Scene* CSimpleCamera::GetScene() {
if (!this->m_scene) {
this->m_scene = M2CreateScene();
}
return this->m_scene;
}
C3Vector CSimpleCamera::Right() const { C3Vector CSimpleCamera::Right() const {
return { this->m_facing.b0, this->m_facing.b1, this->m_facing.b2 }; return { this->m_facing.b0, this->m_facing.b1, this->m_facing.b2 };
} }
@ -98,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->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,29 +2,34 @@
#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 CSimpleCamera { class CSimpleCamera {
public: public:
// Virtual public member functions // Virtual public member functions
virtual float FOV(); virtual float FOV() const;
virtual C3Vector Forward() const; virtual C3Vector Forward() const;
virtual C3Vector Right() const; virtual C3Vector Right() const;
virtual C3Vector Up() const; virtual C3Vector Up() const;
// Public member functions // Public member functions
CSimpleCamera(float nearZ, float farZ, float fov); CSimpleCamera(float nearZ, float farZ, float fov);
CM2Scene* GetScene();
void SetFacing(const C3Vector& forward); void SetFacing(const C3Vector& forward);
void SetFacing(const C3Vector& forward, const C3Vector& up); void SetFacing(const C3Vector& forward, const C3Vector& up);
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:
// Protected member variables // Protected member variables
CM2Scene* m_scene;
C3Vector m_position; C3Vector m_position;
float float10;
C33Matrix m_facing; C33Matrix m_facing;
float m_nearZ; float m_nearZ;
float m_farZ; float m_farZ;