Setting world rotation

Is there a way to set world rotation of a Spatial without accounting for the upper hierarchy that imposes its current rotation to the spatial? For example, I have a rope, dangling, swinging and tilting all around and it has a sign attached to its end. So I want it to always stand up and face one direction instead of danglign with the rope. This video kinda explains my aim (observe the owl’s head).

For a Spatial you have access too: .getWorldRotation() and .getLocalRotation() … from here it is some easy math to get the spatial pointing anyway you want in the world space.

You could also have a look into the Billboard Control, as it will give you the desired outcome.

…and that video rocked =)

2 Likes

Try this:

[java]
/**
* Alter the world orientation of a spatial.
*
* NOTE: This method may yield incorrect results in the presence of
* non-uniform scaling.
*
* @param spatial which spatial (not null)
* @param newOrientation desired world orientation (not null, unaffected)
/
public static void setWorldOrientation(Spatial spatial,
Quaternion newOrientation) {
Spatial parent = spatial.getParent();
Quaternion localRotation;
if (parent != null) {
localRotation = inverseOrientation(parent);
localRotation.multLocal(newOrientation);
localRotation.normalizeLocal();
} else {
localRotation = newOrientation.clone();
}
/

* Apply to the spatial.
/
spatial.setLocalRotation(localRotation);
/

* Apply to the physical object, if any.
*/
RigidBodyControl rigidBodyControl =
spatial.getControl(RigidBodyControl.class);
if (rigidBodyControl != null) {
rigidBodyControl.setPhysicsRotation(newOrientation.clone());
}
}
[/java]

3 Likes