Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Retrieving camera view volume

    Cinema 4D SDK
    sdk c++ maxon api
    2
    3
    549
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      user168462
      last edited by

      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):
      c4909046-2363-47ec-a65e-cd7b43109806-image.png

      1. Does it exist a function returning this volume no matter what kind of camera is used?

      2. 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

      CairynC 1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn @user168462
        last edited by Cairyn

        @user168462

        1. Not that I know of

        2. 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.

        0e8b171d-2ed9-4ff3-a14a-c55925fb05fb-image.png

        Note: I did this on R23, so if the later versions changed the neutral zoom, I wouldn't know.

        U 1 Reply Last reply Reply Quote 1
        • U
          user168462 @Cairyn
          last edited by

          @cairyn Thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post