[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48748] trunk/blender: As a response to issue [#28483] "Enable/ Disable Rigid Body actuator do nothing" reported by Jean-Francois Gallant ( pyroevil), I' m adding preliminary support to enable and disable rigid body physics on dynamic objects .

Mitchell Stokes mogurijin at gmail.com
Mon Jul 9 06:57:24 CEST 2012


Revision: 48748
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48748
Author:   moguri
Date:     2012-07-09 04:57:21 +0000 (Mon, 09 Jul 2012)
Log Message:
-----------
As a response to issue [#28483] "Enable/Disable Rigid Body actuator do nothing" reported by Jean-Francois Gallant (pyroevil), I'm adding preliminary support to enable and disable rigid body physics on dynamic objects. This is can be done via the Edit Object Actuator or through KX_GameObject.enableRigidBody() and KX_GameObject.disableRigidBody(). Thanks to Sergej Reich for his help with the patch.

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.types.rst
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h

Modified: trunk/blender/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2012-07-09 04:32:37 UTC (rev 48747)
+++ trunk/blender/doc/python_api/rst/bge.types.rst	2012-07-09 04:57:21 UTC (rev 48748)
@@ -1335,18 +1335,10 @@
 
       Rigid body physics allows the object to roll on collisions.
 
-      .. note::
-         
-         This is not working with bullet physics yet.
-
    .. method:: 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.
-
    .. method:: setParent(parent, compound=True, ghost=True)
 
       Sets this object's parent.

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2012-07-09 04:32:37 UTC (rev 48747)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2012-07-09 04:57:21 UTC (rev 48748)
@@ -232,6 +232,7 @@
 }
 void	KX_BulletPhysicsController::setRigidBody(bool rigid)
 {
+	CcdPhysicsController::setRigidBody(rigid);
 }
 
 /* This function dynamically adds the collision shape of another controller to

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2012-07-09 04:32:37 UTC (rev 48747)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2012-07-09 04:57:21 UTC (rev 48748)
@@ -118,6 +118,12 @@
 
 	ci.m_MotionState = motionstate;
 	ci.m_gravity = btVector3(0,0,0);
+	ci.m_linearFactor = btVector3(objprop->m_lockXaxis? 0 : 1,
+									objprop->m_lockYaxis? 0 : 1,
+									objprop->m_lockZaxis? 0 : 1);
+	ci.m_angularFactor = btVector3(objprop->m_lockXRotaxis? 0 : 1,
+									objprop->m_lockYRotaxis? 0 : 1,
+									objprop->m_lockZRotaxis? 0 : 1);
 	ci.m_localInertiaTensor =btVector3(0,0,0);
 	ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
 	ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min;
@@ -441,16 +447,8 @@
 		{
 			if (objprop->m_angular_rigidbody)
 			{
-				btVector3 linearFactor(
-					objprop->m_lockXaxis? 0 : 1,
-					objprop->m_lockYaxis? 0 : 1,
-					objprop->m_lockZaxis? 0 : 1);
-				btVector3 angularFactor(
-					objprop->m_lockXRotaxis? 0 : 1,
-					objprop->m_lockYRotaxis? 0 : 1,
-					objprop->m_lockZRotaxis? 0 : 1);
-				rbody->setLinearFactor(linearFactor);
-				rbody->setAngularFactor(angularFactor);
+				rbody->setLinearFactor(ci.m_linearFactor);
+				rbody->setAngularFactor(ci.m_angularFactor);
 			}
 
 			if (rbody && objprop->m_disableSleeping)

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2012-07-09 04:32:37 UTC (rev 48747)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2012-07-09 04:57:21 UTC (rev 48748)
@@ -1294,17 +1294,16 @@
 		// dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted 
 void		CcdPhysicsController::setRigidBody(bool rigid)
 {
-	if (!rigid)
+	btRigidBody* body = GetRigidBody();
+	if (body)
 	{
-		btRigidBody* body = GetRigidBody();
-		if (body)
-		{
-			//fake it for now
-			btVector3 inertia = body->getInvInertiaDiagLocal();
-			inertia[1] = 0.f;
-			body->setInvInertiaDiagLocal(inertia);
-			body->updateInertiaTensor();
+		m_cci.m_bRigid = rigid;
+		if (!rigid) {
+			body->setAngularFactor(0.f);
+			body->setAngularVelocity(btVector3(0.f, 0.f, 0.f));
 		}
+		else
+			body->setAngularFactor(m_cci.m_angularFactor);
 	}
 }
 

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h	2012-07-09 04:32:37 UTC (rev 48747)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h	2012-07-09 04:57:21 UTC (rev 48748)
@@ -229,6 +229,8 @@
 	    :m_localInertiaTensor(1.f, 1.f, 1.f),
 		m_gravity(0,0,0),
 		m_scaling(1.f,1.f,1.f),
+		m_linearFactor(0.f, 0.f, 0.f),
+		m_angularFactor(0.f, 0.f, 0.f),
 		m_mass(0.f),
 		m_clamp_vel_min(-1.f),
 		m_clamp_vel_max(-1.f),
@@ -292,6 +294,8 @@
 	btVector3	m_localInertiaTensor;
 	btVector3	m_gravity;
 	btVector3	m_scaling;
+	btVector3	m_linearFactor;
+	btVector3	m_angularFactor;
 	btScalar	m_mass;
 	btScalar	m_clamp_vel_min;  
 	btScalar	m_clamp_vel_max;  




More information about the Bf-blender-cvs mailing list