However, the ball never seems to rotate. I can see it spin (and have proper english when it bounces) if I set angular velocity, but on its own it never rotates at all. I would expect that if the object has lateral motion, and comes into contact with a wall or floor, it would appropriately spin based on the position of that contact.
Is there something I need to enable/disable for this? Does a sphere body never do this? I've been looking all morning for what I might have missed.
For reference, here's the setup code for the world and ball:
WORLD:
Code: Select all
DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
Vector3f worldAabbMin = new Vector3f(-10,-10,-10);
Vector3f worldAabbMax = new Vector3f(10,10,10);
AxisSweep3 overlappingPairCache = new AxisSweep3(worldAabbMin, worldAabbMax);
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();
dynamicWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicWorld.setGravity(new Vector3f(0,0,-10.0f)); // earth gravity is 9.8 m/s squared
dynamicWorld.getDispatchInfo().allowedCcdPenetration = 0f;
CollisionShape collisionShape;
RigidBodyConstructionInfo rbInfo;
RigidBody body;
Vector3f localInertia = new Vector3f(0, 0, 0);
float mass = 0f; // mass of 0 means Bullet will treat it as a non-moving obstacle-like thing with infinite mass
// Floor, upwards facing
collisionShape = new StaticPlaneShape(new Vector3f(0,0,1), 0);
// put the plane right at 0
Transform floorTransform = new Transform();
floorTransform.setIdentity();
DefaultMotionState floorMotionState = new DefaultMotionState(floorTransform);
rbInfo = new RigidBodyConstructionInfo(mass, floorMotionState, collisionShape, localInertia);
rbInfo.restitution = 0.65f; // how 'bouncy' the surface is
rbInfo.friction = 2f;
body = new RigidBody(rbInfo);
dynamicWorld.addRigidBody(body);
Code: Select all
CollisionShape ballShape = new SphereShape(0.12f); //radius of a basketball in m
Transform startTransform = new Transform();
startTransform.setIdentity();
startTransform.origin.set( new Vector3f( this.origin.x, this.origin.y, this.origin.z) );
float mass = 0.55f; // Wikipedia says a basketball should be minimally 550 grams in weight!
Vector3f localInertia = new Vector3f(0, 0, 0);
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo( mass, myMotionState, ballShape, localInertia );
rbInfo.restitution = 0.95f; // Restitution of 1.0 is, in theory, perfectly bouncy with no loss of energy
rbInfo.friction = 0.1f;