0

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);

  • You apparently know how to get the local coordinate axes. Then simply [project](https://en.wikipedia.org/wiki/Vector_projection) the position of `B` onto the `z`-axis. Or are you looking for something different? – Nico Schertler Jul 12 '19 at 22:04
  • I think this seems to be more of a math problem then a programming problem. It seems you are familiar with some aspects of linear algebra, but if you need to brush up on them here is a good YouTube channel on that subject: https://www.youtube.com/user/BSVino – Francis Cugler Jul 12 '19 at 22:10
  • This channel is very good too: https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw/featured?disable_polymer=1 – Francis Cugler Jul 12 '19 at 22:12
  • @FrancisCugler wow the math for game developers link is amazing, thank you so much, I also think this is more of a math problem, I wasn't quite sure if it was best suited here or in the math stack exchange! – user11777831 Jul 12 '19 at 22:27

0 Answers0