mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(gameui): add CGCamera and workaround to control it
This commit is contained in:
parent
5be5ba35b9
commit
45ceb6354b
8 changed files with 84 additions and 20 deletions
|
|
@ -6,7 +6,8 @@
|
||||||
#include "gx/Device.hpp"
|
#include "gx/Device.hpp"
|
||||||
#include "gx/RenderState.hpp"
|
#include "gx/RenderState.hpp"
|
||||||
#include "world/CWorld.hpp"
|
#include "world/CWorld.hpp"
|
||||||
#include "gameui/camera/CSimpleCamera.hpp"
|
#include "gameui/camera/CGCamera.hpp"
|
||||||
|
#include "event/EvtKeyDown.hpp"
|
||||||
|
|
||||||
#include <bc/Memory.hpp>
|
#include <bc/Memory.hpp>
|
||||||
#include <tempest/Matrix.hpp>
|
#include <tempest/Matrix.hpp>
|
||||||
|
|
@ -17,7 +18,14 @@ CGWorldFrame* CGWorldFrame::s_currentWorldFrame = nullptr;
|
||||||
|
|
||||||
CGWorldFrame::CGWorldFrame(CSimpleFrame* parent) : CSimpleFrame(parent) {
|
CGWorldFrame::CGWorldFrame(CSimpleFrame* parent) : CSimpleFrame(parent) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
this->m_camera = NEW(CGCamera);
|
||||||
|
|
||||||
s_currentWorldFrame = this;
|
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) {
|
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) {
|
CSimpleFrame* CGWorldFrame::Create(CSimpleFrame* parent) {
|
||||||
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGWorldFrame@@", -2);
|
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGWorldFrame@@", -2);
|
||||||
|
|
||||||
|
|
@ -87,3 +131,9 @@ void CGWorldFrame::OnWorldRender() {
|
||||||
|
|
||||||
GxRsPop();
|
GxRsPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGCamera* CGWorldFrame::GetActiveCamera() {
|
||||||
|
STORM_ASSERT(CGWorldFrame::s_currentWorldFrame);
|
||||||
|
STORM_ASSERT(CGWorldFrame::s_currentWorldFrame->m_camera);
|
||||||
|
return CGWorldFrame::s_currentWorldFrame->m_camera;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,22 @@
|
||||||
#include "ui/CSimpleFrame.hpp"
|
#include "ui/CSimpleFrame.hpp"
|
||||||
#include "ui/CSimpleTop.hpp"
|
#include "ui/CSimpleTop.hpp"
|
||||||
|
|
||||||
|
class CGCamera;
|
||||||
|
|
||||||
class CGWorldFrame : public CSimpleFrame {
|
class CGWorldFrame : public CSimpleFrame {
|
||||||
public:
|
public:
|
||||||
CGWorldFrame(CSimpleFrame* parent);
|
CGWorldFrame(CSimpleFrame* parent);
|
||||||
|
|
||||||
virtual void OnFrameRender(CRenderBatch* batch, uint32_t layer);
|
virtual void OnFrameRender(CRenderBatch* batch, uint32_t layer);
|
||||||
|
virtual int32_t OnLayerKeyDown(const CKeyEvent& evt);
|
||||||
|
|
||||||
static CSimpleFrame* Create(CSimpleFrame* parent);
|
static CSimpleFrame* Create(CSimpleFrame* parent);
|
||||||
static void RenderWorld(void* param);
|
static void RenderWorld(void* param);
|
||||||
static void OnWorldUpdate();
|
static void OnWorldUpdate();
|
||||||
static void OnWorldRender();
|
static void OnWorldRender();
|
||||||
|
static CGCamera* GetActiveCamera();
|
||||||
|
|
||||||
|
CGCamera* m_camera = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CGWorldFrame* s_currentWorldFrame;
|
static CGWorldFrame* s_currentWorldFrame;
|
||||||
|
|
|
||||||
1
src/gameui/camera/CGCamera.cpp
Normal file
1
src/gameui/camera/CGCamera.cpp
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
#include "gameui/camera/CGCamera.hpp"
|
||||||
10
src/gameui/camera/CGCamera.hpp
Normal file
10
src/gameui/camera/CGCamera.hpp
Normal 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
|
||||||
|
|
@ -149,9 +149,9 @@ void CSimpleCamera::SetGxProjectionAndView(const CRect& projectionRect) {
|
||||||
GxXformProjection(mProj);
|
GxXformProjection(mProj);
|
||||||
|
|
||||||
GxuXformCreateProjection_SG(this->m_fov, this->m_aspect, this->m_nearZ, this->m_farZ, mProj);
|
GxuXformCreateProjection_SG(this->m_fov, this->m_aspect, this->m_nearZ, this->m_farZ, mProj);
|
||||||
//GxXformSetProjection(mProj);
|
GxXformSetProjection(mProj);
|
||||||
|
|
||||||
C44Matrix mView;
|
C44Matrix mView;
|
||||||
GxuXformCreateLookAtSgCompat(C3Vector(), Forward(), Up(), mView);
|
GxuXformCreateLookAtSgCompat(this->m_position, this->m_position + Forward(), Up(), mView);
|
||||||
GxXformSetView(mView);
|
GxXformSetView(mView);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,27 +12,27 @@ class CSimpleCamera {
|
||||||
CSimpleCamera(float nearZ, float farZ, float fov);
|
CSimpleCamera(float nearZ, float farZ, float fov);
|
||||||
virtual ~CSimpleCamera();
|
virtual ~CSimpleCamera();
|
||||||
|
|
||||||
C3Vector& Position() { this->m_position; };
|
C3Vector& Position() { this->m_position; }
|
||||||
C33Matrix& Facing() { this->m_facing; };
|
C33Matrix& Facing() { this->m_facing; }
|
||||||
float NearZ() { this->m_nearZ; };
|
float NearZ() { this->m_nearZ; }
|
||||||
float FarZ() { this->m_farZ; };
|
float FarZ() { this->m_farZ; }
|
||||||
float FOV() { this->m_fov; };
|
float FOV() { this->m_fov; }
|
||||||
float Aspect() { this->m_aspect; };
|
float Aspect() { this->m_aspect; }
|
||||||
|
|
||||||
virtual C3Vector Forward();
|
virtual C3Vector Forward();
|
||||||
virtual C3Vector Right();
|
virtual C3Vector Right();
|
||||||
virtual C3Vector Up();
|
virtual C3Vector Up();
|
||||||
|
|
||||||
void SetPosition(const C3Vector& position) { this->m_position = position; };
|
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(float x, float y, float z) { this->m_position = C3Vector(x, y, z); }
|
||||||
|
|
||||||
void SetFacing(float yaw, float pitch, float roll);
|
void SetFacing(float yaw, float pitch, float roll);
|
||||||
void SetFacing(const C3Vector& forward, const C3Vector& up);
|
void SetFacing(const C3Vector& forward, const C3Vector& up);
|
||||||
void SetFacing(const C3Vector& forward);
|
void SetFacing(const C3Vector& forward);
|
||||||
|
|
||||||
void SetFieldOfView(float value) { this->m_fov = value; };
|
void SetFieldOfView(float value) { this->m_fov = value; }
|
||||||
void SetNearZ(float value) { this->m_nearZ = value; };
|
void SetNearZ(float value) { this->m_nearZ = value; }
|
||||||
void SetFarZ(float value) { this->m_farZ = value; };
|
void SetFarZ(float value) { this->m_farZ = value; }
|
||||||
|
|
||||||
void SetGxProjectionAndView(const CRect& projectionRect);
|
void SetGxProjectionAndView(const CRect& projectionRect);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
#include "world/map/CMap.hpp"
|
#include "world/map/CMap.hpp"
|
||||||
#include "world/daynight/DayNight.hpp"
|
#include "world/daynight/DayNight.hpp"
|
||||||
#include "gameui/camera/CSimpleCamera.hpp"
|
#include "gameui/camera/CGCamera.hpp"
|
||||||
#include "gameui/CGWorldFrame.hpp"
|
#include "gameui/CGWorldFrame.hpp"
|
||||||
|
|
||||||
uint32_t CWorld::s_enables;
|
uint32_t CWorld::s_enables;
|
||||||
|
|
@ -55,12 +55,9 @@ void CWorld::LoadMap(const char* mapName, const C3Vector& position, int32_t zone
|
||||||
|
|
||||||
void CWorld::Render() {
|
void CWorld::Render() {
|
||||||
GxRsPush();
|
GxRsPush();
|
||||||
CSimpleCamera camera;
|
|
||||||
camera.SetPosition(s_newPosition);
|
|
||||||
camera.SetFacing(s_newFacing, 0.0f, 0.0f);
|
|
||||||
CRect rect;
|
CRect rect;
|
||||||
CGWorldFrame::s_currentWorldFrame->GetRect(&rect);
|
CGWorldFrame::s_currentWorldFrame->GetRect(&rect);
|
||||||
camera.SetGxProjectionAndView(rect);
|
CGWorldFrame::GetActiveCamera()->SetGxProjectionAndView(rect);
|
||||||
DayNight::RenderSky();
|
DayNight::RenderSky();
|
||||||
GxRsPop();
|
GxRsPop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace DayNight {
|
||||||
|
|
||||||
void DNStars::Initialize() {
|
void DNStars::Initialize() {
|
||||||
this->m_scene = M2CreateScene();
|
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();
|
this->m_time = OsGetAsyncTimeMs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue