2

This is going to be a rather complicated explanation so bear with me. In 3D space, a player has 2 rotation values for looking around them, the rotation about the x and y axis. Given a view distance, I have calculated the point in the center of the players view port which is the view distance away (as show below).

enter image description here

  • 'vd' is the view distance
  • 'c' is a value holder
  • '(x,y,z)' is the point to be calculated
  • 'rot.x' and 'rot.y' are the rotations about the x and y axis, respectively.

Given this point (x,y,z), I need to calculate four points relative to this position (as shown below)

enter image description here

  • '(x2,y2,z2)', '(x3,y3,z3)', etc. are the points I need to calculate.
  • The width and height of the green plane is known. Let's call each one 'w' and 'h' respectively.

Now given I still have access to all the values in the first graph (such as rotations, etc), how can I calculate the each of the four points?

A little background.. I am doing this for a culling method called frustum culling. I am trying to do this with LWJGL in order to speed up rendering and reduce the toll on the GPU. I haven't been able to figure out the trigonometry for this calculation, and I have been trying for the past few hours. Any help is appreciated. If any more explanation/clarification is needed, just let me know. Thanks.

EDIT: Also, the points have to be on the same plane and rotate about the x and y axis with the point (x,y,z).

4

1 回答 1

2

假设旋转顺序是先 X 然后是 Y 旋转,那么矩阵计算将是:

V*Ry*Rx

自从V向量成立以来。

V = [view_distance, tan(22.5)*view_distance, tan(22.5)*view_distance*(WIDTH/HEIGHT)]

那么这意味着:

X2 = cos(rot.Y) * view_distance - 
     (tan(22.5) * WIDTH * view_distance * sin(rot.Y))/HEIGHT
Y2 = tan(22.5) * cos(rot.X) * view_distance + 
     (tan(22.5) * WIDTH * cos(rot.Y) * view_distance * sin(rot.X))/HEIGHT +
      view_distance * sin(rot.X) * sin(rot.Y)
Z2 = (tan(22.5) * WIDTH * cos(rot.X) * cos(rot.Y) * view_distance)/HEIGHT - 
     tan(22.5) * view_distance * sin(rot.X) +
     cos(rot.X) * view_distance * sin(rot.Y)

表达式可以进一步简化一点,因为例如可以从所有表达式中考虑视图距离。由于计算这有点毫无意义且容易出错,所以 id 更喜欢使用带有数值的矩阵函数作为更容易的东西。

PS:矩阵符号对您的眼睛和编程经验来说更容易。

于 2012-12-10T20:56:02.460 回答