Problem: I have object A, I know the position of object A (x,y,z). I also know the euler angles of object A. I would like to position object B such that it faces object A's -z axis.
My code: The code I have listed below will take Object A and rotate it such that it's -z axis faces object B's.
Now I would like to write code such that we place object B in a location where it faces object A's -z axis.
I feel like i'm essentially trying to find the "targetPos" from being given the euler angles and the position of object A.
// Calculate the x,y,z rotation vectors
MVector pos = nodeTranslation();
MVector objectUpVector = {0.0, 1.0, 0.0};
MVector zaxis = pos - targetPos; // pos = object A's position, targetPos = object B's position
zaxis.normalize();
MVector xaxis = objectUpVector^zaxis;
xaxis.normalize();
MVector yaxis = zaxis ^ xaxis;
// from the rotation vectors obtain the euler angles
double x = atan2(yaxis.z, zaxis.z);
double s1 = sin(x);
double c1 = cos(x);
double c2 = sqrt(xaxis.x * xaxis.x + xaxis.y*xaxis.y);
double y = atan2(-xaxis.z, c2);
double z = atan2(s1*zaxis.x - c1*yaxis.x, c1*yaxis.y - s1*zaxis.y);