From 9deb69dbca1d766759300bea956e3dbe0301acc0 Mon Sep 17 00:00:00 2001 From: Charlie Carley Date: Fri, 23 Mar 2007 02:20:12 +0000 Subject: [PATCH] Applied patch #6102 submitted by Mal --- .../gameengine/Ketsji/KX_TrackToActuator.cpp | 36 +++++++++++++++++-- source/gameengine/Ketsji/KX_TrackToActuator.h | 9 ++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 0b16ff14f72..36f0d3c3b99 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -70,6 +70,17 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj, m_object = ob; m_trackflag = trackflag; m_upflag = upflag; + m_parentobj = 0; + + if (m_object){ + KX_GameObject* curobj = (KX_GameObject*) GetParent(); + + m_parentobj = curobj->GetParent(); // check if the object is parented + if (m_parentobj) { // if so, store the initial local rotation + m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation(); + } + } + } /* End of constructor */ @@ -325,8 +336,29 @@ bool KX_TrackToActuator::Update(double curtime, bool frame) /* erwin should rewrite this! */ mat= matrix3x3_interpol(oldmat, mat, m_time); - curobj->NodeSetLocalOrientation(mat); - + + if(m_parentobj){ // check if the model is parented and calculate the child transform + + MT_Point3 localpos; + localpos = curobj->GetSGNode()->GetLocalPosition(); + // Get the inverse of the parent matrix + MT_Matrix3x3 parentmatinv; + parentmatinv = m_parentobj->NodeGetWorldOrientation ().inverse (); + // transform the local coordinate system into the parents system + mat = parentmatinv * mat; + // append the initial parent local rotation matrix + mat = m_parentlocalmat * mat; + + // set the models tranformation properties + curobj->NodeSetLocalOrientation(mat); + curobj->NodeSetLocalPosition(localpos); + curobj->UpdateTransform(); + } + else + { + curobj->NodeSetLocalOrientation(mat); + } + result = true; } diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index 6b0ddd7103e..1d257da3f53 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -37,6 +37,9 @@ #include "SCA_IActuator.h" #include "SCA_IObject.h" +#include "MT_Matrix3x3.h" +#include "KX_GameObject.h" + class KX_TrackToActuator : public SCA_IActuator { @@ -50,7 +53,11 @@ class KX_TrackToActuator : public SCA_IActuator int m_trackTime; int m_trackflag; int m_upflag; - public: + + MT_Matrix3x3 m_parentlocalmat; + KX_GameObject* m_parentobj; + + public: KX_TrackToActuator(SCA_IObject* gameobj, SCA_IObject *ob, int time, bool threedee,int trackflag,int upflag, PyTypeObject* T=&Type); virtual ~KX_TrackToActuator();