문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top