[SOLVED] enableSpring problem

Greetings, I am testing the SixDofSpringJoint class (docs: https://javadoc.jmonkeyengine.org/v3.x/com/jme3/bullet/joints/SixDofSpringJoint.html#enableSpring-int-boolean- , source code: https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java) for a future project that I already mentioned earlier in other article (Gravitation Simulator 2 is released! (public domain) and Universor Project is being worked). I want to connect two cubes with a SixDofSpringJoint but they don’t come together. When I put an index on enableSpring(…) between 0 and 3, the cubes disappear. If I make it bigger, the cubes don’t come together. What am I doing wrong?

    // Box 1
    Box b1 = new Box(0.5f, 0.5f, 0.5f);
    Geometry geom1 = new Geometry("Box 1", b1);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Gray);


    RigidBodyControl rbc1 = new RigidBodyControl(3);


    // Box 2
    Box b2 = new Box(0.5f, 0.5f, 0.5f);
    Geometry geom2 = new Geometry("Box 2", b2);



    RigidBodyControl rbc2 = new RigidBodyControl(3);

    // Joint
    SixDofSpringJoint joint = new SixDofSpringJoint(rbc1, rbc2, Vector3f.UNIT_X, Vector3f.UNIT_X.mult(-1), rot1, rot2, true);
    joint.enableSpring(4, true);

Since I didn’t know much about the usefulness of the matrices that are passed as a parameter in SixDofSpringJoint, I tried to put all the elements of the rot1 and rot2 matrices with ones. I changed them to 0 or 0.2f but nothing changes.

1 Like

I’ll take a look later today…

1 Like

Both matrices passed to the joint constructor should be rotation matrices, with determinant = 1 and transpose=inverse. If you intend the joint and both rigid bodies to all share the same orientation in space, the values to pass would both be Matrix3f.IDENTITY.

The index passed to enableSpring() specifies the axis as follows:

  • 0: translation along the joint’s X axis
  • 1: translation along the joint’s Y axis
  • 2: translation along the joint’s Z axis
  • 3: rotation around the joint’s X axis
  • 4: rotation around the joint’s Y axis
  • 5: rotation around the joint’s Z axis

I’ll update the documentation to clarify these details.

For the example you posted, I think you want the index to be 0.

PS: Also, limits should probably be specified for translation along the joint’s X axis, using joint.setLinearLowerLimit() and joint.setLinearUpperLimit().

1 Like

Ohh thanks! :grin: I was looking for information about it but couldn’t find anything. I don’t know if I’m the first to seriously worry about the SixDofSpringJoint class, at least as far as I know. Or will I be the first noob to ask how to use it? Has anyone used it for any of their games? Anyway, I’m going to fix my test program.

Should it work like a spring? It acts as a normal union. How would elasticity be added? I will see it tomorrow.

Have you consulted the source code?

A spring would have stiffness, an equilibrium point, and probably a range of motion.

I have been testing with all the methods of the class but I failed to create the elasticity I was looking for. I tried changing the enableSpring index to other values, but neither. I think what I am going to do is going to be a deeper study of the source code. I will let you know here if I achieve it and how I will have achieved it.

I finally realize my mistake. I missed specifying the limits of the spring. I had only tried the SixDofSpringJoint methods. Now it works well.

Case closed. I don’t bother anymore. :sweat_smile:

1 Like