Torque direction to "point" geometry @ target (local pitch + yaw but "no roll")

Hi!

I’ve been trying for some time now to point one object at a target (Vector3f point) using torque, but I don’t manage to figure out the direction the torque needs to have (applying the torque is not the problem… had it working for one axis between attempts - it was still swinging forth and back a little, but that’s fine). To be more specific: The applied torque is not supposed to turn the geometry to a specific orientation on all axes - it only needs to face into the right direction (like a gun. You can hold it sideways, it doesn’t care) with the minimal amount of necessary alignment change, meaning the “roll” should be ignored.

I just get utterly confused when I try to put everything together:

  • Not entirely sure how the relations between world rotation, local rotation, physics rotation, torque are (although I tested all of those with examples at some point while trying to get them into my head)
  • Keep messing up the directions while trying to imagine the relationship between original rotation, target location, torque direction, original and resulting quaternion etc
  • Also… I guess even though I only want to “yaw and pitch” but NOT “roll”, I need to rotate / apply torque on all axes because depending on the objects current (local) yaw, “pitching” it can be a (global) rotation on either axis and vice versa?
    - Wait a second… if current yaw is PI/2, then pitch is exactly around the X axis… if current yaw is 0, it’s exactly around the Z axis… in between it, “pitching” is… around the sin(yaw)/cos(yaw) axis? And… uhm… thaaaaat iiis… not only wrong (did I confuse sin and cos again?) but it also is irrelevant, because torque is relative to local rotation? Or not? Gnnnnn…

My last (probably useless) attempt looked like this in the end (I’ll leave some of the removed trial+error parts just to illustrate how “confused” I am xD). This is supposed to return the direction of the torque that needs to be applied (repeatedly - strength / length of the torque doesn’t really matter much) to the geometry to point it towards the target…:
[java]Vector3f pointThisAt(Vector3f target){
Vector3f diff = _geometry.getWorldTranslation().subtract(target);
// diff = _body.worldToLocal(target, null);
float[] current = _physics.getPhysicsRotation().toAngles(null);
// float[] wtf = _geometry.getWorldRotation().toAngles(null);
// for (int i = 0; i<3; i++) {current[i] -= wtf[i]; }
// System.out.println(current[0] + " " + current[1] + " " + current[2]);
float pitch = new Vector2f(diff.getZ(), diff.getY()).getAngle() + current[2];
float yaw = new Vector2f(diff.getX(), diff.getZ()).getAngle() + current[1] + FastMath.HALF_PI;
float roll = new Vector2f(diff.getY(), diff.getX()).getAngle() + current[0] + FastMath.HALF_PI;
while (pitch > Math.PI) {
pitch -= 2 * Math.PI;
}
while (pitch < -Math.PI) {
pitch += 2 * Math.PI;
}
while (yaw < -Math.PI) {
yaw += 2 * Math.PI;
}
while (yaw > Math.PI) {
yaw -= 2 * Math.PI;
}
while (roll > Math.PI) {
roll -= 2 * Math.PI;
}
while (roll < -Math.PI) {
roll += 2 * Math.PI;
}
// return new Vector3f(roll, yaw, roll).negate().normalize();
// return new Vector3f(pitch, yaw, roll);
return new Vector3f(pitch, yaw, 0f).normalize();
}[/java]
I thought I was on the right track with this some 200 facepalms ago, but that “yaw’ing” my object towards the mouse position worked in between might have been (almost) coincidence. And now I’m stuck again. Any hints?

Try cross product the target vector with current direction vector. This gives you the torque axis to rotate around. I’ve posted a few solutions to this