diff --git a/src/gameui/CGWorldFrame.cpp b/src/gameui/CGWorldFrame.cpp index d6968d0..0bac82d 100644 --- a/src/gameui/CGWorldFrame.cpp +++ b/src/gameui/CGWorldFrame.cpp @@ -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 #include @@ -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; +} diff --git a/src/gameui/CGWorldFrame.hpp b/src/gameui/CGWorldFrame.hpp index a77f21d..a7e34d2 100644 --- a/src/gameui/CGWorldFrame.hpp +++ b/src/gameui/CGWorldFrame.hpp @@ -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; diff --git a/src/gameui/camera/CGCamera.cpp b/src/gameui/camera/CGCamera.cpp new file mode 100644 index 0000000..78981a1 --- /dev/null +++ b/src/gameui/camera/CGCamera.cpp @@ -0,0 +1 @@ +#include "gameui/camera/CGCamera.hpp" diff --git a/src/gameui/camera/CGCamera.hpp b/src/gameui/camera/CGCamera.hpp new file mode 100644 index 0000000..a3ec361 --- /dev/null +++ b/src/gameui/camera/CGCamera.hpp @@ -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 diff --git a/src/gameui/camera/CSimpleCamera.cpp b/src/gameui/camera/CSimpleCamera.cpp index f041435..c3e146d 100644 --- a/src/gameui/camera/CSimpleCamera.cpp +++ b/src/gameui/camera/CSimpleCamera.cpp @@ -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); } diff --git a/src/gameui/camera/CSimpleCamera.hpp b/src/gameui/camera/CSimpleCamera.hpp index be0f59c..dcd5561 100644 --- a/src/gameui/camera/CSimpleCamera.hpp +++ b/src/gameui/camera/CSimpleCamera.hpp @@ -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); diff --git a/src/world/CWorld.cpp b/src/world/CWorld.cpp index c4f7d93..dad8abc 100644 --- a/src/world/CWorld.cpp +++ b/src/world/CWorld.cpp @@ -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(); } diff --git a/src/world/daynight/DNStars.cpp b/src/world/daynight/DNStars.cpp index 841a4a9..25e8391 100644 --- a/src/world/daynight/DNStars.cpp +++ b/src/world/daynight/DNStars.cpp @@ -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(); }