Hi,
I’m testing the physics engine with simple use cases.
One of them is 2 spheres colliding, A and B , with equal masses and B at rest.
In theory, after collision, A should stop and B should move, but they both move in the same direction.
What am I missing? Here’s the code, thanks :
package jme3test.bullet.dc;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import jme3test.bullet.PhysicsTestHelper;
public class POCCollisionResolution extends SimpleApplication implements PhysicsCollisionListener
{
private BulletAppState bulletAppState;
private static Node shapeA;
private static Node shapeB;
public static void main(String[] args)
{
POCCollisionResolution app = new POCCollisionResolution();
app.start();
}
private void setupKeys()
{
}
@Override
public void simpleInitApp()
{
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
// bulletAppState.getPhysicsSpace().setAccuracy(1f / 3600f);
flyCam.setMoveSpeed(20);
bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, 0));
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
setupKeys();
setupShapes();
shapeA.getControl(RigidBodyControl.class).applyImpulse(new Vector3f(1, 0, 0), Vector3f.ZERO);
// shapeA.getControl(RigidBodyControl.class).setLinearVelocity(new Vector3f(1,0,0));
}
private PhysicsSpace getPhysicsSpace()
{
return bulletAppState.getPhysicsSpace();
}
public void setupShapes()
{
// shapeA = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.001f, .001f, .1f)),1);
shapeA = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(0.1F), 1);
shapeA.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
shapeA.setName("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
shapeA.getControl(RigidBodyControl.class).setSleepingThresholds(0, 0);
rootNode.attachChild(shapeA);
getPhysicsSpace().add(shapeA);
// shapeB = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1);
shapeB = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(0.1F), 1);
shapeB.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 0, 0f));
shapeB.getControl(RigidBodyControl.class).setSleepingThresholds(0, 0);
rootNode.attachChild(shapeB);
getPhysicsSpace().add(shapeB);
getPhysicsSpace().addCollisionListener(this);
}
@Override
public void simpleUpdate(float tpf)
{
}
public void collision(PhysicsCollisionEvent event)
{
}
}