[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29730] branches/soc-2010-aligorith-2: == Bullet SoC - New API Integrated ==

Joshua Leung aligorith at gmail.com
Sun Jun 27 08:08:22 CEST 2010


Revision: 29730
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29730
Author:   aligorith
Date:     2010-06-27 08:08:22 +0200 (Sun, 27 Jun 2010)

Log Message:
-----------
== Bullet SoC - New API Integrated ==

Changes:
* Replaced calls to the old API with calls to the new one
* Removed temp hack code from Bullet C-API
* Tweaked scons files more so that the libs link ok. This currently doesn't work ok if compiling without Bullet. Requires a bit more work to figure out what to do in that case.
* Removed unneeded cruft from RigidBody structs 

Current Status:
- We're now getting some minimal reverse movement now during reverse playback, but not as much as much as it should be. I'll need to investigate further why this is the case.
- Some of the hackier aspects of the current integration now need to be cleaned up to work with the new API

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
    branches/soc-2010-aligorith-2/source/blender/SConscript
    branches/soc-2010-aligorith-2/source/blender/blenkernel/SConscript
    branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h
    branches/soc-2010-aligorith-2/source/blender/rigidbody/SConscript
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

Modified: branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
===================================================================
--- branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp	2010-06-27 06:08:22 UTC (rev 29730)
@@ -96,18 +96,8 @@
 	btBroadphaseInterface*		pairCache = new (mem)btAxisSweep3(physicsSdk->m_worldAabbMin,physicsSdk->m_worldAabbMax);
 	mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
 	btConstraintSolver*			constraintSolver = new(mem) btSequentialImpulseConstraintSolver();
-
-#if 0 // xxx: original bullet code
 	mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
 	return (plDynamicsWorldHandle) new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
-#else // xxx: TEMP CODE TO CHECK THAT THIS ALL WORKS - Bullet SoC
-	mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
-	btDynamicsWorld* 			dynamicsWorld = new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
-
-	dynamicsWorld->setGravity(btVector3(0, 0, -10));
-	
-	return (plDynamicsWorldHandle)dynamicsWorld;
-#endif // xxx: TEMP CODE TO CHECK THAT THIS ALL WORKS - Bullet SoC
 }
 void           plDeleteDynamicsWorld(plDynamicsWorldHandle world)
 {

Modified: branches/soc-2010-aligorith-2/source/blender/SConscript
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/SConscript	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/SConscript	2010-06-27 06:08:22 UTC (rev 29730)
@@ -19,7 +19,8 @@
             'modifiers/SConscript',
             'ikplugin/SConscript',
             'windowmanager/SConscript',
-            'blenfont/SConscript'])
+            'blenfont/SConscript',
+			'rigidbody/SConscript'])
 
 
 
@@ -37,6 +38,3 @@
 
 if env['WITH_BF_COLLADA']:
     SConscript (['collada/SConscript'])
-
-if env['WITH_BF_BULLET']:
-	SConscript (['rigidbody/SConscript'])

Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/SConscript
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/SConscript	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/SConscript	2010-06-27 06:08:22 UTC (rev 29730)
@@ -9,6 +9,7 @@
 incs += ' ../imbuf ../ikplugin ../avi #/intern/elbeem/extern ../nodes ../modifiers'
 incs += ' #/intern/iksolver/extern ../blenloader'
 incs += ' #/extern/bullet2/src'
+incs += ' ../rigidbody'
 incs += ' #/intern/opennl/extern #/intern/bsp/extern'
 incs += ' ../gpu #/extern/glew/include'
 incs += ' #/intern/smoke/extern'

Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-27 06:08:22 UTC (rev 29730)
@@ -37,7 +37,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "Bullet-C-Api.h"
+#include "RBI_api.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_group_types.h"
@@ -69,8 +69,7 @@
 		return;
 		
 	/* free physics references */
-	plDeletePhysicsSdk(rbw->physics_sdk); // XXX: this is needed for Bullet's C-API, but isn't a great idea in long run... 
-	plDeleteDynamicsWorld(rbw->physics_world);
+	rbDWorldDelete(rbw->physics_world);
 	
 	/* free rigidbody world itself */
 	BLI_freelinkN(&scene->rigidbody_worlds, rbw);
@@ -118,10 +117,10 @@
 	}
 #endif
 	
-	plDeleteRigidBody(rbo->physics_object);
+	rbBodyDelete(rbo->physics_object);
 	rbo->physics_object = NULL;
 	
-	plDeleteShape(rbo->physics_shape);
+	rbShapeDelete(rbo->physics_shape);
 	rbo->physics_shape = NULL;
 }
 
@@ -140,11 +139,11 @@
 		case RB_SHAPE_BOX: // includes ground planes...
 			// just take the bounding box dimensions per axis...
 			// XXX: do we need to switch y and z due to diff coordinate systems being used?
-			rbo->physics_shape = plNewBoxShape(dims[0], dims[1], dims[2]);
+			rbo->physics_shape = rbShapeNewBox(dims[0], dims[1], dims[2]);
 			break;
 		case RB_SHAPE_SPHERE:
 			// just take the maximum bounding box dimension to fit everything
-			rbo->physics_shape = plNewSphereShape(MAX2(dims[0], MAX2(dims[1], dims[2])));
+			rbo->physics_shape = rbShapeNewSphere(MAX2(dims[0], MAX2(dims[1], dims[2])));
 			break;
 			
 		// XXX: figure out how to implement these later...
@@ -180,7 +179,7 @@
 	if (rbo->physics_object) {
 		/* get rid of it and rebuild? */
 		if (force)
-			plDeleteRigidBody(rbo->physics_object);
+			rbBodyDelete(rbo->physics_object);
 		else
 			return;
 	}
@@ -188,14 +187,13 @@
 	/* make sure collision shape exists */
 	if ((rbo->physics_shape == NULL) || (force)) {
 		/* remove existing shape for good measure, then build new one */
-		plDeleteShape(rbo->physics_shape);
+		rbShapeDelete(rbo->physics_shape);
 		rigidbody_validate_sim_shape(ob, rbo);
 	}
 	
 	/* create new rigidbody object instance */
-	// XXX: what do we store for userdata (first arg)? set this to the object that this represents for now...
 	// XXX: mass should be calculated via some helper func to get 0.0 when we don't we want 'static' control
-	rbo->physics_object = plCreateRigidBody(ob, rbo->mass, rbo->physics_shape);
+	rbo->physics_object = rbBodyNew(rbo->physics_shape, rbo->mass, ob->obmat);
 }	
 
 /* Add the specified RigidBodyOb to the given physics world */
@@ -203,7 +201,7 @@
 {
 	// FIXME: this really doesn't take into account the problems with one object being in multiple sims
 	// at once... that will need further work later...
-	plAddRigidBody(rbw->physics_world, rbo->physics_object);
+	rbDWorldAddBody(rbw->physics_world, rbo->physics_object);
 }
 
 /* --------------------- */
@@ -218,11 +216,10 @@
 		
 	/* if there's an existing world, replace it */
 	if (rbw->physics_world) 
-		plDeleteDynamicsWorld(rbw->physics_world);
+		rbDWorldDelete(rbw->physics_world);
 		
 	/* create new sim world */
-	rbw->physics_sdk = plNewBulletSdk(); // XXX: this is needed for Bullet's C-API, but isn't a great idea in long run... 
-	rbw->physics_world = plCreateDynamicsWorld(rbw->physics_sdk);
+	rbw->physics_world = rbDWorldCreate(scene->physics_settings.gravity);
 }
 
 /* --------------------- */
@@ -405,7 +402,6 @@
 	}
 	
 	/* flush current scene settings to the physics world */
-	// TODO: could some of this be automated using motionstates?
 	for (go = rbw->group->gobject.first; go; go = go->next) {
 		Object *ob = go->ob;
 		
@@ -431,7 +427,7 @@
 			 *	- Bullet can't cope with scaling in transforms, so need to supply a normalised copy?
 			 */
 			// XXX: the standard object matrix has scaling included... for now, just make sure no scaling goes through...
-			plSetOpenGLMatrix(rbo->physics_object, (plReal*)ob->obmat);
+			rbSetTransformMatrix(rbo->physics_object, ob->obmat);
 		}
 	}
 	
@@ -445,7 +441,7 @@
 	printf("\n");
 	
 	/* perform one step of sim */
-	plStepSimulation(rbw->physics_world, timestep);
+	rbStepSimulation(rbw->physics_world, timestep);
 	
 	
 	/* grab current scene settings from the physics world */
@@ -458,14 +454,10 @@
 			
 			/* get transform matrix from Bullet */
 			// XXX: if we supplied a normalised copy to Bullet, we'll need to reapply scale here...
-			plGetOpenGLMatrix(rbo->physics_object, (plReal*)ob->obmat);
+			rbGetTransformMatrix(rbo->physics_object, ob->obmat);
 			
-			// DEBUG 
-			{
-				float loc[3];
-				plGetPosition(rbo->physics_object, loc);
-				printf("\t%s - (%f, %f, %f) \n", ob->id.name+2, loc[0], loc[1], loc[2]);
-			}
+			// DEBUG
+			printf("\t%s: new pos - %f %f %f \n", ob->id.name+2, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]);
 		}
 		else
 			printf("\tgroup object invalid %p \n", go->ob);

Modified: branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-06-27 06:08:22 UTC (rev 29730)
@@ -66,9 +66,6 @@
 	
 	/* References to Physics Sim objects. Exist at runtime only ---------------------- */
 	void *physics_world;		/* Physics sim world (i.e. btDiscreteDynamicsWorld) */
-	
-		// XXX: review this... the exact settings still need a bit more work...
-	void *physics_sdk;			// needed for creating physics world
 } RigidBodyWorld;
 
 /* Flags for RigidBodyWorld */

Modified: branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h	2010-06-27 06:08:22 UTC (rev 29730)
@@ -1,5 +1,5 @@
 /**
- * $Id: rb_api.h $
+ * $Id: RBI_api.h $
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -100,7 +100,7 @@
 
 /* Create new RigidBody instance */
 // TODO: what other standard/useful settings to add here?
-extern rbRigidBody *rbBodyNew(rbCollisionShape *cshape, float mass, float mat[4][4]);
+extern rbRigidBody *rbBodyNew(rbCollisionShape *cshape, float mass, const float mat[4][4]);
 
 /* Delete the given RigidBody instance */
 extern void rbBodyDelete(rbRigidBody *body);

Modified: branches/soc-2010-aligorith-2/source/blender/rigidbody/SConscript
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/rigidbody/SConscript	2010-06-27 05:39:55 UTC (rev 29729)
+++ branches/soc-2010-aligorith-2/source/blender/rigidbody/SConscript	2010-06-27 06:08:22 UTC (rev 29730)
@@ -27,6 +27,9 @@
 
 Import ('env')
 
+# XXX: we need a contingency plan for when not compiling with Bullet,
+# since this module will always get included... 
+# This problem will also apply to other engines at a later date too...
 sources = env.Glob('*.cpp')
 
 incs = '../blenlib ../../../intern/guardedalloc ../../../extern/bullet2/src'

Modified: branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list