Semi-working translation widget
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "../Core/EntityFilePreprocessor.h"
|
||||
#include "../Core/EntityFileParser.h"
|
||||
#include "../Core/EntityFileWriter.h"
|
||||
#include "../Core/EMouseRelease.h"
|
||||
#include "EditorGUI.h"
|
||||
#include "EditorStats.h"
|
||||
|
||||
@@ -49,4 +50,10 @@ private:
|
||||
void OnEntityChangeName(EntityWrapper entity, const std::string& name);
|
||||
void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
|
||||
void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
|
||||
|
||||
// Events
|
||||
EventRelay<EditorSystem, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease& e);
|
||||
EventRelay<EditorSystem, Events::WidgetDelta> m_EWidgetDelta;
|
||||
bool OnWidgetDelta(const Events::WidgetDelta& e);
|
||||
};
|
||||
@@ -10,6 +10,18 @@
|
||||
#include "../Core/EMousePress.h"
|
||||
#include "../Core/EMouseRelease.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct WidgetDelta : Event
|
||||
{
|
||||
glm::vec3 Translation;
|
||||
glm::vec3 Rotation;
|
||||
glm::vec3 Scale;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class EditorWidgetSystem : public ImpureSystem, PureSystem
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<Entity name="X">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="0" Y="1" Z="0"/>
|
||||
<Type>
|
||||
<Rotate/>
|
||||
</Type>
|
||||
@@ -24,6 +25,7 @@
|
||||
<Entity name="Y">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="1" Y="0" Z="0"/>
|
||||
<Type>
|
||||
<Rotate/>
|
||||
</Type>
|
||||
@@ -39,6 +41,7 @@
|
||||
<Entity name="Z">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="1" Y="1" Z="0"/>
|
||||
<Type>
|
||||
<Rotate/>
|
||||
</Type>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<Entity name="X">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="1" Y="0" Z="0"/>
|
||||
<Axis X="1" Y="0" Z="0"/>
|
||||
</c:EditorWidget>
|
||||
<c:Model>
|
||||
@@ -24,6 +25,7 @@
|
||||
<Entity name="Y">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="0" Y="1" Z="0"/>
|
||||
<Axis X="0" Y="1" Z="0"/>
|
||||
</c:EditorWidget>
|
||||
<c:Model>
|
||||
@@ -36,6 +38,7 @@
|
||||
<Entity name="Z">
|
||||
<Components>
|
||||
<c:EditorWidget>
|
||||
<MouseAxis X="0" Y="0" Z="1"/>
|
||||
<Axis X="0" Y="0" Z="1"/>
|
||||
</c:EditorWidget>
|
||||
<c:Model>
|
||||
|
||||
@@ -7,7 +7,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
|
||||
while (entity != EntityID_Invalid) {
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
EntityID parent = world->GetParent(entity);
|
||||
position += Transform::AbsoluteScale(world, parent) * Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
||||
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
||||
entity = parent;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
|
||||
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
|
||||
m_EditorGUI->SetWidgetModeCallback(std::bind(&EditorSystem::setWidgetMode, this, std::placeholders::_1));
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &EditorSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EWidgetDelta, &EditorSystem::OnWidgetDelta);
|
||||
|
||||
m_EditorStats = new EditorStats();
|
||||
|
||||
Events::SetCamera e;
|
||||
@@ -49,11 +52,15 @@ EditorSystem::~EditorSystem()
|
||||
|
||||
void EditorSystem::Update(double dt)
|
||||
{
|
||||
m_EditorWorldSystemPipeline->Update(dt);
|
||||
|
||||
m_EditorGUI->Draw();
|
||||
m_EditorStats->Draw(dt);
|
||||
|
||||
if (m_CurrentSelection.Valid() && m_Widget.Valid()) {
|
||||
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID);
|
||||
}
|
||||
|
||||
m_EditorWorldSystemPipeline->Update(dt);
|
||||
|
||||
m_DebugCameraInputController->Update(dt);
|
||||
m_Camera["Transform"]["Position"] = m_DebugCameraInputController->Position();
|
||||
m_Camera["Transform"]["Orientation"] = glm::eulerAngles(m_DebugCameraInputController->Orientation());
|
||||
@@ -103,6 +110,26 @@ void EditorSystem::OnComponentDelete(EntityWrapper entity, const std::string& co
|
||||
entity.World->DeleteComponent(entity.ID, componentType);
|
||||
}
|
||||
|
||||
bool EditorSystem::OnMouseRelease(const Events::MouseRelease& e)
|
||||
{
|
||||
if (e.Button == GLFW_MOUSE_BUTTON_1) {
|
||||
PickData pick = m_Renderer->Pick(glm::vec2(e.X, e.Y));
|
||||
if (pick.World == m_World) {
|
||||
m_CurrentSelection = EntityWrapper(m_World, pick.Entity);
|
||||
m_EditorGUI->SelectEntity(m_CurrentSelection);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
|
||||
{
|
||||
if (m_CurrentSelection.Valid()) {
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += glm::inverse(Transform::AbsoluteOrientation(m_CurrentSelection.World, m_CurrentSelection.ID)) * e.Translation;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem::path filePath)
|
||||
{
|
||||
if (parent.World == nullptr) {
|
||||
|
||||
@@ -21,19 +21,30 @@ void EditorWidgetSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
return;
|
||||
}
|
||||
|
||||
Events::WidgetDelta e;
|
||||
|
||||
EntityWrapper moveEntity = entity.Parent();
|
||||
if (!moveEntity.Valid()) {
|
||||
moveEntity = entity;
|
||||
}
|
||||
|
||||
auto camera = m_PickData.Camera;
|
||||
glm::vec3 axis = cEditorWidget["Axis"];
|
||||
glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->Resolution()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->Resolution());
|
||||
float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen);
|
||||
glm::vec3 worldMovement = dot * axis;
|
||||
|
||||
ComponentWrapper::SubscriptProxy& type = cEditorWidget["Type"];
|
||||
if ((ComponentInfo::EnumType)type == type.Enum("Translate")) {
|
||||
auto camera = m_PickData.Camera;
|
||||
glm::vec3 axis = cEditorWidget["Axis"];
|
||||
glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->Resolution()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->Resolution());
|
||||
float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen);
|
||||
glm::vec3 worldMovement = dot * axis;
|
||||
(glm::vec3&)moveEntity["Transform"]["Position"] += worldMovement;
|
||||
e.Translation += worldMovement;
|
||||
m_EventBroker->Publish(e);
|
||||
} else if ((ComponentInfo::EnumType)type == type.Enum("Rotate")) {
|
||||
//if (glm::length(worldMovement) > 0) {
|
||||
// glm::vec3& orientation = moveEntity["Transform"]["Orientation"];
|
||||
// glm::quat q = glm::quat(orientation);
|
||||
// q *= glm::quat(glm::vec3(worldMovement));
|
||||
// orientation = glm::eulerAngles(q);
|
||||
//}
|
||||
}
|
||||
|
||||
m_MouseDelta = glm::vec2(0);
|
||||
|
||||
Reference in New Issue
Block a user