No, I haven’t read that, but I will. By the way.
Try to run this code, it’s supposed to be Newton’s cradle.
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.joints.HingeJoint;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
private BulletAppState bulletAppState;
private Node node1;
private Node node2;
private Node node3;
private Node node4;
private Node dyn1;
private Node dyn2;
private Node dyn3;
private Node dyn4;
private HingeJoint joint1;
private HingeJoint joint2;
private HingeJoint joint3;
private HingeJoint joint4;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
setupStaticalNodes();
setupDynamicalNodes();
setupJoints();
}
private void setupStaticalNodes(){
// Static nodes
node1 = createControl(new BoxCollisionShape(new Vector3f(0.1f, 0.1f, 0.1f)), 0);
node2 = createControl(new BoxCollisionShape(new Vector3f(0.1f, 0.1f, 0.1f)), 0);
node3 = createControl(new BoxCollisionShape(new Vector3f(0.1f, 0.1f, 0.1f)), 0);
node4 = createControl(new BoxCollisionShape(new Vector3f(0.1f, 0.1f, 0.1f)), 0);
// Place out the static nodes
node1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1f, 0, 0f));
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2f, 0, 0f));
node4.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3f, 0, 0f));
// Attach them to physical space
bulletAppState.getPhysicsSpace().add(node1);
bulletAppState.getPhysicsSpace().add(node2);
bulletAppState.getPhysicsSpace().add(node3);
bulletAppState.getPhysicsSpace().add(node4);
// Attach the static nodes to the rootNode
rootNode.attachChild(node1);
rootNode.attachChild(node2);
rootNode.attachChild(node3);
rootNode.attachChild(node4);
}
private void setupDynamicalNodes(){
// Static nodes
dyn1 = createControl(new BoxCollisionShape(new Vector3f(0.5f, 0.5f, 0.5f)), 100);
dyn2 = createControl(new BoxCollisionShape(new Vector3f(0.5f, 0.5f, 0.5f)), 100);
dyn3 = createControl(new BoxCollisionShape(new Vector3f(0.5f, 0.5f, 0.5f)), 100);
dyn4 = createControl(new BoxCollisionShape(new Vector3f(0.5f, 0.5f, 0.5f)), 100);
// Place out the static nodes
dyn1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(-10f, -5, 0f));
dyn2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1f, -5, 0f));
dyn3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2f, -5, 0f));
dyn4.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3f, -5, 0f));
// Attach them to physical space
bulletAppState.getPhysicsSpace().add(dyn1);
bulletAppState.getPhysicsSpace().add(dyn2);
bulletAppState.getPhysicsSpace().add(dyn3);
bulletAppState.getPhysicsSpace().add(dyn4);
// Attach the static nodes to the rootNode
rootNode.attachChild(dyn1);
rootNode.attachChild(dyn2);
rootNode.attachChild(dyn3);
rootNode.attachChild(dyn4);
}
private void setupJoints(){
// Joints
joint1 = new HingeJoint(node1.getControl(RigidBodyControl.class), // A
dyn1.getControl(RigidBodyControl.class), // B
Vector3f.ZERO, // pivot point local to A
new Vector3f(0f, 5, 0), // pivot point local to B
Vector3f.UNIT_Z, // DoF Axis of A (Z axis)
Vector3f.UNIT_Z); // DoF Axis of B (Z axis)
joint2 = new HingeJoint(node2.getControl(RigidBodyControl.class), // A
dyn2.getControl(RigidBodyControl.class), // B
Vector3f.ZERO, // pivot point local to A
new Vector3f(0f, 5, 0), // pivot point local to B
Vector3f.UNIT_Z, // DoF Axis of A (Z axis)
Vector3f.UNIT_Z); // DoF Axis of B (Z axis)
joint3 = new HingeJoint(node3.getControl(RigidBodyControl.class), // A
dyn3.getControl(RigidBodyControl.class), // B
Vector3f.ZERO, // pivot point local to A
new Vector3f(0f, 5, 0), // pivot point local to B
Vector3f.UNIT_Z, // DoF Axis of A (Z axis)
Vector3f.UNIT_Z); // DoF Axis of B (Z axis)
joint4 = new HingeJoint(node4.getControl(RigidBodyControl.class), // A
dyn4.getControl(RigidBodyControl.class), // B
Vector3f.ZERO, // pivot point local to A
new Vector3f(0f, 5, 0), // pivot point local to B
Vector3f.UNIT_Z, // DoF Axis of A (Z axis)
Vector3f.UNIT_Z); // DoF Axis of B (Z axis)
bulletAppState.getPhysicsSpace().add(joint1);
bulletAppState.getPhysicsSpace().add(joint2);
bulletAppState.getPhysicsSpace().add(joint3);
bulletAppState.getPhysicsSpace().add(joint4);
}
// Add control to a node.
// Static nodes has 0 mass and dynamicla nodes hass mass > 0
private Node createControl(BoxCollisionShape shape, float mass){
Node node = new Node();
RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, mass);
node.addControl(rigidBodyControl);
return node;
}
boolean flag = true;
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
I jused the jme3- jbullet library and not the jme3-bullet and jme3-bullet-native.

Not really what I expected, but it’s bullet physics.
I expected a real simulation of newton’s cradle.