Added optional argument to Node::SetParent
Also fixed Set[Rotation|Scale|Translation] within global coordinate system Former-commit-id: 7808de7c3044f7b9261b22b7db521aad00d63c9b
This commit is contained in:
parent
e5731bee91
commit
842890e12e
|
|
@ -56,8 +56,8 @@ class NAZARA_API NzNode
|
|||
void SetInitialScale(float scaleX, float scaleY, float scaleZ);
|
||||
void SetInitialTranslation(const NzVector3f& translation);
|
||||
void SetInitialTranslation(float translationX, float translationXY, float translationZ);
|
||||
void SetParent(const NzNode* node = nullptr);
|
||||
void SetParent(const NzNode& node);
|
||||
void SetParent(const NzNode* node = nullptr, bool keepDerived = false);
|
||||
void SetParent(const NzNode& node, bool keepDerived = false);
|
||||
void SetRotation(const NzQuaternionf& quat, nzCoordSys coordSys = nzCoordSys_Local);
|
||||
void SetScale(const NzVector3f& scale, nzCoordSys coordSys = nzCoordSys_Local);
|
||||
void SetScale(float scale, nzCoordSys coordSys = nzCoordSys_Local);
|
||||
|
|
|
|||
|
|
@ -297,11 +297,29 @@ void NzNode::SetInitialTranslation(float translationX, float translationY, float
|
|||
Invalidate();
|
||||
}
|
||||
|
||||
void NzNode::SetParent(const NzNode* node)
|
||||
void NzNode::SetParent(const NzNode* node, bool keepDerived)
|
||||
{
|
||||
if (m_parent == node)
|
||||
return;
|
||||
|
||||
if (keepDerived)
|
||||
{
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
|
||||
if (m_parent)
|
||||
m_parent->RemoveChild(this);
|
||||
|
||||
m_parent = node;
|
||||
if (m_parent)
|
||||
m_parent->AddChild(this);
|
||||
|
||||
SetRotation(m_derivedRotation, nzCoordSys_Global);
|
||||
SetScale(m_derivedScale, nzCoordSys_Global);
|
||||
SetTranslation(m_derivedTranslation, nzCoordSys_Global);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->RemoveChild(this);
|
||||
|
||||
|
|
@ -311,10 +329,11 @@ void NzNode::SetParent(const NzNode* node)
|
|||
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void NzNode::SetParent(const NzNode& node)
|
||||
void NzNode::SetParent(const NzNode& node, bool keepDerived)
|
||||
{
|
||||
SetParent(&node);
|
||||
SetParent(&node, keepDerived);
|
||||
}
|
||||
|
||||
void NzNode::SetRotation(const NzQuaternionf& rotation, nzCoordSys coordSys)
|
||||
|
|
@ -327,9 +346,11 @@ void NzNode::SetRotation(const NzQuaternionf& rotation, nzCoordSys coordSys)
|
|||
{
|
||||
case nzCoordSys_Global:
|
||||
{
|
||||
if (m_parent)
|
||||
if (m_parent && m_inheritRotation)
|
||||
{
|
||||
m_rotation = q * m_parent->GetDerivedRotation().GetInverse(); ///FIXME: Vérifier si le résultat est correct
|
||||
NzQuaternionf rot(m_initialRotation * m_parent->GetDerivedRotation());
|
||||
|
||||
m_rotation = rot.GetInverse() * q; ///FIXME: Vérifier si le résultat est correct
|
||||
m_rotation.Normalize();
|
||||
}
|
||||
else
|
||||
|
|
@ -352,10 +373,10 @@ void NzNode::SetScale(const NzVector3f& scale, nzCoordSys coordSys)
|
|||
{
|
||||
case nzCoordSys_Global:
|
||||
{
|
||||
if (m_parent)
|
||||
m_scale = scale / m_parent->GetDerivedScale();
|
||||
if (m_parent && m_inheritScale)
|
||||
m_scale = scale / (m_initialScale * m_parent->GetDerivedScale());
|
||||
else
|
||||
m_scale = scale;
|
||||
m_scale = scale / m_initialScale;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -383,10 +404,15 @@ void NzNode::SetTranslation(const NzVector3f& translation, nzCoordSys coordSys)
|
|||
{
|
||||
case nzCoordSys_Global:
|
||||
{
|
||||
if (m_parent)
|
||||
m_translation = translation - m_parent->GetDerivedTranslation();
|
||||
if (m_parent && m_inheritTranslation)
|
||||
{
|
||||
if (!m_parent->m_derivedUpdated)
|
||||
m_parent->UpdateDerived();
|
||||
|
||||
m_translation = (m_parent->m_derivedRotation.GetConjugate()*(translation - m_parent->m_derivedTranslation))/m_parent->m_derivedScale - m_initialTranslation;
|
||||
}
|
||||
else
|
||||
m_translation = translation;
|
||||
m_translation = translation - m_initialTranslation;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue