0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ You have these values available as angles? Or as the axis of rotation (pitch axis, yaw axis)? \$\endgroup\$ Commented Mar 22, 2021 at 19:39
  • \$\begingroup\$ @PentaKon I have them as angles \$\endgroup\$ Commented Mar 22, 2021 at 19:40

1 Answer 1

2
\$\begingroup\$

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); 
\$\endgroup\$
1
  • \$\begingroup\$ I had to tweak the signs a bit, I think that's from how my axes are set up, Otherwise works fine. \$\endgroup\$ Commented Mar 23, 2021 at 7:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.