Semi-working translation widget

This commit is contained in:
2016-01-21 14:14:22 +01:00
parent 0183e1bdb7
commit b9147344e1
7 changed files with 72 additions and 9 deletions
+1 -1
View File
@@ -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;
}
+29 -2
View File
@@ -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) {
+17 -6
View File
@@ -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);