// If a new shape should be created ...
if (createNewShape) {
// Create the collision shape (sphere with radius of 3 metres).
CollisionShape shape = new SphereShape(3);
// Create the motion state (x and z are the same as the camera's).
DefaultMotionState motionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(camera.x(), 35, camera.z()), 1.0f)));
// Calculate the inertia (resistance to movement) using the ball's mass of 1 kilogram.
Vector3f inertia = new Vector3f(0, 0, 0);
shape.calculateLocalInertia(1.0f, inertia);
RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(1, motionState, shape, inertia);
constructionInfo.restitution = 0.75f;
RigidBody rigidBody = new RigidBody(constructionInfo);
balls.add(rigidBody);
dynamicsWorld.addRigidBody(rigidBody);
createNewShape = false;
}
// If the controllable ball's position and orientation should be reset ...
if (resetControlBall) {
// Set the position of the ball to (0, 50, 0).
controlBall.setCenterOfMassTransform(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, 50, 0), 1.0f)));
// Reset the angular velocity (spinning movement) of the ball.
controlBall.setAngularVelocity(new Vector3f(0, 0, 0));
// Reset the linear velocity (x,y,z movement) of the ball.
controlBall.setLinearVelocity(new Vector3f(0, 0, 0));
resetControlBall = false;