Pregunta

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)

¿Fue útil?

Solución

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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top