BGE: Added 'ghost' arg to KX_GameObject.suspendDynamics() method
authorSybren A. Stüvel <sybren@stuvel.eu>
Mon, 4 May 2015 04:04:09 +0000 (12:04 +0800)
committerSybren A. Stüvel <sybren@stuvel.eu>
Mon, 4 May 2015 04:04:09 +0000 (12:04 +0800)
The implementation of this 'ghost' argument already existed in the C++
source, but wasn't exposed to Python yet.

doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h

index 7b2f68b019c98d6c61ca6d6260b906c6b72941c5..672df3728a95bf57033032e6644fe9f0198051df 100644 (file)
@@ -84,6 +84,8 @@ base class --- :class:`SCA_IObject`
 
       :type: boolean
 
+      .. seealso:: :py:meth:`suspendDynamics` and :py:meth:`restoreDynamics` allow you to change the state.
+
    .. attribute:: linearDamping
 
       The object's linear damping, also known as translational damping. Can be set simultaneously with angular damping using the :py:meth:`setDamping` method.
@@ -671,13 +673,19 @@ base class --- :class:`SCA_IObject`
       :arg angular_damping: Angular ("rotational") damping factor.
       :type angular_damping: float ∈ [0, 1]
 
-   .. method:: suspendDynamics()
+   .. method:: suspendDynamics([ghost])
 
       Suspends physics for this object.
 
+      :arg ghost: When set to `True`, collisions with the object will be ignored, similar to the "ghost" checkbox in
+          Blender. When `False` (the default), the object becomes static but still collide with other objects.
+      :type ghost: bool
+
+      .. seealso:: :py:attr:`isSuspendDynamics` allows you to inspect whether the object is in a suspended state.
+
    .. method:: restoreDynamics()
 
-      Resumes physics for this object.
+      Resumes physics for this object. Also reinstates collisions; the object will no longer be a ghost.
 
       .. note::
 
index e464883016ef6397d6d2feea0b96867d85e79713..44d9bfa0cf487c2f9de30ede99d4dce327cc02c8 100644 (file)
@@ -1907,7 +1907,7 @@ PyMethodDef KX_GameObject::Methods[] = {
        {"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_NOARGS},
        {"alignAxisToVect",(PyCFunction) KX_GameObject::sPyAlignAxisToVect, METH_VARARGS},
        {"getAxisVect",(PyCFunction) KX_GameObject::sPyGetAxisVect, METH_O},
-       {"suspendDynamics", (PyCFunction)KX_GameObject::sPySuspendDynamics,METH_NOARGS},
+       {"suspendDynamics", (PyCFunction)KX_GameObject::sPySuspendDynamics, METH_VARARGS},
        {"restoreDynamics", (PyCFunction)KX_GameObject::sPyRestoreDynamics,METH_NOARGS},
        {"enableRigidBody", (PyCFunction)KX_GameObject::sPyEnableRigidBody,METH_NOARGS},
        {"disableRigidBody", (PyCFunction)KX_GameObject::sPyDisableRigidBody,METH_NOARGS},
@@ -3318,10 +3318,16 @@ PyObject *KX_GameObject::PyApplyImpulse(PyObject *args)
 
 
 
-PyObject *KX_GameObject::PySuspendDynamics()
+PyObject *KX_GameObject::PySuspendDynamics(PyObject *args)
 {
+       bool ghost = false;
+
+       if (!PyArg_ParseTuple(args, "|b", &ghost))
+               return NULL;
+
        if (GetPhysicsController())
-               GetPhysicsController()->SuspendDynamics();
+               GetPhysicsController()->SuspendDynamics(ghost);
+
        Py_RETURN_NONE;
 }
 
index 9b85572bec2e772574c4f6dfb680938b68cfb8d5..9c081b449ecffdd28a6dbabe88d9622dcf028fba 100644 (file)
@@ -1005,7 +1005,7 @@ public:
        KX_PYMETHOD_O(KX_GameObject,SetState);
        KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
        KX_PYMETHOD_O(KX_GameObject,GetAxisVect);
-       KX_PYMETHOD_NOARGS(KX_GameObject,SuspendDynamics);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SuspendDynamics);
        KX_PYMETHOD_NOARGS(KX_GameObject,RestoreDynamics);
        KX_PYMETHOD_NOARGS(KX_GameObject,EnableRigidBody);
        KX_PYMETHOD_NOARGS(KX_GameObject,DisableRigidBody);