From ed82f404926b5d71ea766ccca7f735a4e2a617a7 Mon Sep 17 00:00:00 2001 From: Chewico Date: Wed, 21 May 2025 16:15:26 +0200 Subject: [PATCH] Camera working --- DeerStudio/src/DeerStudio/DeerStudio.cpp | 6 ++-- DeerStudio/src/DeerStudio/EditorEngine.h | 3 +- .../src/DeerStudio/EditorEngine/API/Math.h | 2 ++ .../src/DeerStudio/EditorEngine/API/UI.h | 4 ++- .../EditorEngine/API_Implementation/Math.cpp | 4 +++ .../API_Registration/Math_Register.cpp | 4 ++- .../EditorEngine/DockPanelObject.cpp | 30 +++++++++++++++- .../DeerStudio/EditorEngine/DockPanelObject.h | 2 ++ .../DeerStudio/EditorEngine/EditorEngine.cpp | 13 ++++++- roe/Editor/as.predefined | 8 ++++- roe/Editor/test.as | 8 +++-- roe/imgui.ini | 34 +++++++++---------- 12 files changed, 90 insertions(+), 28 deletions(-) diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index fb18251..1dde0f7 100755 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -77,9 +77,11 @@ namespace Deer { void DeerStudioApplication::onUpdate(Timestep delta) { if (Scene::getExecutingState()) Scene::tickExecution(); - + if (VoxelWorld::isInitialized()) VoxelWorld::bakeNextChunk(); + + EditorEngine::tick(); } void DeerStudioApplication::onEvent(Event& e) { @@ -132,7 +134,7 @@ namespace Deer { // ---- PanelS ----- TerrainEditor::onImGui(); viewport_onImGui(); - EditorEngine::execute(); + EditorEngine::render(); // ---- PanelS ----- Scene::gizmoRenderer.refresh(); ImGui::End(); diff --git a/DeerStudio/src/DeerStudio/EditorEngine.h b/DeerStudio/src/DeerStudio/EditorEngine.h index 70b5f10..2037df6 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine.h +++ b/DeerStudio/src/DeerStudio/EditorEngine.h @@ -14,7 +14,8 @@ namespace Deer { void initialize(); void deinitialize(); - void execute(); + void render(); + void tick(); extern asIScriptEngine* scriptEngine; extern asIScriptModule* scriptModule; diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h index abcf258..42539af 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/Math.h @@ -29,6 +29,8 @@ namespace Deer { void camera_construct(CameraComponent*); void sceneCamera_Construct(SceneCamera*); + glm::vec3 transform_relative(glm::vec3, TransformComponent*); + void emptyDestructor(); void registerMathStructs(); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h index 75d34c8..8b28207 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/UI.h @@ -80,7 +80,9 @@ namespace Deer { float magicSlider(std::string&, float, float); // Draws a complex slider that with double click you can set a specific value in vec3 glm::vec3 magicSlider3(std::string&, glm::vec3, float); - + // Returns if the current executing pannel is active + bool isPannelActive(); + void registerUIFunctions(); } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Math.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Math.cpp index 66bc291..693d8cb 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Math.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/Math.cpp @@ -44,6 +44,10 @@ namespace Deer { return *mem * *data; } + glm::vec3 transform_relative(glm::vec3 pos, TransformComponent* transform) { + return transform->getMatrix() * glm::vec4(pos, 1.0f); + } + void transform_construct(TransformComponent* mem) { new (mem) TransformComponent(); } diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/Math_Register.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/Math_Register.cpp index 71622e3..66694e7 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/Math_Register.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Registration/Math_Register.cpp @@ -64,7 +64,7 @@ namespace Deer { } void registerMathFunctions() { - REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opAdds(const vec3 &in)", vec3_add); + REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opAdd(const vec3 &in)", vec3_add); REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opSub(const vec3 &in) const", vec3_sub); REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opNeg() const", vec3_neg); REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul(float) const", vec3_mult); @@ -80,6 +80,8 @@ namespace Deer { REGISTER_EXT_OBJECT_CONSTRUCTOR("Transform", "void f()", transform_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR("Camera", "void f()", camera_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR("SceneCamera", "void f()", sceneCamera_Construct); + + REGISTER_EXT_OBJECT_METHOD("Transform", "vec3 relative(vec3)", transform_relative); } } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp index 2193a9f..f9e2b50 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp @@ -46,6 +46,7 @@ namespace Deer { return; } + tickFunction = type->GetMethodByDecl("void onTick()"); menuBarFunction = type->GetMethodByDecl("void onMenuBar()"); initFunction = type->GetMethodByDecl("void onInit()"); @@ -135,8 +136,32 @@ namespace Deer { ImGui::End(); } + void EditorEngine::DockPanelObject::tickExecution() { + if (!isValid) + return; + + if (!tickFunction) + return; + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Prepare(tickFunction), + type->GetName() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->SetObject(object), + type->GetName() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Execute(), + type->GetName() + ); + + } + EditorEngine::DockPanelObject::DockPanelObject(DockPanelObject&& other) noexcept - : isValid(other.isValid), renderFunction(other.renderFunction), type(other.type), object(other.object), menuBarFunction(other.menuBarFunction), initFunction(other.initFunction) { + : isValid(other.isValid), renderFunction(other.renderFunction), type(other.type), object(other.object), menuBarFunction(other.menuBarFunction), initFunction(other.initFunction), tickFunction(other.tickFunction) { other.isValid = false; other.renderFunction = nullptr; @@ -144,6 +169,7 @@ namespace Deer { other.object = nullptr; other.menuBarFunction = nullptr; other.initFunction = nullptr; + other.tickFunction = nullptr; } EditorEngine::DockPanelObject& EditorEngine::DockPanelObject::operator=(EditorEngine::DockPanelObject&& other) noexcept { @@ -154,6 +180,7 @@ namespace Deer { object = other.object; menuBarFunction = other.menuBarFunction; initFunction = other.initFunction; + tickFunction = other.tickFunction; other.isValid = false; other.renderFunction = nullptr; @@ -161,6 +188,7 @@ namespace Deer { other.object = nullptr; other.menuBarFunction = nullptr; other.initFunction = nullptr; + other.tickFunction = nullptr; } return *this; diff --git a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h index 544e04b..da4a125 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h @@ -10,6 +10,7 @@ namespace Deer { asITypeInfo* type = nullptr; asIScriptObject* object = nullptr; asIScriptFunction* renderFunction = nullptr; + asIScriptFunction* tickFunction = nullptr; asIScriptFunction* menuBarFunction = nullptr; asIScriptFunction* initFunction = nullptr; bool isValid = false; @@ -25,6 +26,7 @@ namespace Deer { DockPanelObject& operator=(DockPanelObject&& other) noexcept; void executeRender(); + void tickExecution(); void invalidate(); void init(); }; diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp index 2268724..7129772 100644 --- a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp @@ -73,7 +73,7 @@ namespace Deer { active = false; } - void EditorEngine::execute() { + void EditorEngine::render() { if (!active) return; @@ -83,4 +83,15 @@ namespace Deer { } currentDockPanelExecution = nullptr; } + + void EditorEngine::tick() { + if (!active) + return; + + for (auto& panel : dockPanels) { + currentDockPanelExecution = &panel; + panel.tickExecution(); + } + currentDockPanelExecution = nullptr; + } } \ No newline at end of file diff --git a/roe/Editor/as.predefined b/roe/Editor/as.predefined index 7a51935..1a6b848 100644 --- a/roe/Editor/as.predefined +++ b/roe/Editor/as.predefined @@ -151,6 +151,7 @@ class TransformComponent { // Gets/sets rotation vector (Euler angles) vec3 get_rotation() const property; void set_rotation(const vec3) property; + } class MeshComponent { @@ -206,7 +207,7 @@ class vec3 { vec3(float, float = 0, float = 0); // Vector addition - vec3 opAdds(const vec3&in); + vec3 opAdd(const vec3&in); // Vector subtraction vec3 opSub(const vec3&in) const; // Negation @@ -244,6 +245,9 @@ class Transform { vec3 position; vec3 scale; quat rotation; + + // Returns a vec3 relative to the transform + vec3 relative(vec3); } class Camera { @@ -468,4 +472,6 @@ namespace UI { // Draw a title aligned to the end void titleEnd(const string& in txt); + bool isPannelActive(); + } diff --git a/roe/Editor/test.as b/roe/Editor/test.as index af6c5b6..5ddae98 100644 --- a/roe/Editor/test.as +++ b/roe/Editor/test.as @@ -15,10 +15,12 @@ class Test : DockPanel { UI::drawFrameBufferCentered(frameBuffer, 400, 400); } + void onTick() { + vec3 newPos = sceneCamera.transform.relative(vec3(0, 0, 0.01f)); + sceneCamera.transform.position = newPos; + } + void onInit() { - - Engine::print("hi!!"); - frameBuffer = Engine::createRGBA8FrameBuffer("MainFrameBuffer", 400, 400); mainEnv = Engine::getMainEnvironment(); diff --git a/roe/imgui.ini b/roe/imgui.ini index 8dbef3d..a428c39 100644 --- a/roe/imgui.ini +++ b/roe/imgui.ini @@ -16,7 +16,7 @@ DockId=0x00000004,1 [Window][Game Window] Pos=365,24 -Size=741,395 +Size=521,504 Collapsed=0 DockId=0x00000006,0 @@ -27,14 +27,14 @@ Collapsed=0 DockId=0x00000001,0 [Window][Terrain Editor] -Pos=1108,24 -Size=172,395 +Pos=888,24 +Size=392,504 Collapsed=0 DockId=0x00000004,0 [Window][Viewport] Pos=365,24 -Size=741,395 +Size=521,504 Collapsed=0 DockId=0x00000006,1 @@ -57,14 +57,14 @@ Collapsed=0 DockId=0x00000008,1 [Window][MeshExplorer] -Pos=0,421 -Size=1280,299 +Pos=0,530 +Size=1280,190 Collapsed=0 DockId=0x00000008,0 [Window][TreePannel] Pos=0,24 -Size=363,395 +Size=363,504 Collapsed=0 DockId=0x00000005,0 @@ -79,8 +79,8 @@ Size=351,75 Collapsed=0 [Window][PropertiesPannel] -Pos=1108,24 -Size=172,395 +Pos=888,24 +Size=392,504 Collapsed=0 DockId=0x00000004,1 @@ -91,25 +91,25 @@ Collapsed=0 DockId=0x00000004,1 [Window][ShaderExplorer] -Pos=0,421 -Size=1280,299 +Pos=0,530 +Size=1280,190 Collapsed=0 DockId=0x00000008,1 [Window][Test] Pos=365,24 -Size=741,395 +Size=521,504 Collapsed=0 DockId=0x00000006,2 [Docking][Data] DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y - DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,395 Split=Y + DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,504 Split=Y DockNode ID=0x00000001 Parent=0x00000007 SizeRef=2560,363 Split=X Selected=0x13926F0B - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1106,338 Split=X Selected=0x13926F0B + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=886,338 Split=X Selected=0x13926F0B DockNode ID=0x00000005 Parent=0x00000003 SizeRef=363,446 Selected=0xE45B9F93 - DockNode ID=0x00000006 Parent=0x00000003 SizeRef=741,446 CentralNode=1 Selected=0x44A6A033 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=172,338 Selected=0xA35A27E3 + DockNode ID=0x00000006 Parent=0x00000003 SizeRef=521,446 CentralNode=1 Selected=0x44A6A033 + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=392,338 Selected=0xA35A27E3 DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702 - DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,299 Selected=0xD962995A + DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,190 Selected=0xD962995A