Revision: 17753
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17753
Author:   campbellbarton
Date:     2008-12-09 05:13:23 +0100 (Tue, 09 Dec 2008)

Log Message:
-----------
patch from Mitchell Stokes
#18045] [patch] A patch that exposes the rest of the motion functions of 
KX_GameObject to Python.

*applyForce     => setForce
*applyTorque    => setTorque
*applyRotation  => setDRot
*applyMovement  => setDLoc

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-12-09 
04:02:18 UTC (rev 17752)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2008-12-09 
04:13:23 UTC (rev 17753)
@@ -615,6 +615,7 @@
                m_pPhysicsController1->SetAngularVelocity(ang_vel,local);
 }
 
+
 void KX_GameObject::ResolveCombinedVelocities(
        const MT_Vector3 & lin_vel,
        const MT_Vector3 & ang_vel,
@@ -969,6 +970,10 @@
        {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, 
METH_NOARGS},
        {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
        {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, 
METH_O},
+       {"applyForce", (PyCFunction)    KX_GameObject::sPyApplyForce, 
METH_VARARGS},
+       {"applyTorque", (PyCFunction)   KX_GameObject::sPyApplyTorque, 
METH_VARARGS},
+       {"applyRotation", (PyCFunction) KX_GameObject::sPyApplyRotation, 
METH_VARARGS},
+       {"applyMovement", (PyCFunction) KX_GameObject::sPyApplyMovement, 
METH_VARARGS},
        {"getLinearVelocity", (PyCFunction) 
KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
        {"setLinearVelocity", (PyCFunction) 
KX_GameObject::sPySetLinearVelocity, METH_VARARGS},
        {"getAngularVelocity", (PyCFunction) 
KX_GameObject::sPyGetAngularVelocity, METH_VARARGS},
@@ -1261,7 +1266,66 @@
        return SCA_IObject::_setattr(attr, value);
 }
 
+PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args)
+{
+       int local = 0;
+       PyObject* pyvect;
 
+       if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
+               MT_Vector3 force;
+               if (PyVecTo(pyvect, force)) {
+                       ApplyForce(force, (local!=0));
+                       Py_RETURN_NONE;
+               }
+       }
+       return NULL;
+}
+
+PyObject* KX_GameObject::PyApplyTorque(PyObject* self, PyObject* args)
+{
+       int local = 0;
+       PyObject* pyvect;
+
+       if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
+               MT_Vector3 torque;
+               if (PyVecTo(pyvect, torque)) {
+                       ApplyTorque(torque, (local!=0));
+                       Py_RETURN_NONE;
+               }
+       }
+       return NULL;
+}
+
+PyObject* KX_GameObject::PyApplyRotation(PyObject* self, PyObject* args)
+{
+       int local = 0;
+       PyObject* pyvect;
+
+       if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
+               MT_Vector3 rotation;
+               if (PyVecTo(pyvect, rotation)) {
+                       ApplyRotation(rotation, (local!=0));
+                       Py_RETURN_NONE;
+               }
+       }
+       return NULL;
+}
+
+PyObject* KX_GameObject::PyApplyMovement(PyObject* self, PyObject* args)
+{
+       int local = 0;
+       PyObject* pyvect;
+
+       if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) {
+               MT_Vector3 movement;
+               if (PyVecTo(pyvect, movement)) {
+                       ApplyMovement(movement, (local!=0));
+                       Py_RETURN_NONE;
+               }
+       }
+       return NULL;
+}
+
 PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args)
 {
        // only can get the velocity if we have a physics object connected to 
us...

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-12-09 
04:02:18 UTC (rev 17752)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2008-12-09 
04:13:23 UTC (rev 17753)
@@ -772,6 +772,10 @@
        KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
        KX_PYMETHOD_O(KX_GameObject,SetPosition);
        KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyForce);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyTorque);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyRotation);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyMovement);
        KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
        KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
        KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2008-12-09 
04:02:18 UTC (rev 17752)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2008-12-09 
04:13:23 UTC (rev 17753)
@@ -123,6 +123,50 @@
                @return: The game object's rotation matrix
                @note: When using this matrix with Blender.Mathutils.Matrix() 
types, it will need to be transposed.
                """
+       def applyMovement(movement, local = 0):
+               """
+               Sets the game object's movement.
+               
+               @type movement: 3d vector.
+               @param movement: movement vector.
+               @type local: boolean
+               @param local: - False: you get the "global" movement ie: 
relative to world orientation (default).
+                             - True: you get the "local" movement ie: relative 
to object orientation.
+               """     
+       def applyRotation(movement, local = 0):
+               """
+               Sets the game object's rotation.
+               
+               @type rotation: 3d vector.
+               @param rotation: rotation vector.
+               @type local: boolean
+               @param local: - False: you get the "global" rotation ie: 
relative to world orientation (default).
+                                         - True: you get the "local" rotation 
ie: relative to object orientation.
+               """     
+       def applyForce(force, local = 0):
+               """
+               Sets the game object's force.
+               
+               This requires a dynamic object.
+               
+               @type force: 3d vector.
+               @param force: force vector.
+               @type local: boolean
+               @param local: - False: you get the "global" force ie: relative 
to world orientation (default).
+                                         - True: you get the "local" force ie: 
relative to object orientation.
+               """     
+       def applyTorque(torque, local = 0):
+               """
+               Sets the game object's torque.
+               
+               This requires a dynamic object.
+               
+               @type torque: 3d vector.
+               @param torque: torque vector.
+               @type local: boolean
+               @param local: - False: you get the "global" torque ie: relative 
to world orientation (default).
+                                         - True: you get the "local" torque 
ie: relative to object orientation.
+               """
        def getLinearVelocity(local = 0):
                """
                Gets the game object's linear velocity.
@@ -143,6 +187,8 @@
                This method sets game object's velocity through it's centre of 
mass,
                ie no angular velocity component.
                
+               This requires a dynamic object.
+               
                @type velocity: 3d vector.
                @param velocity: linear velocity vector.
                @type local: boolean
@@ -163,6 +209,8 @@
                """
                Sets the game object's angular velocity.
                
+               This requires a dynamic object.
+               
                @type velocity: 3d vector.
                @param velocity: angular velocity vector.
                @type local: boolean


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to