Calculation of a point in three-dimensional space

I am trying to find a point in three-dimensional space relative to the origin (0,0,0). I have 3 values ​​for calculating this point with: rotation in degrees both on the x axis and on the y axis, as well as the "distance of view". Using these values, how can I find a point in three-dimensional space relative to the origin? I tried using basic trigonometric functions, but the results seem random. The image below gives a visual idea of ​​what needs to be done.

enter image description here

  • 'vd' is the "viewing distance"
  • 'c' is a value holder
  • '(x, y, z)' - the coordinate I'm trying to find

What I'm trying to do is find the point at which the player is looking at a certain distance (find the point in the player’s line of sight at a certain distance). Keep in mind that the rotation around the x and y axis is constantly changing, but the viewing distance remains unchanged. If someone has any suggestions, methods on how to do this, or clarification is required, comment / answer below.

I am doing this in LWJGL, and the code I use is as follows:

float c = (float)(Math.cos(Math.toRadians(A00.rot.y)) * view_distance); locate.y = (float)(Math.sin(Math.toRadians(rot.y)) * view_distance); locate.x = (float)(Math.cos(Math.toRadians(rot.x)) * c); locate.z = (float)(Math.sin(Math.toRadians(rot.x)) * c); 

EDIT:

My problem is that this current installation does NOT work for some reason. Mathematics seems legal to me, but I have to do something wrong in the actual schedule setup.

+4
source share
1 answer

I suggest looking for quaternions. You do not need to fully understand how they work. You can also find ready-made classes for java available on the Internet. Quaternions allow you to imagine rotation in three-dimensional space.

What I did then was to start with a vector representing the direction pointing forward from the origin, and apply the same rotation that the player has to him now. Now he points in the same direction as the player. Now, if you take the player’s current point and direction vector, we now have a ray that describes where the player is.

I suggest this link for more information on quaternions. They may look complicated, but, as I said, you do not need to fully understand how and why they work in order to be able to use them. Just copy the formulas and find out how they are used. Once you figure out how to use them, they make 3D rotation very easy.

http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation

+1
source

All Articles