Fixed widget movement calculations going weird when world origin wasn't on screen

This commit is contained in:
2016-02-01 11:56:21 +01:00
parent ee92200300
commit 5bfcffc142
+5 -2
View File
@@ -23,14 +23,17 @@ void EditorWidgetSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
Events::WidgetDelta e;
// Widget axes should have a common parent
EntityWrapper moveEntity = entity.Parent();
if (!moveEntity.Valid()) {
moveEntity = entity;
}
glm::vec3 moveEntityPos = moveEntity["Transform"]["Position"];
auto camera = m_PickData.Camera;
glm::vec3 axis = cEditorWidget["Axis"];
glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->GetViewPortSize()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->GetViewPortSize());
glm::vec3 axis = (glm::vec3)cEditorWidget["Axis"];
glm::vec2 axisScreen = camera->WorldToScreen(moveEntityPos + axis, m_Renderer->GetViewPortSize()) - camera->WorldToScreen(moveEntityPos, m_Renderer->GetViewPortSize());
ImGui::Text("axisScreen: (%f, %f)", axisScreen.x, axisScreen.y);
float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen);
glm::vec3 worldMovement = dot * axis;