groundShape.calculateLocalInertia(mass, localInertia);
}
// using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
// add the body to the dynamics world
dynamicsWorld.addRigidBody(body);
}
{
// create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
CollisionShape colShape = new BoxShape(new Vector3f(1, 1, 1));
//CollisionShape colShape = new SphereShape(1f);
collisionShapes.add(colShape);
// Create Dynamic Objects
Transform startTransform = new Transform();
startTransform.setIdentity();
float mass = 1f;
// rigidbody is dynamic if and only if mass is non zero, otherwise static
boolean isDynamic = (mass != 0f);
Vector3f localInertia = new Vector3f(0, 0, 0);
if (isDynamic) {
colShape.calculateLocalInertia(mass, localInertia);
}
float start_x = START_POS_X - ARRAY_SIZE_X / 2;
float start_y = START_POS_Y;
float start_z = START_POS_Z - ARRAY_SIZE_Z / 2;
for (int k = 0; k < ARRAY_SIZE_Y; k++) {
for (int i = 0; i < ARRAY_SIZE_X; i++) {
for (int j = 0; j < ARRAY_SIZE_Z; j++) {
startTransform.origin.set(
2f * i + start_x,
10f + 2f * k + start_y,
2f * j + start_z);
// using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
body.setActivationState(RigidBody.ISLAND_SLEEPING);
dynamicsWorld.addRigidBody(body);
body.setActivationState(RigidBody.ISLAND_SLEEPING);