The 3D coordinate of the 2D camera and the viewing plane

I want to generate rays from the camera through the viewing plane. To do this, I need the camera position ("eye"), up, right and in the direction of the vectors (where the vector from the camera is in the direction in the direction of the object the camera is looking at) and P, a point on the viewing plane. As soon as I have a generated ray:

ray = camera_eye + t*(P-camera_eye); 

where t is the distance along the beam (assume that t = 1 at the moment).

My question is: how to get the 3D coordinates of point P, given that it is in position (i, j) on the viewing plane? Assume that the upper left and lower right corners of the viewing plane are indicated.

NOTE. The viewing plane is not really a plane in the sense that it does not extend infinitely in all directions. Rather, this aircraft can be seen as an image of width. In the x direction, the range is 0 → width, and in the y direction, the range is 0 → height. I want to find the three-dimensional coordinate of the (i, j) th element, 0

+7
c ++ geometry raytracing trigonometry
source share
3 answers

When I directly connected the proposed formulas to my program, I did not get the correct results (some debugging may be required). My initial problem seemed to be a misunderstanding of the coordinates (x, y, z) of the interpolating corner points. I processed the x, y, z-coordinates separately, where I shouldn't (and this may be application specific, as the camera can be oriented in any direction). Instead, the solution turned out to be a simple interpolation of the corner points of the viewing plane:

  • interpolate the lower corner points in the i direction to get P1
  • interpolate the top corner points in the i direction to get P2
  • interpolate P1 and P2 in the j direction to get world coordinates of the endpoint
0
source share

For a general solution of itnersection of a line and a plane, see http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/

Your specific graphics library (OpenGL / DirectcX, etc.) might have a standard way to do this.

edit: Are you trying to find the 3d intersection of a screen point (such as a mouse cursor) with a 3D object in your scene?

+2
source share

To execute P, you need the distance from the camera to the nearest clipping plane (screen), the size of the window on the near clipping plane (or viewing angle, you can determine the size of the window with the viewing angle) and the size of the displayed window.

  • Scale the position of the screen in the range -1 <x <+1 and -1 <y <+1, where +1 is the top / right and -1 is the bottom / left
  • Scale normalized x, y to fit viewport
  • Scale to the right and up the camera vector and summarize the results
  • Add a look at the vector scaled by the clipping distance.

Essentially, you get:

 p = at * near_clip_dist + x * right + y * up 

where x and y:

 x = (screen_x - screen_centre_x) / (width / 2) * view_width y = (screen_y - screen_centre_y) / (height / 2) * view_height 
0
source share

All Articles