This weekend I experimented a bit and came up with a trial implementation of JBullet on Processing. It's a port of the HelloWorld implementation you can find on http://www.bulletphysics.com/mediawiki-1.5.8/index.php?title=Hello_World .
Given the great work by jezek2, one could extend the use of this library to more sophisticated stuff, like the examples on http://jbullet.advel.cz/ (vehicles, hinges, collision responses with inertia...). At this stage, the example works (after having copied jbullet.jar to libraries/jbullet/library/ and with test version 0154), but I'm not sure if I did it all the right way. So, if you know more, please let me know.
Jelp
Code:
import com.bulletphysics.*;
import com.bulletphysics.collision.dispatch.*;
import com.bulletphysics.collision.shapes.*;
import com.bulletphysics.collision.broadphase.*;
import com.bulletphysics.dynamics.*;
import com.bulletphysics.dynamics.constraintsolver.*;
import com.bulletphysics.linearmath.*;
import javax.vecmath.*;
CollisionDispatcher myCd;
BroadphaseInterface myBi;
ConstraintSolver myCs;
CollisionConfiguration myCc;
RigidBody groundRigidBody;
RigidBody fallRigidBody;
int maxProxies = 1024;
Vector3f worldAabbMin = new Vector3f(-10000,-10000,-10000);
Vector3f worldAabbMax = new Vector3f(10000,10000,10000);
DynamicsWorld myWorld;
Transform myTransform;
void setup(){
size(400,400);
myCc = new DefaultCollisionConfiguration();
myBi = new AxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
myCd = new CollisionDispatcher(myCc);
myCs = new SequentialImpulseConstraintSolver();
myWorld = new DiscreteDynamicsWorld(myCd, myBi, myCs, myCc);
myWorld.setGravity(new Vector3f(0,-10,0));
//ADD STATIC GROUND
CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0,1,0), 1); //1 m thick under ground
myTransform = new Transform(); myTransform.origin.set(new Vector3f(0,-1,0)); myTransform.setRotation(new Quat4f(0,0,0,1));
DefaultMotionState groundMotionState = new DefaultMotionState(myTransform);
RigidBodyConstructionInfo groundCI = new RigidBodyConstructionInfo(0, groundMotionState, groundShape, new Vector3f(0,0,0));
RigidBody groundRigidBody = new RigidBody(groundCI);
myWorld.addRigidBody(groundRigidBody);
//ADD FALLING SPHERE
CollisionShape fallShape = new SphereShape(1);
myTransform = new Transform(); myTransform.origin.set(new Vector3f(0,50,0)); myTransform.setRotation(new Quat4f(0,0,0,1));
DefaultMotionState fallMotionState = new DefaultMotionState(myTransform);
float myFallMass = 1; Vector3f myFallInertia = new Vector3f(0,0,0);
fallShape.calculateLocalInertia(myFallMass, myFallInertia);
RigidBodyConstructionInfo fallRigidBodyCI = new RigidBodyConstructionInfo(myFallMass, fallMotionState, fallShape, myFallInertia);
fallRigidBody = new RigidBody(fallRigidBodyCI);
myWorld.addRigidBody(fallRigidBody);
}
void draw(){
myWorld.stepSimulation(1.0/60.0,8);
myTransform = new Transform();
myTransform = fallRigidBody.getMotionState().getWorldTransform(myTransform);
//background(#FFFFFF);
ellipse(frameCount, myTransform.origin.y*5, 2,2);
println(myTransform.origin.y);
}