简体   繁体   中英

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM