Fixed widget movement calculations going weird when world origin wasn't on screen
This commit is contained in:
@@ -23,14 +23,17 @@ void EditorWidgetSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
|||||||
|
|
||||||
Events::WidgetDelta e;
|
Events::WidgetDelta e;
|
||||||
|
|
||||||
|
// Widget axes should have a common parent
|
||||||
EntityWrapper moveEntity = entity.Parent();
|
EntityWrapper moveEntity = entity.Parent();
|
||||||
if (!moveEntity.Valid()) {
|
if (!moveEntity.Valid()) {
|
||||||
moveEntity = entity;
|
moveEntity = entity;
|
||||||
}
|
}
|
||||||
|
glm::vec3 moveEntityPos = moveEntity["Transform"]["Position"];
|
||||||
|
|
||||||
auto camera = m_PickData.Camera;
|
auto camera = m_PickData.Camera;
|
||||||
glm::vec3 axis = cEditorWidget["Axis"];
|
glm::vec3 axis = (glm::vec3)cEditorWidget["Axis"];
|
||||||
glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->GetViewPortSize()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->GetViewPortSize());
|
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);
|
float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen);
|
||||||
glm::vec3 worldMovement = dot * axis;
|
glm::vec3 worldMovement = dot * axis;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user