Working rotations and translations relative to global and local space for children
This commit is contained in:
+1
-1
Submodule deps updated: f20b9cc13b...e63991581a
@@ -1,5 +1,5 @@
|
|||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0" Z="0"/>
|
<Position X="0" Y="0" Z="0"/>
|
||||||
<Orientation X="0" Y="0" Z="0" W="0"/>
|
<Orientation X="0" Y="0" Z="0"/>
|
||||||
<Scale X="1" Y="1" Z="1"/>
|
<Scale X="1" Y="1" Z="1"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
<Entity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd" xmlns:c="components">
|
<Entity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd" xmlns:c="components">
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform></c:Transform>
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0"/>
|
||||||
|
<Orientation X="0" Y="0" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
<Entity>
|
<Entity>
|
||||||
@@ -19,12 +22,28 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="1" Z="0"/>
|
<Position X="1" Y="1" Z="0"/>
|
||||||
|
<Orientation X="0" Y="0.78539" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>An error</Resource>
|
<Resource>An error</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
</Components>
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="2" Y="0" Z="0"/>
|
||||||
|
<Orientation X="0" Y="0.78539" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>An error</Resource>
|
||||||
|
</c:Model>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
@@ -431,12 +431,12 @@ float EntityXMLFile::getFloatAttribute(const xercesc::DOMElement* element, const
|
|||||||
{
|
{
|
||||||
using namespace xercesc;
|
using namespace xercesc;
|
||||||
XSValue::Status status;
|
XSValue::Status status;
|
||||||
XSValue* val = XSValue::getActualValue(element->getAttribute(XSTR(attribute)), xercesc::XSValue::DataType::dt_float, status);
|
XSValue* val = XSValue::getActualValue(element->getAttribute(XSTR(attribute)), xercesc::XSValue::DataType::dt_double, status);
|
||||||
if (val == nullptr) {
|
if (val == nullptr) {
|
||||||
LOG_ERROR("Element \"%s\" doesn't have an \"%s\" attribute!", XSTR(element->getTagName()), attribute);
|
LOG_ERROR("Element \"%s\" doesn't have an \"%s\" attribute!", XSTR(element->getTagName()), attribute);
|
||||||
return 0.f;
|
return 0.f;
|
||||||
} else {
|
} else {
|
||||||
return val->fData.fValue.f_float;
|
return static_cast<float>(val->fData.fValue.f_double);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,26 +111,37 @@ bool EditorSystem::OnMouseMove(const Events::MouseMove& e)
|
|||||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||||
if (m_WidgetMode == WidgetMode::Translate) {
|
if (m_WidgetMode == WidgetMode::Translate) {
|
||||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||||
(glm::vec3&)m_World->GetComponent(m_Selection, "Transform")["Position"] += movement;
|
EntityID parent = m_World->GetParent(m_Selection);
|
||||||
|
glm::quat inverseParentOrientation;
|
||||||
|
if (parent != 0) {
|
||||||
|
inverseParentOrientation = glm::inverse(RenderQueueFactory::AbsoluteOrientation(m_World, parent));
|
||||||
|
}
|
||||||
|
(glm::vec3&)m_World->GetComponent(m_Selection, "Transform")["Position"] += inverseParentOrientation * movement;
|
||||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||||
(glm::vec3&)selectionTransform["Position"] += glm::quat((glm::vec3&)selectionTransform["Orientation"]) * movement;
|
(glm::vec3&)selectionTransform["Position"] += glm::quat((glm::vec3)selectionTransform["Orientation"]) * movement;
|
||||||
}
|
}
|
||||||
} else if (m_WidgetMode == WidgetMode::Rotate) {
|
} else if (m_WidgetMode == WidgetMode::Rotate) {
|
||||||
glm::vec3 finalMovement;
|
glm::vec3 finalMovement;
|
||||||
finalMovement.x = -deltaWorld.y * m_WidgetCurrentAxis.x;
|
finalMovement.x = -deltaWorld.y * m_WidgetCurrentAxis.x;
|
||||||
finalMovement.y = deltaWorld.x * m_WidgetCurrentAxis.y;
|
finalMovement.y = deltaWorld.x * m_WidgetCurrentAxis.y;
|
||||||
finalMovement.z = deltaWorld.y * m_WidgetCurrentAxis.z;
|
finalMovement.z = deltaWorld.y * m_WidgetCurrentAxis.z;
|
||||||
glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"];
|
|
||||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||||
glm::quat currentOrientation = glm::quat(selectionOrientation);
|
EntityID parent = m_World->GetParent(m_Selection);
|
||||||
|
glm::quat parentOrientation;
|
||||||
|
if (parent != 0) {
|
||||||
|
parentOrientation = RenderQueueFactory::AbsoluteOrientation(m_World, parent);
|
||||||
|
}
|
||||||
|
glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"];
|
||||||
|
//glm::quat currentOrientation = RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection);
|
||||||
|
glm::quat currentOrientation = parentOrientation * glm::quat(selectionOrientation);
|
||||||
glm::quat deltaOrientation(finalMovement);
|
glm::quat deltaOrientation(finalMovement);
|
||||||
selectionOrientation = glm::eulerAngles(deltaOrientation * currentOrientation); // (currentOrientation * deltaOrientation) * glm::vec3(0, 0, -1);
|
selectionOrientation = glm::eulerAngles(glm::inverse(parentOrientation) * (deltaOrientation * currentOrientation));
|
||||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||||
|
glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"];
|
||||||
glm::quat currentOrientation(selectionOrientation);
|
glm::quat currentOrientation(selectionOrientation);
|
||||||
glm::quat deltaOrientation(finalMovement);
|
glm::quat deltaOrientation(finalMovement);
|
||||||
selectionOrientation = glm::eulerAngles(currentOrientation * deltaOrientation); // (currentOrientation * deltaOrientation) * glm::vec3(0, 0, -1);
|
selectionOrientation = glm::eulerAngles(currentOrientation * deltaOrientation);
|
||||||
widgetTransform["Orientation"] = selectionOrientation;
|
|
||||||
}
|
}
|
||||||
} else if (m_WidgetMode == WidgetMode::Scale) {
|
} else if (m_WidgetMode == WidgetMode::Scale) {
|
||||||
glm::vec3& scaleX = m_World->GetComponent(m_WidgetX, "Transform")["Scale"];
|
glm::vec3& scaleX = m_World->GetComponent(m_WidgetX, "Transform")["Scale"];
|
||||||
@@ -189,6 +200,7 @@ bool EditorSystem::OnPicking(const Events::Picking& e)
|
|||||||
//widgetTransform["Position"] = (glm::vec3)selectionTransform["Position"];
|
//widgetTransform["Position"] = (glm::vec3)selectionTransform["Position"];
|
||||||
} else {
|
} else {
|
||||||
m_Selection = entity;
|
m_Selection = entity;
|
||||||
|
setWidgetMode(m_WidgetMode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_Selection = 0;
|
m_Selection = 0;
|
||||||
@@ -222,8 +234,11 @@ void EditorSystem::updateWidget()
|
|||||||
|
|
||||||
if (m_Selection != 0) {
|
if (m_Selection != 0) {
|
||||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
glm::vec3 selectionPosition = RenderQueueFactory::AbsolutePosition(m_World, m_Selection);
|
||||||
widgetTransform["Position"] = (glm::vec3)selectionTransform["Position"];
|
widgetTransform["Position"] = selectionPosition;
|
||||||
|
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||||
|
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +263,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode)
|
|||||||
if (m_Selection != 0) {
|
if (m_Selection != 0) {
|
||||||
if (m_WidgetSpace == WidgetSpace::Local) {
|
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||||
widgetTransform["Orientation"] = (glm::vec3)selectionTransform["Orientation"];
|
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (newMode == WidgetMode::Scale) {
|
} else if (newMode == WidgetMode::Scale) {
|
||||||
@@ -269,7 +284,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode)
|
|||||||
if (m_Selection != 0) {
|
if (m_Selection != 0) {
|
||||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||||
if (m_WidgetSpace == WidgetSpace::Local) {
|
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||||
widgetTransform["Orientation"] = (glm::vec3)selectionTransform["Orientation"];
|
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user