mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-26 05:46:04 +03:00
feat(gameui): add game camera script methods
This commit is contained in:
parent
35e44e0976
commit
5be5ba35b9
@ -5,6 +5,7 @@
|
||||
|
||||
#include "client/Client.hpp"
|
||||
#include "gameui/CGWorldFrame.hpp"
|
||||
#include "gameui/GameScriptFunctions.hpp"
|
||||
#include "gx/Coordinate.hpp"
|
||||
#include "gx/Device.hpp"
|
||||
#include "ui/FrameScript.hpp"
|
||||
@ -72,7 +73,7 @@ void CGGameUI::Initialize() {
|
||||
//CGInputControl::UpdateMouseMode((int)Active, 1);
|
||||
|
||||
FrameScript_Flush();
|
||||
//LoadScriptFunctions();
|
||||
LoadScriptFunctions();
|
||||
FrameScript_CreateEvents(g_scriptEvents, 722);
|
||||
//CGGameUI::RegisterGameCVars();
|
||||
//CGUIBindings::Initialize();
|
||||
|
||||
@ -3,7 +3,10 @@
|
||||
#include "gx/Transform.hpp"
|
||||
#include "gx/Draw.hpp"
|
||||
#include "gx/Shader.hpp"
|
||||
#include "gx/Device.hpp"
|
||||
#include "gx/RenderState.hpp"
|
||||
#include "world/CWorld.hpp"
|
||||
#include "gameui/camera/CSimpleCamera.hpp"
|
||||
|
||||
#include <bc/Memory.hpp>
|
||||
#include <tempest/Matrix.hpp>
|
||||
@ -53,15 +56,34 @@ void CGWorldFrame::RenderWorld(void* param) {
|
||||
}
|
||||
|
||||
void CGWorldFrame::OnWorldUpdate() {
|
||||
GxXformSetViewport(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
|
||||
CImVector clearColor = { 0x00, 0x00, 0x00, 0xFF };
|
||||
GxSceneClear(3, clearColor);
|
||||
C44Matrix matrix;
|
||||
GxuXformCreateOrtho(0.0, 1.0, -0.5, 0.5, 0.0, 500.0, matrix);
|
||||
GxXformSetView(C44Matrix());
|
||||
GxXformSetProjection(matrix);
|
||||
|
||||
}
|
||||
|
||||
void CGWorldFrame::OnWorldRender() {
|
||||
CRect windowSize;
|
||||
GxCapsWindowSize(windowSize);
|
||||
if (windowSize.maxY - windowSize.minY == 0.0f || windowSize.maxX - windowSize.minX == 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
GxRsPush();
|
||||
|
||||
C3Vector saveMin;
|
||||
C3Vector saveMax;
|
||||
|
||||
GxXformViewport(saveMin.x, saveMax.x, saveMin.y, saveMax.y, saveMin.z, saveMax.z);
|
||||
|
||||
// TODO
|
||||
|
||||
// WORKAROUND:
|
||||
float maxZ = saveMax.z - (saveMax.z - saveMin.z) * 0.050000001;
|
||||
GxXformSetViewport(saveMin.x, saveMax.x, saveMin.y, saveMax.y, saveMin.z, maxZ);
|
||||
|
||||
CShaderEffect::UpdateProjMatrix();
|
||||
|
||||
CWorld::Render();
|
||||
|
||||
GxRsPop();
|
||||
}
|
||||
|
||||
17
src/gameui/GameScriptFunctions.cpp
Normal file
17
src/gameui/GameScriptFunctions.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "gameui/GameScriptFunctions.hpp"
|
||||
#include "ui/FrameScript.hpp"
|
||||
#include "ui/ScriptFunctions.hpp"
|
||||
|
||||
void LoadScriptFunctions() {
|
||||
RegisterSimpleFrameScriptMethods();
|
||||
// TODO
|
||||
CameraRegisterScriptFunctions();
|
||||
}
|
||||
|
||||
void CameraRegisterScriptFunctions() {
|
||||
for (int32_t i = 0; i < NUM_SCRIPT_FUNCTIONS_CAMERA; ++i) {
|
||||
FrameScript_RegisterFunction(
|
||||
GameScript::s_ScriptFunctions_Camera[i].name,
|
||||
GameScript::s_ScriptFunctions_Camera[i].method);
|
||||
}
|
||||
}
|
||||
20
src/gameui/GameScriptFunctions.hpp
Normal file
20
src/gameui/GameScriptFunctions.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef GAMEUI_GAME_SCRIPT_FUNCTIONS_HPP
|
||||
#define GAMEUI_GAME_SCRIPT_FUNCTIONS_HPP
|
||||
|
||||
#include "ui/Types.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
struct lua_State;
|
||||
|
||||
#define NUM_SCRIPT_FUNCTIONS_CAMERA 22
|
||||
|
||||
namespace GameScript {
|
||||
extern FrameScript_Method s_ScriptFunctions_Camera[NUM_SCRIPT_FUNCTIONS_CAMERA];
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
||||
void LoadScriptFunctions();
|
||||
void CameraRegisterScriptFunctions();
|
||||
|
||||
#endif
|
||||
119
src/gameui/GameScriptFunctionsCamera.cpp
Normal file
119
src/gameui/GameScriptFunctionsCamera.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include "gameui/GameScriptFunctions.hpp"
|
||||
#include "ui/FrameScript.hpp"
|
||||
#include "util/Lua.hpp"
|
||||
#include "util/Unimplemented.hpp"
|
||||
|
||||
|
||||
int32_t Script_CameraZoomIn(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_CameraZoomOut(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewInStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewInStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewOutStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewOutStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewLeftStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewLeftStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewRightStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewRightStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewUpStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewUpStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewDownStart(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_MoveViewDownStop(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_SetView(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_SaveView(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_ResetView(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_NextView(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_PrevView(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_FlipCameraYaw(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_VehicleCameraZoomIn(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
int32_t Script_VehicleCameraZoomOut(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
|
||||
FrameScript_Method GameScript::s_ScriptFunctions_Camera[NUM_SCRIPT_FUNCTIONS_CAMERA] = {
|
||||
{ "CameraZoomIn", &Script_CameraZoomIn },
|
||||
{ "CameraZoomOut", &Script_CameraZoomOut },
|
||||
{ "MoveViewInStart", &Script_MoveViewInStart },
|
||||
{ "MoveViewInStop", &Script_MoveViewInStop },
|
||||
{ "MoveViewOutStart", &Script_MoveViewOutStart },
|
||||
{ "MoveViewOutStop", &Script_MoveViewOutStop },
|
||||
{ "MoveViewLeftStart", &Script_MoveViewLeftStart },
|
||||
{ "MoveViewLeftStop", &Script_MoveViewLeftStop },
|
||||
{ "MoveViewRightStart", &Script_MoveViewRightStart },
|
||||
{ "MoveViewRightStop", &Script_MoveViewRightStop },
|
||||
{ "MoveViewUpStart", &Script_MoveViewUpStart },
|
||||
{ "MoveViewUpStop", &Script_MoveViewUpStop },
|
||||
{ "MoveViewDownStart", &Script_MoveViewDownStart },
|
||||
{ "MoveViewDownStop", &Script_MoveViewDownStop },
|
||||
{ "SetView", &Script_SetView },
|
||||
{ "SaveView", &Script_SaveView },
|
||||
{ "ResetView", &Script_ResetView },
|
||||
{ "NextView", &Script_NextView },
|
||||
{ "PrevView", &Script_PrevView },
|
||||
{ "FlipCameraYaw", &Script_FlipCameraYaw },
|
||||
{ "VehicleCameraZoomIn", &Script_VehicleCameraZoomIn },
|
||||
{ "VehicleCameraZoomOut", &Script_VehicleCameraZoomOut },
|
||||
};
|
||||
@ -5,6 +5,7 @@
|
||||
#include <tempest/matrix/C44Matrix.hpp>
|
||||
|
||||
#include "gx/Transform.hpp"
|
||||
#include "gx/Shader.hpp"
|
||||
|
||||
|
||||
static void FaceDirection(const C3Vector& direction, C3Vector* xprime, C3Vector* yprime, C3Vector* zprime) {
|
||||
@ -145,8 +146,10 @@ void CSimpleCamera::SetGxProjectionAndView(const CRect& projectionRect) {
|
||||
this->m_aspect = (projectionRect.maxX - projectionRect.minX) / (projectionRect.maxY - projectionRect.minY);
|
||||
|
||||
C44Matrix mProj;
|
||||
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);
|
||||
|
||||
@ -17,6 +17,7 @@ target_link_libraries(world
|
||||
PRIVATE
|
||||
gx
|
||||
model
|
||||
gameui
|
||||
PUBLIC
|
||||
bc
|
||||
common
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
#include "world/CWorld.hpp"
|
||||
#include "gx/Device.hpp"
|
||||
#include "gx/Shader.hpp"
|
||||
#include "gx/RenderState.hpp"
|
||||
#include "model/Model2.hpp"
|
||||
#include "world/World.hpp"
|
||||
#include "world/map/CMap.hpp"
|
||||
#include "world/daynight/DayNight.hpp"
|
||||
#include "gameui/camera/CSimpleCamera.hpp"
|
||||
#include "gameui/CGWorldFrame.hpp"
|
||||
|
||||
uint32_t CWorld::s_enables;
|
||||
uint32_t CWorld::s_enables2;
|
||||
@ -50,5 +54,13 @@ 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);
|
||||
DayNight::RenderSky();
|
||||
GxRsPop();
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ namespace DayNight {
|
||||
|
||||
void DNStars::Initialize() {
|
||||
this->m_scene = M2CreateScene();
|
||||
this->m_model = this->m_scene->CreateModel("Environments\\Stars\\stars.mdl", 0);
|
||||
this->m_model = this->m_scene->CreateModel("Spells\\ErrorCube.mdx" /* "Environments\\Stars\\stars.mdl" */, 0);
|
||||
this->m_time = OsGetAsyncTimeMs();
|
||||
}
|
||||
|
||||
@ -32,8 +32,9 @@ void DNStars::Render() {
|
||||
}
|
||||
|
||||
this->m_model->SetAnimating(1);
|
||||
this->m_model->SetVisible(1);
|
||||
|
||||
// TODO
|
||||
// TODO: this->m_model->SetSomething(1);
|
||||
|
||||
uint32_t elapsed = OsGetAsyncTimeMs() - this->m_time;
|
||||
this->m_time += elapsed;
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
#include "world/daynight/DayNight.hpp"
|
||||
#include "world/daynight/DNStars.hpp"
|
||||
#include "gx/Transform.hpp"
|
||||
#include "gx/RenderState.hpp"
|
||||
#include "gx/Draw.hpp"
|
||||
|
||||
|
||||
namespace DayNight {
|
||||
@ -14,6 +17,22 @@ void LoadMap(int32_t zoneID) {
|
||||
|
||||
void RenderSky() {
|
||||
// TODO
|
||||
|
||||
float minX;
|
||||
float maxX;
|
||||
float minY;
|
||||
float maxY;
|
||||
float minZ;
|
||||
float maxZ;
|
||||
GxXformViewport(minX, maxX, minY, maxY, minZ, maxZ);
|
||||
|
||||
// TODO
|
||||
|
||||
GxXformSetViewport(minX, maxX, minY, maxY, 0.99902344f, 1.0f);
|
||||
GxRsSet(GxRs_ScissorTest, 1);
|
||||
CImVector color { 0xFF000000 };
|
||||
GxSceneClear(3, color);
|
||||
|
||||
g_stars.Render();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user