Retrieving camera view volume
-
Hello guys,
I am working with cameras to do some computation I need to retrieve its current view volume. I call view volume, the visible scene's "cone" from the camera pov.
See picture below (this cone is visible when the option "Show Cone" in camera object is switched on):
-
Does it exist a function returning this volume no matter what kind of camera is used?
-
While I can compute it for perspective camera, I couldn't guess the right parameters to compute it for parallel camera.
struct frustum{ Float farVal, nearVal, right, left, top, bottom; }f; cam = GetCamera()) { Float near = 0; Float far = 1000; Float focusLength= getParam(CAMERAOBJECT_TARGETDISTANCE, DA_REAL, cam).DReal; if (getParam(CAMERAOBJECT_NEAR_CLIPPING_ENABLE, DA_LLONG, cam).DLLong != 0) { near = getParam(CAMERAOBJECT_NEAR_CLIPPING, DA_REAL, cam).DReal; } if (getParam(CAMERAOBJECT_FAR_CLIPPING_ENABLE, DA_LLONG, cam).DLLong != 0) { far = getParam(CAMERAOBJECT_FAR_CLIPPING, DA_REAL, cam).DReal; } auto fov_vertical = getParam(CAMERAOBJECT_FOV_VERTICAL, DA_REAL, cam).DReal; auto widthHalf = focusLength * maxon::Tan(fov / 2.0)/100.0; auto heightHalf = focusLength * maxon::Tan(fov_vertical / 2.0) / 100.0; f.farVal = far; f.nearVal = near; f.right = widthHalf; f.left = -f.right; f.top = heightHalf; f.bottom = -f.top; return 0; }
Any help is welcome.
Thank you in advance -
-
-
Not that I know of
-
In a parallel camera, the view frustrum is a rectangular box/"cube". The dimensions depend on the render setting dimensions and the camera's zoom value. For some reason the neutral zoom is 1.024, not 1, so: if your render settings define an image of 1000x500 pixels, and the camera zoom is 1.024, then an object with the dimensions 1000x500 units parallel to the camera's view plane will appear as filling the image.
(Obviously, in parallel projection the distance of the object does not matter.)
A zoom of 0.512 will show the object as half size (500x250 pixels, plusminus whatever the antialias settings screw up), a zoom of 2.048 will show the object as double size, etc. As the geometric frustrum is simple, the calculations for the volume (up to the focus distance) are trivial.
Note: I did this on R23, so if the later versions changed the neutral zoom, I wouldn't know.
-
-
@cairyn Thank you!