Weird rotation issue when using Cylinder (not CylinderCollisionShape) and a HingeJoint

I’m fiddling about with an inverted double pendulum whose arm segments has mass as well as its hammer. I had modeled this before using CollisionShapes (spheres and cylinders) and it worked just fine.



I’m now trying to fiddle about using Spatials instead of CollisionShapes so that I can apply materials, and I’m encountering some weirdness when it comes to orienting my Geometries. To simplify the problem, I will simply demonstrate my problem with a 0-mass pendulum hook and a cylindrical arm that has mass.



When I was using the CollisionShapes, I was able to select the axis of orientation for the Cylinders; when doing so using jme3 Cylinder spatials applied to a Geometry I can only effect this change by performing a rotation on the Geometry. This works, until I create a joint between the pendulum’s hook and the arm and add that joint to the physics space. Once I do this, the cylinder becomes horizontal again.



Now, code and pictures.



You can see here what the hook-and-arm looks like:







I would like for the cylinder to be in line with the joint connection. I can get the graphics to point in the right direction, but doing so requires getting the connection point of the joint to be outside of the cylinder itself:







To give you an idea of how I’m setting everything up:



[java]

private final Sphere hookNodeSphere = new Sphere(255, 255, SPHERE_RADIUS);

private final Cylinder pendulumSegmentCylinder = new Cylinder(255, 255, CYLINDER_X_EXTENT, CYLINDER_Y_EXTENT * 2, true);



private Geometry hookGeometry;

private Geometry topPendulumSegment;



private RigidBodyControl hookPhysics;

private RigidBodyControl topPendulumSegmentPhysics;



hookGeometry = new Geometry(“Pendulum Hook Geometry”, hookNodeSphere);

hookGeometry.move(0, 0, 0);



hookPhysics = new RigidBodyControl(0.0f);

hookGeometry.addControl(hookPhysics);

hookPhysics.setPhysicsLocation(Vector3f.ZERO);



hookGeometry.setMaterial(sphereMaterial);

rootNode.attachChild(hookGeometry);



topPendulumSegment = new Geometry(“Top Pendulum Segment”, pendulumSegmentCylinder);

Vector3f topPendulumOffsetVector = new Vector3f(0, (SPHERE_RADIUS + CYLINDER_Y_EXTENT + .01f), 0);

topPendulumSegment.move(topPendulumOffsetVector);

topPendulumSegment.rotate(rotate90AboutXQuat);



topPendulumSegmentPhysics = new RigidBodyControl(1f);

topPendulumSegment.addControl(topPendulumSegmentPhysics);

topPendulumSegmentPhysics.setPhysicsLocation(topPendulumOffsetVector);



topPendulumSegment.setMaterial(cylinderMaterial);

rootNode.attachChild(topPendulumSegment);



physicsSpace.add(hookGeometry);

physicsSpace.add(topPendulumSegment);

[/java]



If I stop here and run as-is, I see this:







Which is what I expect. It’s as soon as I create the joint and then add it to the Physics Space that things go sideways (literally):



[java]

hookJoint = new HingeJoint(hookPhysics, topPendulumSegmentPhysics, Vector3f.ZERO, new Vector3f(0f, -(SPHERE_RADIUS + CYLINDER_Y_EXTENT + .01f), 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z);

physicsSpace.add(hookJoint);

[/java]



Will yield:







This is the exact same code that I used when I was using CollisionShapes; for educational purposes, if I use the CollisionShape in the constructor for the RigidBodyControl, you see what I would expect:



Can you ask a specific question? I don’t know what your actual issue/misunderstanding is.

@normen Why does adding the joint make it go sideways, and how can I get the cylinder in line with the joint’s pivot?

The joint has a direction, it probably forces the object in position. The pivot you give is local to the object.

@normen Ah. I see what I was doing wrong. I wasn’t doing the local coordinate math in my head correctly. It looks like I was on the right path when I did what I was doing that got the pivot pointing outside of the body of the cylinder, because I have it all lined up now. Thanks.

2 Likes