# [solved] SetWorldRotation?

Hey all,

I’m trying to make walking limbs in my game, and I have a “leg” with a known world starting position (GetWorldTranslation()) and a known stepping point. I want to point the leg in the direction of its starting position to the stepping position. This is easy enough when the leg is attached to the root node, but when I have it attached to a parent node (e.g. the torso) which also rotates, I’m having difficulty getting the leg to stay pointed at the stepping position. I’ve been trying to set the rotation of the leg, and then subtract the rotation of the parent node, but I can’t find anything that “works”. What I would really like to accomplish is a SetWorldRotation() function, that sets the rotation of an object with respect to the world, and not locally… any suggestions on how to go about this? :?

Thank you!

Its relatively complicated as you can only deduce that when its attached really. Check the source of the CollisionShapeFactory, it has a method that deduces the “relative” rotation from any super geometry. If you have a direct parent, the RigidBodyPhysicsControl and the other physics controls have about the most elegant way to get a proper local rotation value for any given world rotation in their update method, inverting the parent quaternion and shit

I know you can do inverse transforms so I would have thought you can do inverse rotation:

I use:

getParent().getWorldTransform().transformInverseVector(vec);

In quite a few places to convert a point back to world space in order to then convert it into another objects frame of reference.

@zarch said:
I know you can do inverse transforms so I would have thought you can do inverse rotation:

I use:
getParent().getWorldTransform().transformInverseVector(vec);

In quite a few places to convert a point back to world space in order to then convert it into another objects frame of reference.

Can't seem to find the rotation equivalent of this :(

Check the source of the CollisionShapeFactory, it has a method that deduces the “relative” rotation from any super geometry.

I'm trying to find this code you are referring to... here is CollisionShapeFactory:

... which I assume the relative rotation magic happens in .addChildShape, which points me here:

... which has a native call which points me here:

... which I don't see anything useful(?). However, I think I'm just lost :P

I found the solution! Not too crazy, actually, from here:

Translated into jME3 code, it looks like this:

[java]Quaternion relativeToSet = LimbGeometry.getParent().getLocalRotation().inverse().mult(desiredWorldRotation);

LimbGeometry.setLocalRotation(relativeToSet);[/java]

@phr00t said:
I found the solution! Not too crazy, actually, from here: