feat(gameui): add CGCamera and workaround to control it

This commit is contained in:
VDm 2025-07-27 19:09:15 +04:00
parent 5be5ba35b9
commit 45ceb6354b
8 changed files with 84 additions and 20 deletions

View File

@ -6,7 +6,8 @@
#include "gx/Device.hpp"
#include "gx/RenderState.hpp"
#include "world/CWorld.hpp"
#include "gameui/camera/CSimpleCamera.hpp"
#include "gameui/camera/CGCamera.hpp"
#include "event/EvtKeyDown.hpp"
#include <bc/Memory.hpp>
#include <tempest/Matrix.hpp>
@ -17,7 +18,14 @@ CGWorldFrame* CGWorldFrame::s_currentWorldFrame = nullptr;
CGWorldFrame::CGWorldFrame(CSimpleFrame* parent) : CSimpleFrame(parent) {
// TODO
this->m_camera = NEW(CGCamera);
s_currentWorldFrame = this;
this->EnableEvent(SIMPLE_EVENT_KEY, -1);
this->EnableEvent(SIMPLE_EVENT_MOUSE, -1);
this->EnableEvent(SIMPLE_EVENT_MOUSEWHEEL, -1);
}
void CGWorldFrame::OnFrameRender(CRenderBatch* batch, uint32_t layer) {
@ -27,6 +35,42 @@ void CGWorldFrame::OnFrameRender(CRenderBatch* batch, uint32_t layer) {
}
}
int32_t CGWorldFrame::OnLayerKeyDown(const CKeyEvent& evt) {
if (CSimpleFrame::OnLayerKeyDown(evt)) {
return 1;
}
// WORKAROUND: Camera testing
C3Vector& position = this->m_camera->m_position;
float step = 0.1f;
switch (evt.key) {
case KEY_W:
position.z -= step;
break;
case KEY_A:
position.y -= step;
break;
case KEY_S:
position.z += step;
break;
case KEY_D:
position.y += step;
break;
case KEY_PLUS:
position.x += step;
break;
case KEY_MINUS:
position.x -= step;
break;
default:
break;
}
return 0;
}
CSimpleFrame* CGWorldFrame::Create(CSimpleFrame* parent) {
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGWorldFrame@@", -2);
@ -87,3 +131,9 @@ void CGWorldFrame::OnWorldRender() {
GxRsPop();
}
CGCamera* CGWorldFrame::GetActiveCamera() {
STORM_ASSERT(CGWorldFrame::s_currentWorldFrame);
STORM_ASSERT(CGWorldFrame::s_currentWorldFrame->m_camera);
return CGWorldFrame::s_currentWorldFrame->m_camera;
}

View File

@ -4,16 +4,22 @@
#include "ui/CSimpleFrame.hpp"
#include "ui/CSimpleTop.hpp"
class CGCamera;
class CGWorldFrame : public CSimpleFrame {
public:
CGWorldFrame(CSimpleFrame* parent);
virtual void OnFrameRender(CRenderBatch* batch, uint32_t layer);
virtual int32_t OnLayerKeyDown(const CKeyEvent& evt);
static CSimpleFrame* Create(CSimpleFrame* parent);
static void RenderWorld(void* param);
static void OnWorldUpdate();
static void OnWorldRender();
static CGCamera* GetActiveCamera();
CGCamera* m_camera = nullptr;
public:
static CGWorldFrame* s_currentWorldFrame;

View File

@ -0,0 +1 @@
#include "gameui/camera/CGCamera.hpp"

View File

@ -0,0 +1,10 @@
#ifndef GAME_UI_CAMERA_CGCAMERA_HPP
#define GAME_UI_CAMERA_CGCAMERA_HPP
#include "gameui/camera/CSimpleCamera.hpp"
class CGCamera : public CSimpleCamera {
};
#endif // GAME_UI_CAMERA_CGCAMERA_HPP

View File

@ -149,9 +149,9 @@ void CSimpleCamera::SetGxProjectionAndView(const CRect& projectionRect) {
GxXformProjection(mProj);
GxuXformCreateProjection_SG(this->m_fov, this->m_aspect, this->m_nearZ, this->m_farZ, mProj);
//GxXformSetProjection(mProj);
GxXformSetProjection(mProj);
C44Matrix mView;
GxuXformCreateLookAtSgCompat(C3Vector(), Forward(), Up(), mView);
GxuXformCreateLookAtSgCompat(this->m_position, this->m_position + Forward(), Up(), mView);
GxXformSetView(mView);
}

View File

@ -12,27 +12,27 @@ class CSimpleCamera {
CSimpleCamera(float nearZ, float farZ, float fov);
virtual ~CSimpleCamera();
C3Vector& Position() { this->m_position; };
C33Matrix& Facing() { this->m_facing; };
float NearZ() { this->m_nearZ; };
float FarZ() { this->m_farZ; };
float FOV() { this->m_fov; };
float Aspect() { this->m_aspect; };
C3Vector& Position() { this->m_position; }
C33Matrix& Facing() { this->m_facing; }
float NearZ() { this->m_nearZ; }
float FarZ() { this->m_farZ; }
float FOV() { this->m_fov; }
float Aspect() { this->m_aspect; }
virtual C3Vector Forward();
virtual C3Vector Right();
virtual C3Vector Up();
void SetPosition(const C3Vector& position) { this->m_position = position; };
void SetPosition(float x, float y, float z) { this->m_position = C3Vector(x, y, z); };
void SetPosition(const C3Vector& position) { this->m_position = position; }
void SetPosition(float x, float y, float z) { this->m_position = C3Vector(x, y, z); }
void SetFacing(float yaw, float pitch, float roll);
void SetFacing(const C3Vector& forward, const C3Vector& up);
void SetFacing(const C3Vector& forward);
void SetFieldOfView(float value) { this->m_fov = value; };
void SetNearZ(float value) { this->m_nearZ = value; };
void SetFarZ(float value) { this->m_farZ = value; };
void SetFieldOfView(float value) { this->m_fov = value; }
void SetNearZ(float value) { this->m_nearZ = value; }
void SetFarZ(float value) { this->m_farZ = value; }
void SetGxProjectionAndView(const CRect& projectionRect);

View File

@ -6,7 +6,7 @@
#include "world/World.hpp"
#include "world/map/CMap.hpp"
#include "world/daynight/DayNight.hpp"
#include "gameui/camera/CSimpleCamera.hpp"
#include "gameui/camera/CGCamera.hpp"
#include "gameui/CGWorldFrame.hpp"
uint32_t CWorld::s_enables;
@ -55,12 +55,9 @@ void CWorld::LoadMap(const char* mapName, const C3Vector& position, int32_t zone
void CWorld::Render() {
GxRsPush();
CSimpleCamera camera;
camera.SetPosition(s_newPosition);
camera.SetFacing(s_newFacing, 0.0f, 0.0f);
CRect rect;
CGWorldFrame::s_currentWorldFrame->GetRect(&rect);
camera.SetGxProjectionAndView(rect);
CGWorldFrame::GetActiveCamera()->SetGxProjectionAndView(rect);
DayNight::RenderSky();
GxRsPop();
}

View File

@ -6,7 +6,7 @@ namespace DayNight {
void DNStars::Initialize() {
this->m_scene = M2CreateScene();
this->m_model = this->m_scene->CreateModel("Spells\\ErrorCube.mdx" /* "Environments\\Stars\\stars.mdl" */, 0);
this->m_model = this->m_scene->CreateModel("Environments\\Stars\\stars.mdl", 0);
this->m_time = OsGetAsyncTimeMs();
}