Added access for adjusting timeOffset value at runtime, used for apricot (Franky...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jun 2008 17:12:49 +0000 (17:12 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jun 2008 17:12:49 +0000 (17:12 +0000)
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_SG_NodeRelationships.h
source/gameengine/PyDoc/KX_GameObject.py
source/gameengine/SceneGraph/SG_Node.cpp
source/gameengine/SceneGraph/SG_Node.h
source/gameengine/SceneGraph/SG_ParentRelation.h
source/gameengine/SceneGraph/SG_Spatial.cpp
source/gameengine/SceneGraph/SG_Spatial.h

index c192cd012614a59425e06b0540eacac1dbd2ddd3..6fde94fec5321c16eb2bc752fce0f58e613465f3 100644 (file)
@@ -911,6 +911,14 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr)
                
        if (attr == "name")
                return PyString_FromString(m_name.ReadPtr());
+       if (attr == "timeOffset") {
+               if (m_pSGNode->GetSGParent()->IsSlowParent()) {
+                       return PyFloat_FromDouble(static_cast<KX_SlowParentRelation *>(m_pSGNode->GetSGParent()->GetParentRelation())->GetTimeOffset());
+               } else {
+                       return PyFloat_FromDouble(0.0);
+               }
+       }
+       
        
        _getattr_up(SCA_IObject);
 }
@@ -932,6 +940,19 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value)       // _setattr
                        return 0;
                }
        }
+
+       if (PyFloat_Check(value))
+       {
+               MT_Scalar val = PyFloat_AsDouble(value);
+               if (attr == "timeOffset") {
+                       if (m_pSGNode->GetSGParent()->IsSlowParent()) {
+                               static_cast<KX_SlowParentRelation *>(m_pSGNode->GetSGParent()->GetParentRelation())->SetTimeOffset(val);
+                               return 0;
+                       } else {
+                               return 0;
+                       }               
+               }
+       }
        
        if (PySequence_Check(value))
        {
index e53af22408ed4f6baed770153610cba26cb56753..faa650106c800284de1e3d492ed4906de8182435 100644 (file)
@@ -177,8 +177,23 @@ public :
        NewCopy(
        );
 
+               MT_Scalar
+       GetTimeOffset(
+       ) { return m_relax; }
+       
+               void
+       SetTimeOffset(
+               MT_Scalar relaxation
+       ) { m_relax = relaxation; }
+
        ~KX_SlowParentRelation(
        );
+       
+               bool
+       IsSlowRelation(
+       ) { 
+               return true;
+       }
 
 private :
 
index 8d29a70438084f82a1fa14f4ff416686dba1f31c..678df59e4a92e3ab41eaaab26727b4e1bf714f81 100644 (file)
@@ -22,6 +22,8 @@ class KX_GameObject:
        @type orientation: 3x3 Matrix [[float]]
        @ivar scaling: The object's scaling factor. list [sx, sy, sz]
        @type scaling: list [sx, sy, sz]
+       @ivar timeOffset: adjust the slowparent delay at runtime.
+       @type timeOffset: float
        """
        
        def setVisible(visible):
index ff9a9f7f3714abc51abca6b41ee670cdb9f7a702..4e90d7c46536c5724f5f27118a9ff2142f367505 100644 (file)
@@ -159,6 +159,17 @@ IsVertexParent()
        return false;
 }
 
+       bool
+SG_Node::
+IsSlowParent()
+{
+       if (m_parent_relation)
+       {
+               return m_parent_relation->IsSlowRelation();
+       }
+       return false;
+}
+
        void 
 SG_Node::
 DisconnectFromParent(
index 5cf24de68f3650a273e58089e7cf3809a275a361..f86e3046d93ae8e33cc91a083692b1d8241cb5f3 100644 (file)
@@ -159,6 +159,14 @@ public:
                bool    
        IsVertexParent(
        ) ;
+       
+       /**
+        * Return slow parent status.
+        */
+
+               bool    
+       IsSlowParent(
+       ) ;
 
        /**             
         * Update the spatial data of this node. Iterate through
index 9d360d1c2747221ba0a22576b5898d289cc0feb0..6507cb98519d245210555a2794edb8065f08b189 100644 (file)
@@ -99,6 +99,16 @@ public :
        ) { 
                return false;
        }
+       
+       /**
+        * Need this to see if we are able to adjust time-offset from the python api
+        */
+       virtual
+               bool
+       IsSlowRelation(
+       ) { 
+               return false;
+       }
 protected :
 
        /** 
index 18049592977535ad62465d7e2824ab65eceab554..5ba116e59db0aeecec23c77d8f39c58078ba2364 100644 (file)
@@ -87,6 +87,13 @@ SG_Spatial::
        delete (m_parent_relation);
 }
 
+       SG_ParentRelation *
+SG_Spatial::
+GetParentRelation(
+){
+       return m_parent_relation;
+}
+
        void
 SG_Spatial::
 SetParentRelation(
index a70784472a7deb9ddfdf2e673d3c66aa3c4279fd..28848b0f933653b89fd83bbfe6cb04859771d9eb 100644 (file)
@@ -83,6 +83,10 @@ public:
        SetParentRelation(
                SG_ParentRelation *relation
        );
+       
+               SG_ParentRelation *
+       GetParentRelation(
+       );
 
 
        /**