Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera Pitch/Yaw to Direction Vector

What I'm trying to do is cast a ray from my camera. I know the camera's x, y and z coordinates, as well as its pitch and yaw. I need to calculate its direction vector so I can pass it to my raytracing algorithm.

The camera's up vector is (0, 1, 0). "Pitch", from the perspective of the camera, is looking up and down.

(I would prefer to not use matrices, but I will if I have to)

like image 742
RunasSudo Avatar asked May 13 '12 06:05

RunasSudo


1 Answers

Assuming that your coordinate system is set up such that the following conditions are met:

(pitch, yaw)  -> (x, y, z)
(0,     0)    -> (1, 0, 0)
(pi/2,  0)    -> (0, 1, 0)
(0,    -pi/2) -> (0, 0, 1)

This will calculate (x, y, z):

xzLen = cos(pitch)
x = xzLen * cos(yaw)
y = sin(pitch)
z = xzLen * sin(-yaw)
like image 82
Neil Forrester Avatar answered Oct 01 '22 07:10

Neil Forrester