Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-07-03 05:34:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-07-03 05:34:50 +0400
commit31aa43da9736a014579ec05fb68ff2051f5eb69d (patch)
tree0aee9863f0e1ca5d2dfe6661b3d8ba867c4d8714 /source
parent424141f44d1c971455d7d207ad386d1fcd7d854b (diff)
Adding GameObject setLinearVelocity(), without this interacting with objects requires them to have logic bricks to apply force which doesn't work well when the character is in a seperate blend file to the levels. (its also messy to have a script & multiple motion actuators on each object you can pickup and throw).
This is also needed for removing any force that existed before suspending dynamics - In the case of franky hanging, resuming dynamics when he fell would apply the velocity he had when grabbing making dropping to the ground work unpredictably. Also note in pydocs that enable/disable rigidbody physics doesn't work with bullet yet.
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp18
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h1
-rw-r--r--source/gameengine/PyDoc/KX_GameObject.py20
3 files changed, 36 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index ee8161702e1..993e852a7ee 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -812,6 +812,7 @@ PyMethodDef KX_GameObject::Methods[] = {
{"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_VARARGS},
{"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_VARARGS},
{"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
+ {"setLinearVelocity", (PyCFunction) KX_GameObject::sPySetLinearVelocity, METH_VARARGS},
{"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS},
{"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_VARARGS},
{"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_VARARGS},
@@ -1091,7 +1092,22 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self,
}
}
-
+PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ int local = 0;
+ PyObject* pyvect;
+
+ if (PyArg_ParseTuple(args,"O|i",&pyvect,&local)) {
+ MT_Vector3 velocity;
+ if (PyVecTo(pyvect, velocity)) {
+ setLinearVelocity(velocity, (local!=0));
+ Py_Return;
+ }
+ }
+ return NULL;
+}
PyObject* KX_GameObject::PySetVisible(PyObject* self,
PyObject* args,
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 89f4cb396d1..3a9abd2fc61 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -713,6 +713,7 @@ public:
KX_PYMETHOD(KX_GameObject,GetPosition);
KX_PYMETHOD(KX_GameObject,GetLinearVelocity);
+ KX_PYMETHOD(KX_GameObject,SetLinearVelocity);
KX_PYMETHOD(KX_GameObject,GetVelocity);
KX_PYMETHOD(KX_GameObject,GetMass);
KX_PYMETHOD(KX_GameObject,GetReactionForce);
diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py
index ec7496daa75..faadf61abb5 100644
--- a/source/gameengine/PyDoc/KX_GameObject.py
+++ b/source/gameengine/PyDoc/KX_GameObject.py
@@ -98,7 +98,7 @@ class KX_GameObject:
@return: The game object's rotation matrix
@note: When using this matrix with Blender.Mathutils.Matrix() types, it will need to be transposed.
"""
- def getLinearVelocity(local):
+ def getLinearVelocity(local = 0):
"""
Gets the game object's linear velocity.
@@ -106,11 +106,24 @@ class KX_GameObject:
ie no angular velocity component.
@type local: boolean
- @param local: - False: you get the "global" velocity ie: relative to world orientation.
+ @param local: - False: you get the "global" velocity ie: relative to world orientation (default).
- True: you get the "local" velocity ie: relative to object orientation.
@rtype: list [vx, vy, vz]
@return: the object's linear velocity.
"""
+ def setLinearVelocity(velocity, local = 0):
+ """
+ Sets the game object's linear velocity.
+
+ This method sets game object's velocity through it's centre of mass,
+ ie no angular velocity component.
+
+ @type velocity: 3d vector.
+ @param velocity: linear velocity vector.
+ @type local: boolean
+ @param local: - False: you get the "global" velocity ie: relative to world orientation (default).
+ - True: you get the "local" velocity ie: relative to object orientation.
+ """
def getVelocity(point):
"""
Gets the game object's velocity at the specified point.
@@ -158,16 +171,19 @@ class KX_GameObject:
def restoreDynamics():
"""
Resumes physics for this object.
+ @Note: The objects linear velocity will be applied from when the dynamics were suspended.
"""
def enableRigidBody():
"""
Enables rigid body physics for this object.
Rigid body physics allows the object to roll on collisions.
+ @Note: This is not working with bullet physics yet.
"""
def disableRigidBody():
"""
Disables rigid body physics for this object.
+ @Note: This is not working with bullet physics yet. The angular is removed but rigid body physics can still rotate it later.
"""
def getParent():
"""