View frustum visualization
Given a 3D 开发者_运维百科position of a camera, 3D target position of the camera (the point the camera points to), far plane distance from the camera, field of view and aspect ratio, how can I calculate the four 3D points in the far plane? This should be possible with basic trigonometry but I'm not getting the exact right results.
It might be basic trig in 2D, but the problem is a bit more elaborate in 3D. I don't have a specific answer for you, but this might give you some paths to explore.
Rougly, the steps are as follow:
- Find the equation of the image plane
- Find the FOV radius
- Find the equation of the FOV circle
- Find the four points lying on that circle that correspond to your aspect ratio
The plane on which that circle sits can be obtained by a point and normal vector, then allowing you to determine the equation of that circle in 3D (the point being the location of the camera, and the vector is the line between the camera and the target).
The radius of the circle can be determine by the relation r = d tan(theta / 2)
where d is the distance between the camera and target, and theta is the FOV angle in degrees.
The equation of that circle in 3D can be defined according to the radius and normal vector.
Finally, you need to find the rectangle with given aspect ratio that can be inscribed in that circle, your four points being the intersection of the rectangle and circle.
You also need to consider whether the camera can be tilted or if it is leveled. This will change the points, but they will still lie on the same circle/plane.
Depending on your objective, it might help simplify the problem if the camera is always located at (0,0,0) and is aligned with one of the axes (i.e. the target is on one of the axes).
精彩评论