How to find the vector corresponding to the 3-dimensional angle?

2

Hello, I'm doing a 3D game and I'm having trouble making 3D raycasting. In case, I want to do to the camera, to know if there is no object between the camera and the player. For this I need to find a vertex that represents the angle and check on the map whether there are obstacles or not. The camera stores the two-axis angle: Y-axis (modified with horizontal mouse movement, X-axis of the screen in the 2D plane) and X-axis (modified by vertical mouse movement, Y axis of the screen in the 2D plane) . I can do raycast from any of these angles alone, but I can not put them together to make raycast in 3 dimensions. The problem is that both share the Z (the sine of the Y axis and the cosine of the X axis). If I multiply the two between them, the result is only correct when the angle Y is 0º or 90º. If not, it gets inverted.

What formula should I use to calculate the Z value?

    
asked by anonymous 06.08.2015 / 18:14

1 answer

2

Thanks KaduAmaral for the hint, I found the formula in Math :

x = r cos β sin α
y = r cos β cos α
z = r sin β

Vetor: xî +yĵ +zk̂
    
06.08.2015 / 20:05