Okay guys, here's another set of changes for the JBullet integration. Feel free to ping me with critiques. If I haven't heard from anybody by the weekend, I'll go ahead and commit.
It's a long-ish one, so here goes.
Fixes include:
-Better null-checking in collisions and PendingContact classes
-PhysicsSpace.collide() method implemented
-PhysicsSpace.pick() method implementd
-PhysicsPicker implemented
-ContactCallbacks cleaned up a bit.
-PhysicsCallbacks wired up
-Fixed (as in 0 axis) Joints implemented
-CollisionGroup handling fixed. (had a wacky bit o' logic in the last checkin)
-Attempted to fix 'applyForce' and 'applyTorque' methods, but with only sporadic success.
-Fixed some more bugs with mass calculations that caused JBullet to interpret dynamic nodes as static.
-Added 'worldBounds' and 'maxObject' properties to PhysicsSpace to allow for more optimization
-Added optimization code to auto-switch to better broadphase sweeping algorithms when world bounds are specified.
-Added better null-checking in com.jmex.physics.material.MaterialContactCallback. (get material from node when geometries aren't available.)
Code changes:
com.jmex.physics.PhysicsSpace:
added the following code:
private Vector3f worldMinBounds = new Vector3f(Float.MIN_VALUE,Float.MIN_VALUE,Float.MIN_VALUE);
private Vector3f worldMaxBounds = new Vector3f(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE);
/**
* Change the declared boundaries of the physics world. This value is used for optimization only and
* will not actually limit the placement of objects. However, tuning world boundaries MAY for some
* implementations result in a performance improvement. Default values at start are Float.MIN_VALUE and
* Float.MAX_VALUE respectively for all axes.
*
* @param min The minimum boundary of the physics space.
* @param max The maximum boundary of the physics space.
*/
public void setWorldBounds(Vector3f min, Vector3f max)
{
if(min!=null)
worldMinBounds.set(min);
if(max!=null)
worldMaxBounds.set(max);
}
public Vector3f getWorldMinBound(Vector3f store)
{
if(store==null)
store = new Vector3f();
store.set(worldMinBounds);
return store;
}
public Vector3f getWorldMaxBound(Vector3f store)
{
if(store==null)
store = new Vector3f();
store.set(worldMaxBounds);
return store;
}
private int maxObjects = 10000; //This default can change, if need be. Seems like a decent start tho.
public int getMaxObjects() {
return maxObjects;
}
/**
* sets the maximum number of physics objects (i.e. physics nodes) in the world. This number MAY
* be a hard limit depending on the implementation, but can be invaluable for tuning and performance
* improvement purposes.
*
* @return
*/
public void setMaxObjects(int maxObjects) {
this.maxObjects = maxObjects;
}
com.jmex.physics.material.MaterialContactCallback:
changed lines 65 and 66 to:
Material m1 = (contact.getGeometry1()!=null)?contact.getGeometry1().getMaterial():contact.getNode1().getMaterial();
Material m2 = (contact.getGeometry2()!=null)?contact.getGeometry2().getMaterial():contact.getNode2().getMaterial();
com.jmex.physics.impl.jbullet.callback.JBulletPendingContactCache:
changed lines 18 and 19 to:
ShapeProxy sp1=(ShapeProxy)obj1.getLastTempProxyCollisionShape();
ShapeProxy sp2=(ShapeProxy)obj2.getLastTempProxyCollisionShape();
ContactSet cs1 = new ContactSet((sp1==null)?null:sp1.getJmeShape(),obj1.getParentNode());
ContactSet cs2 = new ContactSet((sp2==null)?null:sp2.getJmeShape(),obj2.getParentNode());
com.jmex.physics.impl.jbullet.JBulletCollisionGroup:
inserted at line 11:
this.collidesWith(this, true);
com.jmex.physics.impl.jbullet.JBulletPhysicsNode,
com.jmex.physics.impl.jbullet.JBulletStaticPhysicsNode:
changed 'getBody()' method to return JBulletRigidBody
com.jmex.physics.impl.jbullet.JBulletRigidBody:
changed 'checkCollideWithOverride()' method to the following:
public boolean checkCollideWith(CollisionObject co) {
if(co instanceof JBulletRigidBody)
{
CollisionGroup cg1 = ((PhysicsNode)getParentNode()).getCollisionGroup();
CollisionGroup cg2 = ((PhysicsNode)((JBulletRigidBody)co).getParentNode()).getCollisionGroup();
if(cg1.getCollidesWith().contains(cg2) || cg2.getCollidesWith().contains(cg1))
return super.checkCollideWith(co);
return false;
}
return super.checkCollideWith(co);
}
also, added the following method:
@Override
public void setGravity(Vector3f acceleration) {
if(((JBulletDynamicPhysicsNode)getParentNode()).isAffectedByGravity())
super.setGravity(acceleration);
}
Remaining changes are too large to paste, and have been included as attached files. No lib changes or anything else too wacky. Let me know if you see problems.
-Falken