Hey guys,
I have a problem with rotation of a node. The basic thing I want is, that the humanoid (which is my node ;)) looks straight to a given bearing Vector (which is normalized Vector pointing into to direction where the humanoid should look at).
The code I wrote is the following:
@Override
public void setBearing(Vector3f bearing) {
Vector3f oldBearing = this.getBearing().normalizeLocal();
if(bearing != null && oldBearing != null){
Vector3f newBearing = bearing.normalizeLocal();
if(!newBearing.equals(oldBearing)){
super.setBearing(newBearing);
float angle = oldBearing.angleBetween(newBearing);
Quaternion q = new Quaternion();
q.fromAngleNormalAxis(angle * -1, Vector3f.UNIT_Z);
entityRoot.getLocalRotation().multLocal(q);
}
}
}
The problem is, that I do not know in which direction I have to turn, cause angleBetween always returns 0-PI. So if I click left from the humanoid, the bearing is correct. If I then click right to the humanoid, the bearing is ok (180