Camera working

This commit is contained in:
Chewico 2025-05-21 16:15:26 +02:00
parent fc169a2c91
commit ed82f40492
12 changed files with 90 additions and 28 deletions

View File

@ -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();

View File

@ -14,7 +14,8 @@ namespace Deer {
void initialize();
void deinitialize();
void execute();
void render();
void tick();
extern asIScriptEngine* scriptEngine;
extern asIScriptModule* scriptModule;

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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();
};

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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