[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15413] trunk/blender/source/gameengine: 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.

Campbell Barton ideasman42 at gmail.com
Thu Jul 3 03:35:58 CEST 2008


Revision: 15413
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15413
Author:   campbellbarton
Date:     2008-07-03 03:34:50 +0200 (Thu, 03 Jul 2008)

Log Message:
-----------
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.

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-07-02 21:57:18 UTC (rev 15412)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-07-03 01:34:50 UTC (rev 15413)
@@ -812,6 +812,7 @@
 	{"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,8 +1092,23 @@
 	}
 }
 
+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,
 									  PyObject* kwds)

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-07-02 21:57:18 UTC (rev 15412)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-07-03 01:34:50 UTC (rev 15413)
@@ -713,6 +713,7 @@
 
 	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);

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-07-02 21:57:18 UTC (rev 15412)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-07-03 01:34:50 UTC (rev 15413)
@@ -98,7 +98,7 @@
 		@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 @@
 		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 @@
 	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():
 		"""





More information about the Bf-blender-cvs mailing list