Compare commits
1 Commits
v0.1.3
...
236da3059f
| Author | SHA256 | Date | |
|---|---|---|---|
| 236da3059f |
@@ -17,6 +17,7 @@ void TSE::ICursorHandler::Enable()
|
|||||||
if(!enabled())
|
if(!enabled())
|
||||||
{
|
{
|
||||||
IInputManager::instance()->RegisterCursorHandler(this);
|
IInputManager::instance()->RegisterCursorHandler(this);
|
||||||
|
Enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ void TSE::ICursorHandler::Disable()
|
|||||||
if(enabled())
|
if(enabled())
|
||||||
{
|
{
|
||||||
IInputManager::instance()->UnregisterCursorHandler(this);
|
IInputManager::instance()->UnregisterCursorHandler(this);
|
||||||
|
Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ void TSE::IKeyInputHandler::Enable()
|
|||||||
if(!enabled())
|
if(!enabled())
|
||||||
{
|
{
|
||||||
IInputManager::instance()->RegisterKeyHandler(this);
|
IInputManager::instance()->RegisterKeyHandler(this);
|
||||||
|
Enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ void TSE::IKeyInputHandler::Disable()
|
|||||||
if(enabled())
|
if(enabled())
|
||||||
{
|
{
|
||||||
IInputManager::instance()->UnregisterKeyHandler(this);
|
IInputManager::instance()->UnregisterKeyHandler(this);
|
||||||
|
Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
172
TSE_Editor/src/BehaviourScripts/basicEditorCamera.cpp
Normal file
172
TSE_Editor/src/BehaviourScripts/basicEditorCamera.cpp
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#include "basicEditorCamera.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
#include "BehaviourScripts/Camera.hpp"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnUpdate()
|
||||||
|
{
|
||||||
|
auto euler = baseObject->GetEuler();
|
||||||
|
auto finalrot = rotDelta * rotationMultiplier * Time::deltaTime();
|
||||||
|
rotDelta = Vector2::zero;
|
||||||
|
if(mouseInputEnabled)
|
||||||
|
{
|
||||||
|
euler.y += finalrot.x;
|
||||||
|
euler.x += finalrot.y;
|
||||||
|
}
|
||||||
|
baseObject->SetEuler(euler);
|
||||||
|
|
||||||
|
Vector3 move;
|
||||||
|
|
||||||
|
if(keyInputEnabled && SceneView::IsHovered)
|
||||||
|
delta = delta + keydelta * keyMultiplier;
|
||||||
|
|
||||||
|
move = baseObject->right() * delta.x;
|
||||||
|
move = move + baseObject->up() * delta.y;
|
||||||
|
move = move + baseObject->forward() * delta.z;
|
||||||
|
|
||||||
|
delta = Vector3::zero;
|
||||||
|
|
||||||
|
|
||||||
|
move = move * movementMultiplier * Time::deltaTime();
|
||||||
|
|
||||||
|
baseObject->position = baseObject->position + move;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::Start()
|
||||||
|
{
|
||||||
|
ICursorHandler::Enable();
|
||||||
|
IKeyInputHandler::Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnKeyDown(const Key &key, const Modifier &mods)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key::LeftShift:
|
||||||
|
isShiftPressed = true;
|
||||||
|
break;
|
||||||
|
case Key::W:
|
||||||
|
keydelta = keydelta + Vector3::forward * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::A:
|
||||||
|
keydelta = keydelta + Vector3::left * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::S:
|
||||||
|
keydelta = keydelta + Vector3::back * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::D:
|
||||||
|
keydelta = keydelta + Vector3::right * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::E:
|
||||||
|
keydelta = keydelta + Vector3::up * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::Q:
|
||||||
|
keydelta = keydelta + Vector3::down * keyMultiplier;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnKeyUp(const Key &key, const Modifier &mods)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key::LeftShift:
|
||||||
|
isShiftPressed = false;
|
||||||
|
break;
|
||||||
|
case Key::W:
|
||||||
|
keydelta = keydelta - Vector3::forward * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::A:
|
||||||
|
keydelta = keydelta - Vector3::left * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::S:
|
||||||
|
keydelta = keydelta - Vector3::back * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::D:
|
||||||
|
keydelta = keydelta - Vector3::right * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::E:
|
||||||
|
keydelta = keydelta - Vector3::up * keyMultiplier;
|
||||||
|
break;
|
||||||
|
case Key::Q:
|
||||||
|
keydelta = keydelta - Vector3::down * keyMultiplier;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnMouseButtonDown(const MouseBtn &btn, const Modifier &mods)
|
||||||
|
{
|
||||||
|
if(!mouseInputEnabled) return;
|
||||||
|
switch (btn)
|
||||||
|
{
|
||||||
|
case MouseBtn::RightMouse:
|
||||||
|
holdingRightClick = true;
|
||||||
|
break;
|
||||||
|
case MouseBtn::LeftMouse:
|
||||||
|
holdingLeftClick = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnMouseButtonUp(const MouseBtn &btn, const Modifier &mods)
|
||||||
|
{
|
||||||
|
if(!mouseInputEnabled) return;
|
||||||
|
switch (btn)
|
||||||
|
{
|
||||||
|
case MouseBtn::RightMouse:
|
||||||
|
holdingRightClick = false;
|
||||||
|
break;
|
||||||
|
case MouseBtn::LeftMouse:
|
||||||
|
holdingLeftClick = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnMousePosition(const Vector2 &pos)
|
||||||
|
{
|
||||||
|
if(!mouseInputEnabled || !SceneView::IsHovered) return;
|
||||||
|
if(isShiftPressed && holdingLeftClick)
|
||||||
|
{
|
||||||
|
auto tmp = pos - lastMousepos;
|
||||||
|
tmp.x *= -1;
|
||||||
|
delta = delta + tmp;
|
||||||
|
}
|
||||||
|
else if(holdingRightClick)
|
||||||
|
{
|
||||||
|
rotDelta = rotDelta + (pos - lastMousepos);
|
||||||
|
}
|
||||||
|
lastMousepos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::OnMouseScroll(const Vector2 &mdelta)
|
||||||
|
{
|
||||||
|
if(!mouseInputEnabled || !SceneView::IsHovered) return;
|
||||||
|
Camera* editorCam = (Camera*)Transformable::Find(".EditorCamera")->GetBehaviourScript(CAMERA);
|
||||||
|
float scale = editorCam->GetRenderScale();
|
||||||
|
|
||||||
|
scale += mdelta.y * zoomMultiplier;
|
||||||
|
scale = std::clamp(scale, zoomMin, zoomMax);
|
||||||
|
|
||||||
|
editorCam->SetRenderScale(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::EDITOR::basicEditorCamera::CustomDraw(const bool &debug)
|
||||||
|
{
|
||||||
|
ImGui::DragFloat("Rotation Speed", &rotationMultiplier, 0.1f);
|
||||||
|
ImGui::DragFloat("Movement Speed", &movementMultiplier, 0.1f);
|
||||||
|
ImGui::DragFloat("Zoom Speed", &zoomMultiplier, 0.1f);
|
||||||
|
ImGui::DragFloat("key Speed", &keyMultiplier, 0.1f);
|
||||||
|
|
||||||
|
ImGui::Checkbox("Keybord Input", &keyInputEnabled);
|
||||||
|
ImGui::Checkbox("Mouse Input", &mouseInputEnabled);
|
||||||
|
}
|
||||||
60
TSE_Editor/src/BehaviourScripts/basicEditorCamera.hpp
Normal file
60
TSE_Editor/src/BehaviourScripts/basicEditorCamera.hpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define BASIC_EDITOR_CAMERA typeid(basicEditorCamera).name()
|
||||||
|
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "interfaces/ICursorHandler.hpp"
|
||||||
|
#include "interfaces/IKeyInputHandler.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
#include "UI/windows/SceneView.hpp"
|
||||||
|
|
||||||
|
namespace TSE::EDITOR
|
||||||
|
{
|
||||||
|
class basicEditorCamera : public BehaviourScript, public ICursorHandler, public IKeyInputHandler
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
bool keyInputEnabled = true;
|
||||||
|
bool mouseInputEnabled = true;
|
||||||
|
|
||||||
|
bool isShiftPressed = false;
|
||||||
|
bool holdingRightClick = false;
|
||||||
|
bool holdingLeftClick = false;
|
||||||
|
Vector3 delta = Vector3::zero;
|
||||||
|
Vector3 keydelta = Vector3::zero;
|
||||||
|
Vector2 rotDelta = Vector2::zero;
|
||||||
|
Vector2 lastMousepos;
|
||||||
|
float keyMultiplier = 0.5f;
|
||||||
|
|
||||||
|
float rotationMultiplier = 150;
|
||||||
|
float movementMultiplier = 64;
|
||||||
|
float zoomMultiplier = 2;
|
||||||
|
|
||||||
|
const float zoomMin = 6;
|
||||||
|
const float zoomMax = 500;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "basicEditorCamera";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(const Key& key, const Modifier& mods) override;
|
||||||
|
|
||||||
|
void OnKeyUp(const Key& key, const Modifier& mods) override;
|
||||||
|
|
||||||
|
void OnMouseButtonDown(const MouseBtn& btn, const Modifier& mods) override;
|
||||||
|
|
||||||
|
void OnMouseButtonUp(const MouseBtn& btn, const Modifier& mods) override;
|
||||||
|
|
||||||
|
void OnMousePosition(const Vector2& pos) override;
|
||||||
|
|
||||||
|
void OnMouseScroll(const Vector2& delta) override;
|
||||||
|
|
||||||
|
void CustomDraw(const bool& debug) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace TSE::EDITOR
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "BehaviourScriptRegistry.hpp"
|
#include "BehaviourScriptRegistry.hpp"
|
||||||
#include "BehaviourScripts/AudioListener.hpp"
|
#include "BehaviourScripts/AudioListener.hpp"
|
||||||
#include "BehaviourScripts/AudioSource.hpp"
|
#include "BehaviourScripts/AudioSource.hpp"
|
||||||
|
#include "BehaviourScripts/basicEditorCamera.hpp"
|
||||||
|
|
||||||
TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("")
|
TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("")
|
||||||
{
|
{
|
||||||
@@ -34,8 +35,8 @@ TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("")
|
|||||||
editorCam->SetRenderTarget(rt);
|
editorCam->SetRenderTarget(rt);
|
||||||
editorCamera->AddBehaviourScript(editorCam);
|
editorCamera->AddBehaviourScript(editorCam);
|
||||||
|
|
||||||
// basicCameraControls controls = basicCameraControls();
|
basicEditorCamera* controls = new basicEditorCamera();
|
||||||
// editorCamera->AddBehaviourScript(&controls);
|
editorCamera->AddBehaviourScript(controls);
|
||||||
|
|
||||||
editorLayer = Layer(".editor");
|
editorLayer = Layer(".editor");
|
||||||
editorLayer.AddTransformable(editorCamera);
|
editorLayer.AddTransformable(editorCamera);
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ void TSE::EDITOR::HirearchieView::Define()
|
|||||||
DisplayLayer(layer);
|
DisplayLayer(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!selectedFound && PropertiesView::GetCurrentInspectableType() == InspectableType::Transformable)
|
||||||
|
{
|
||||||
|
PropertiesView::ForceClearInspectorElement();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activatePopUpNamingLayer)
|
if(activatePopUpNamingLayer)
|
||||||
@@ -188,10 +193,6 @@ void TSE::EDITOR::HirearchieView::DisplayLayer(Layer *l)
|
|||||||
{
|
{
|
||||||
DisplayObj(l->GetAllObjects()[i], l);
|
DisplayObj(l->GetAllObjects()[i], l);
|
||||||
}
|
}
|
||||||
if(!selectedFound && PropertiesView::GetCurrentInspectableType() == InspectableType::Transformable)
|
|
||||||
{
|
|
||||||
PropertiesView::ForceClearInspectorElement();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::Unindent(20.0f);
|
ImGui::Unindent(20.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ void TSE::EDITOR::SceneView::Define()
|
|||||||
{
|
{
|
||||||
fb->SetSize({vec2.x, vec2.y});
|
fb->SetSize({vec2.x, vec2.y});
|
||||||
}
|
}
|
||||||
|
if(ImGui::IsWindowFocused())
|
||||||
|
{
|
||||||
|
IsHovered = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsHovered = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace TSE::EDITOR
|
|||||||
private:
|
private:
|
||||||
TSE::IRenderTexture* fb;
|
TSE::IRenderTexture* fb;
|
||||||
public:
|
public:
|
||||||
|
inline static bool IsHovered = false;
|
||||||
SceneView(TSE::IRenderTexture* frameBuffer);
|
SceneView(TSE::IRenderTexture* frameBuffer);
|
||||||
void Define() override;
|
void Define() override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,18 +17,21 @@ void TSE::GLFW::InputGlfw::KeyCallback(GLFWwindow *window, int key, int scancode
|
|||||||
case 1: //down
|
case 1: //down
|
||||||
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnKeyDown((Key)key, (Modifier)mods);
|
handler->OnKeyDown((Key)key, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0: //up
|
case 0: //up
|
||||||
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnKeyUp((Key)key, (Modifier)mods);
|
handler->OnKeyUp((Key)key, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: //hold
|
case 2: //hold
|
||||||
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnKeyHold((Key)key, (Modifier)mods);
|
handler->OnKeyHold((Key)key, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -42,18 +45,21 @@ void TSE::GLFW::InputGlfw::MouseButtonCallback(GLFWwindow *window, int button, i
|
|||||||
case 1: //down
|
case 1: //down
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnMouseButtonDown((MouseBtn)button, (Modifier)mods);
|
handler->OnMouseButtonDown((MouseBtn)button, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0: //up
|
case 0: //up
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnMouseButtonUp((MouseBtn)button, (Modifier)mods);
|
handler->OnMouseButtonUp((MouseBtn)button, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: //hold
|
case 2: //hold
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnMouseButtonHold((MouseBtn)button, (Modifier)mods);
|
handler->OnMouseButtonHold((MouseBtn)button, (Modifier)mods);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -64,6 +70,7 @@ void TSE::GLFW::InputGlfw::CursorPosCallback(GLFWwindow *window, double xpos, do
|
|||||||
{
|
{
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnMousePosition(Vector2(xpos, ypos));
|
handler->OnMousePosition(Vector2(xpos, ypos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +79,7 @@ void TSE::GLFW::InputGlfw::ScrollCallback(GLFWwindow *window, double xoffset, do
|
|||||||
{
|
{
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnMouseScroll(Vector2(xoffset, yoffset));
|
handler->OnMouseScroll(Vector2(xoffset, yoffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,6 +114,7 @@ void TSE::GLFW::InputGlfw::CharCallback(GLFWwindow *window, unsigned int codepoi
|
|||||||
|
|
||||||
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
for(auto handler : ((InputGlfw*)instance())->keyHandler)
|
||||||
{
|
{
|
||||||
|
if(handler->enabled())
|
||||||
handler->OnChar(msg);
|
handler->OnChar(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user