Fix BGE bug #7532: TrackTo Actuator does not work correctly if it has a Vertex Parent...
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 14 May 2008 20:22:57 +0000 (20:22 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 14 May 2008 20:22:57 +0000 (20:22 +0000)
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_SG_NodeRelationships.h
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/SceneGraph/SG_Node.cpp
source/gameengine/SceneGraph/SG_Node.h
source/gameengine/SceneGraph/SG_ParentRelation.h

index b83d63e26bfa7d70b47f19f68997a6b630bb0293..5dae59d1d63c012ea757d577d3d869fc83a8a1a1 100644 (file)
@@ -368,7 +368,15 @@ public:
        { 
                return m_bDyna; 
        }
        { 
                return m_bDyna; 
        }
-       
+
+       /**
+        * Check if this object has a vertex parent relationship
+        */
+       bool IsVertexParent( )
+       {
+               return (m_pSGNode && m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsVertexParent());
+       }
+
        bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 
 
        bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 
 
index d83fb79ee2542a4dcd4fe39b9f58b89dd7dfbc65..e53af22408ed4f6baed770153610cba26cb56753 100644 (file)
@@ -129,6 +129,12 @@ public :
        ~KX_VertexParentRelation(
        );
 
        ~KX_VertexParentRelation(
        );
 
+               bool
+       IsVertexRelation(
+       ) { 
+               return true;
+       }
+
 private :
 
        KX_VertexParentRelation(
 private :
 
        KX_VertexParentRelation(
index 58b873672584470cec806296af6614fac2abf68d..b9792303565a35d387ca0c942910b9e17b89ec5f 100644 (file)
@@ -69,13 +69,19 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj,
        m_upflag = upflag;
        m_parentobj = 0;
        
        m_upflag = upflag;
        m_parentobj = 0;
        
-       if (m_object){
+       if (m_object)
                m_object->RegisterActuator(this);
                m_object->RegisterActuator(this);
-               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();
+       if (gameobj->isA(&KX_GameObject::Type))
+       {
+               // if the object is vertex parented, don't check parent orientation as the link is broken
+               if (!((KX_GameObject*)gameobj)->IsVertexParent()){
+                       m_parentobj = ((KX_GameObject*)gameobj)->GetParent(); // check if the object is parented 
+                       if (m_parentobj) {  
+                               // if so, store the initial local rotation
+                               // this is needed to revert the effect of the parent inverse node (TBC)
+                               m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
+                       }
                }
        }
 
                }
        }
 
@@ -180,6 +186,8 @@ KX_TrackToActuator::~KX_TrackToActuator()
 {
        if (m_object)
                m_object->UnregisterActuator(this);
 {
        if (m_object)
                m_object->UnregisterActuator(this);
+       if (m_parentobj)
+               m_parentobj->Release();
 } /* end of destructor */
 
 void KX_TrackToActuator::ProcessReplica()
 } /* end of destructor */
 
 void KX_TrackToActuator::ProcessReplica()
index 73e1686317386470873602f264751092c8baec5e..ff9a9f7f3714abc51abca6b41ee670cdb9f7a702 100644 (file)
@@ -148,6 +148,16 @@ GetRootSGParent(
        return (m_SGparent ? (const SG_Node*) m_SGparent->GetRootSGParent() : (const SG_Node*) this);
 }
 
        return (m_SGparent ? (const SG_Node*) m_SGparent->GetRootSGParent() : (const SG_Node*) this);
 }
 
+       bool
+SG_Node::
+IsVertexParent()
+{
+       if (m_parent_relation)
+       {
+               return m_parent_relation->IsVertexRelation();
+       }
+       return false;
+}
 
        void 
 SG_Node::
 
        void 
 SG_Node::
index 4808f6f7d9485d018f39a54c15a618bf8e097fd4..5cf24de68f3650a273e58089e7cf3809a275a361 100644 (file)
@@ -152,6 +152,14 @@ public:
        ) ;
 
 
        ) ;
 
 
+       /**
+        * Return vertex parent status.
+        */
+
+               bool    
+       IsVertexParent(
+       ) ;
+
        /**             
         * Update the spatial data of this node. Iterate through
         * the children of this node and update their world data.
        /**             
         * Update the spatial data of this node. Iterate through
         * the children of this node and update their world data.
index 1d211a9f39f13b73a88e5ebec257a26320be89d1..9d360d1c2747221ba0a22576b5898d289cc0feb0 100644 (file)
@@ -90,6 +90,15 @@ public :
        NewCopy(
        ) = 0;
 
        NewCopy(
        ) = 0;
 
+       /**
+        * Vertex Parent Relation are special: they don't propagate rotation
+        */
+       virtual
+               bool
+       IsVertexRelation(
+       ) { 
+               return false;
+       }
 protected :
 
        /** 
 protected :
 
        /**