We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Jbullet (physics) on Processing
Page Index Toggle Pages: 1
Jbullet (physics) on Processing (Read 2722 times)
Jbullet (physics) on Processing
Oct 27th, 2008, 1:12am
 
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);
}
Re: Jbullet (physics) on Processing
Reply #1 - Oct 27th, 2008, 2:25pm
 
very useful! i'm sure many people will be happy to see this Smiley
Re: Jbullet (physics) on Processing
Reply #2 - Dec 15th, 2008, 11:33pm
 
I thought I would update you: http://www.vimeo.com/2534691 .
Page Index Toggle Pages: 1