How to find the vector corresponding to the angle in 3 dimensions?

Asked

Viewed 849 times

2

Hello, I’m doing a 3-D game and I’m having trouble doing a 3-D raycasting. In this case, I want to do it for the camera, to see 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 guards the angle of two axes: Y axis (modified with the mouse movement in the horizontal, X axis of the screen in the 2D plane) and X axis (modified with the mouse movement in the vertical, Y axis of the screen in the 2D plane). I can make raycast from any of these angles by myself, but I can’t put them together to make raycast in 3 dimensions. The problem is that they both share the Z (the sine of the Y-axis and the cosine of the X-axis). If I multiply the two between each other, the result is only correct when the angle Y is 0º or 90º. If not, it is reversed. inserir a descrição da imagem aqui

What formula should I use to calculate the Z-value?

  • Complex, I think you’ll have to post this question on Math since it does not imply code, only formula.

1 answer

2

Thank you Kaduamaral for the tip, I found the formula in Math:

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

Vetor: xî +yĵ +zk̂
  • 3

    At your service

Browser other questions tagged

You are not signed in. Login or sign up in order to post.