/** * @brief * Returns the target position within the container space of the owner node */ bool SNMRotationTarget::GetTargetPosition(Vector3 &vPos) const { // Target scene node given? if (Target.Get().GetLength()) { // Get the target scene node const SceneNode *pTarget; if (GetSceneNode().GetContainer()) pTarget = GetSceneNode().GetContainer()->GetByName(Target.Get()); else { // This must be the root :() pTarget = static_cast<const SceneContainer&>(GetSceneNode()).GetByName(Target.Get()); } if (pTarget) { // Set the position of the attached node vPos = pTarget->GetTransform().GetPosition(); // Are we in luck and the target is within the same container as the owner node? if (GetSceneNode().GetContainer() != pTarget->GetContainer()) { // Nope, we have to translate the position into the correct space :( SceneContainer *pContainer = pTarget->GetContainer(); while (pContainer) { vPos *= pContainer->GetTransform().GetMatrix(); pContainer = pContainer->GetContainer(); } // To container space of the owner node pContainer = GetSceneNode().GetContainer(); Stack<SceneContainer*> lstStack; while (pContainer) { lstStack.Push(pContainer); pContainer = pContainer->GetContainer(); } while (lstStack.GetNumOfElements()) { pContainer = lstStack.Top(); lstStack.Pop(); vPos *= pContainer->GetTransform().GetInverseMatrix(); } } // Done return true; } } // Error - no valid target scene node, no target rotation :( return false; }
/** * @brief * Returns the target rotation within the container space of the owner node */ bool SNMMeshJoint::GetTargetRotation(Quaternion &qRot) const { // Get the target scene node const SceneNode *pTarget; if (GetSceneNode().GetContainer()) pTarget = GetSceneNode().GetContainer()->GetByName(RotationFrom.Get()); else { // This must be the root :() pTarget = static_cast<const SceneContainer&>(GetSceneNode()).GetByName(RotationFrom.Get()); } if (!pTarget) return false; // Error - no valid target scene node, no target rotation :( // Set the rotation of the attached node qRot = pTarget->GetTransform().GetRotation(); // Are we in luck and the target is within the same container as the owner node? if (GetSceneNode().GetContainer() != pTarget->GetContainer()) { // Nope, we have to translate the rotation into the correct space :( const SceneContainer *pContainer = pTarget->GetContainer(); while (pContainer) { qRot *= pContainer->GetTransform().GetRotation(); pContainer = pContainer->GetContainer(); } // To container space of the owner node pContainer = GetSceneNode().GetContainer(); Stack<const SceneContainer*> lstStack; while (pContainer) { lstStack.Push(pContainer); pContainer = pContainer->GetContainer(); } while (lstStack.GetNumOfElements()) { pContainer = lstStack.Top(); lstStack.Pop(); qRot *= pContainer->GetTransform().GetRotation().GetUnitInverted(); } } // Done return true; }