As the title says, I have the pitch and the yaw of an object, How do i use them to calculate the forward, up, right vectors (like the ones in unity), I've searched everywhere and only could find the forward vector.
\$\begingroup\$ \$\endgroup\$
2 - \$\begingroup\$ You have these values available as angles? Or as the axis of rotation (pitch axis, yaw axis)? \$\endgroup\$PentaKon– PentaKon2021-03-22 19:39:17 +00:00Commented Mar 22, 2021 at 19:39
- \$\begingroup\$ @PentaKon I have them as angles \$\endgroup\$Hamza Nasab– Hamza Nasab2021-03-22 19:40:30 +00:00Commented Mar 22, 2021 at 19:40
Add a comment |
1 Answer
\$\begingroup\$ \$\endgroup\$
1 Assuming your axes are set up like Unity's...
forward.x = cos(pitch) * sin(yaw); forward.y = -sin(pitch); forward.z = cos(pitch) * cos(yaw); Since pitching acts around the right axis, you can neglect pitch for that case. Then it's basically the same as the forward axis, shifted by 90 degrees of yaw (turning sine into cosine and cosine into negative sine)
right.x = cos(yaw); right.y = 0; right.z = -sin(yaw); And the up vector is just the cross product of the two.
up = cross(forward, right); Or equivalently:
up.x = sin(pitch) * sin(yaw); up.y = cos(pitch); up.z = sin(pitch) * cos(yaw); - \$\begingroup\$ I had to tweak the signs a bit, I think that's from how my axes are set up, Otherwise works fine. \$\endgroup\$Hamza Nasab– Hamza Nasab2021-03-23 07:58:56 +00:00Commented Mar 23, 2021 at 7:58