Class SoCamera

  • All Implemented Interfaces:
    SafeDisposable
    Direct Known Subclasses:
    SoOrthographicCamera, SoPerspectiveCamera

    public abstract class SoCamera
    extends SoNode
    Abstract base class for camera nodes. This is the abstract base class for all camera nodes. It defines the common methods and fields that all cameras have. Cameras are used to view a scene. When a camera is encountered during rendering, it sets the projection and viewing matrices and viewport appropriately; it does not draw geometry. Cameras should be placed before any shape nodes or light nodes in a scene graph; otherwise, those shapes or lights cannot be rendered properly. Cameras are affected by the current transformation, so you can position a camera by placing a transformation node before it in the scene graph. The default position and orientation of a camera is at (0,0,1) looking along the negative z-axis.

    You can also use a node kit to create a camera; see the reference page for SoCameraKit.

    Useful algorithms for manipulating a camera are provided in the SoCameraInteractor class.

    EXAMPLE

    Compute the current view vector or up vector.

     SoCamera camera . . .
     SbRotation orientation = camera.orientation.getValue();
     SbVec3f upVec = orientation.multVec( new SbVec3f(0,1,0) );
     SbVec3f vwVec = orientation.multVec( new SbVec3f(0,0,-1) );

    Compute the current focal point.

     SbRotation orientation = camera.orientation.getValue();
     SbVec3f offset = orientation.multVec( new SbVec3f(0,0,-1) );
     offset.multiply( camera.focalDistance.getValue() );
     SbVec3f focalPt = camera.position.getValue().plus( offset );

    See Also:
    SoOrthographicCamera, SoPerspectiveCamera, SoCameraKit, SoCameraInteractor
    • Field Detail

      • viewportMapping

        public final SoSFEnum<SoCamera.ViewportMappings> viewportMapping
        Defines how to map the rendered image into the current viewport, when the aspect ratio of the camera differs from that of the viewport. . Default is ADJUST_CAMERA.
      • position

        public final SoSFVec3f position
        The location of the camera viewpoint.
      • orientation

        public final SoSFRotation orientation
        The orientation of the camera viewpoint, defined as a rotation of the viewing direction from its default (0,0,-1) vector.
      • aspectRatio

        public final SoSFFloat aspectRatio
        The ratio of camera viewing width to height. This value must be greater than 0.0. There are several standard camera aspect ratios defined in SoCamera.h.
      • nearDistance

        public final SoSFFloat nearDistance
        The distance from the camera viewpoint to the near clipping plane.
      • farDistance

        public final SoSFFloat farDistance
        The distance from the camera viewpoint to the far clipping plane.
      • focalDistance

        public final SoSFFloat focalDistance
        The distance from the viewpoint to the point of focus. This is typically ignored during rendering, but may be used by some viewers to define a point of interest.
    • Method Detail

      • setBalanceAdjustment

        @Deprecated
        public void setBalanceAdjustment​(float adjustment)
        Deprecated.
        Calls setBalanceAdjustment(adjustment, (boolean)false).
      • viewAll

        public void viewAll​(SoPath path,
                            SbViewportRegion vpRegion)
        Calls viewAll(path, vpRegion, (float)1.0).
      • viewAll

        public void viewAll​(SoNode sceneRoot,
                            SbViewportRegion vpRegion)
        Calls viewAll(sceneRoot, vpRegion, (float)1.0).
      • getViewVolume

        public SbViewVolume getViewVolume()
        Calls getViewVolume((float)0.0).
      • scaleHeight

        public void scaleHeight​(float scaleFactor)
        Scales the height of the camera. Perspective cameras scale their heightAngle fields, and orthographic cameras scale their height fields.
      • getViewVolume

        public SbViewVolume getViewVolume​(float useAspectRatio)
        Returns a view volume object, based on the camera's viewing parameters.
        This object can be used, for example, to get the view and projection matrices, to project 2D screen coordinates into 3D space and to project 3D coordinates into screen space.

        If the useAspectRatio parameter is 0.0 (the default), the camera uses the current value of the aspectRatio field to compute the view volume.

        NOTE: In ADJUST_CAMERA mode (the default), the view volume returned when useAspectRatio = 0, is not (in general) the actual view volume used for rendering. Using this view volume to project points will not (in general) produce the correct results.

        This is because, in ADJUST_CAMERA mode, Inventor automatically modifies the view volume to match the aspect ratio of the current viewport. This avoids the distortion that would be caused by "stretching" the view volume when it is mapped into the viewport. However the view volume values are not changed, only the values passed to OpenGL. In order to get the modified values (i.e., the actual view volume used for rendering) you must pass the actual viewport aspect ratio to getViewVolume. You can get the current viewport from the renderArea or viewer object that contains the Open Inventor window.

        Also note that in ADJUST_CAMERA mode, when the viewport aspect ratio is less than 1, Open Inventor automatically scales the actual rendering view volume by the inverse of the aspect ratio (i.e. 1/aspect). The getViewVolume method does not automatically apply this adjustment. So a correct query of the actual rendering view volume can be done like this:

         // Given a viewer object, get the actual rendering view volume
         SoCamera camera = viewer.getArea().getCamera();
         float aspect    = viewer.getArea().getViewportRegion().getViewportAspectRatio();
         SbViewVolume viewVol = camera.getViewVolume( aspect );
         if (aspect < 1)
           viewVol.scale( 1 / aspect );

      • getStereoAbsoluteAdjustment

        @Deprecated
        public boolean getStereoAbsoluteAdjustment()
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and absoluteAdjustments field instead.
        Queries the stereo absolute adjustment state.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and absoluteAdjustments field instead.

      • pointAt

        public void pointAt​(SbVec3f targetPoint)
        Sets the orientation of the camera so that it points toward the given target point while keeping the "up" direction of the camera parallel to the positive y-axis. If this is not possible, it uses the positive z-axis as "up."
      • setStereoAdjustment

        @Deprecated
        public void setStereoAdjustment​(float adjustment)
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and offset field instead.
        Sets the stereo offset (the distance of each eye from the camera position). The right eye is moved plus offset and the left eye is moved minus offset. Default is 0.7. The default can be set using OIV_STEREO_OFFSET environment variable.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and offset field instead.

      • isBalanceAdjustmentNearFrac

        @Deprecated
        public boolean isBalanceAdjustmentNearFrac()
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and balanceNearFrac field instead.
        Returns true if the stereo balance adjustement is defined as a fraction of the camera near distance.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and balanceNearFrac field instead.

      • getViewportBounds

        public SbViewportRegion getViewportBounds​(SbViewportRegion region)
        Returns the viewport region this camera would use to render into the given viewport region, accounting for cropping.
      • getBalanceAdjustment

        @Deprecated
        public float getBalanceAdjustment()
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and balance field instead.
        Queries the parallax balance.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and balance field instead.

      • setStereoAbsoluteAdjustments

        @Deprecated
        public void setStereoAbsoluteAdjustments​(boolean absolute)
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and absoluteAdjustments field instead.
        Specifies if stereo adjustments are absolute. false by default.

        The default non-absolute mode allows the stereo settings to be valid over a range of different view volume settings. If you chose absolute mode, you are responsible for modifying the stereo settings (if necessary) when the view volume changes.

        When absolute mode is true, stereo offset and balance are used as shown in the following pseudo-code for the right eye view:

         StereoCameraOffset = getStereoAdjustment();
         FrustumAsymmetry   = getBalanceAdjustment();
         
         glTranslated (-StereoCameraOffset, 0, 0);
         glFrustum (FrustumLeft + FrustumAsymmetry, FrustumRight + FrustumAsymmetry,
                    FrustumBottom, FrustumTop, NearClipDistance, FarClipDistance);
        The left eye view is symmetric.

        When absolute mode is false, stereo offset and balance are used as shown in the following pseudo-code for the right eye view:

        Xrange is right minus left (i.e., first two arguments of glFrustum) and multiply that difference by the ratio of the distance to the desired plane of zero parallax to the near clipping plane distance.

         StereoCameraOffset   = Xrange * 0.035 * getStereoAdjustment();
         FrustumAsymmetry     = -StereoCameraOffset * getBalanceAdjustment();
         ZeroParallaxDistance = (NearClipDistance + FarClipDistance)/0.5;
         
         FrustumAsymmetry *= NearClipDistance / ZeroParallaxDistance;
         
         glTranslated (-StereoCameraOffset, 0, 0);
         glFrustum (FrustumLeft + FrustumAsymmetry, FrustumRight + FrustumAsymmetry,
                    FrustumBottom, FrustumTop, NearClipDistance, FarClipDistance);
        The left eye view is symmetric.

        Not virtual pure for compatiblity reasons.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and absoluteAdjustments field instead.

      • setBalanceAdjustment

        @Deprecated
        public void setBalanceAdjustment​(float adjustment,
                                         boolean nearFrac)
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and balance / balanceNearFrac fields instead.
        Sets the stereo balance (the position of the zero parallax plane) and specifies whether the balance value is defined as a fraction of the camera near distance. Note: Since the projection matrix always depends on the camera's near plane, in some cases it may be necessary to detect changes to the camera near plane and adjust by setting a new stereo balance value. Open Inventor will make these adjustments automatically if the nearFrac parameter is set to true. In this case the stereo balance value is defined as a fraction of the camera near distance.

        Default balance is 1.0. The default can be set using the OIV_STEREO_BALANCE environment variable. Default nearFrac is false. The default can be set using the OIV_STEREO_BALANCE_NEAR_FRAC environment variable.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and balance / balanceNearFrac fields instead.

      • getStereoAdjustment

        @Deprecated
        public float getStereoAdjustment()
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera and offset field instead.
        Queries the stereo offset.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera and offset field instead.

      • viewAll

        public void viewAll​(SoNode sceneRoot,
                            SbViewportRegion vpRegion,
                            float slack)
        Sets the camera to view the scene rooted by the given node. The near and far clipping planes will be positioned slack bounding sphere radii away from the bounding box's center. A value of 1.0 will make the near and far clipping planes the tightest around the bounding sphere.

        The node applies an SoGetBoundingBoxAction to the scene graph to get the bounding box of the entire scene. The bounding box will only include shapes that are actually traversed. For example the bounding box will not include shapes under an SoSwitch with whichChild set to SO_SWITCH_NONE. The action does not consider the visibility of shapes that are traversed. In other words the bounding box will include shapes that are invisible (SoDrawStyle), shapes that are clipped (SoClipPlane), etc. Use an SoBBox node to exclude shapes from the bounding box computation. Bounding boxes are automatically cached at SoSeparator nodes, so getting the bounding box is very fast when the scene graph has not been changed.

      • getViewVolume

        public SbViewVolume getViewVolume​(float aspectRatio,
                                          float nearDist,
                                          float farDist,
                                          SbVec3f position,
                                          SbRotation rotation)
        Computes a view volume from the given parameters.
      • viewAll

        public void viewAll​(SoPath path,
                            SbViewportRegion vpRegion,
                            float slack)
        Sets the camera to view the scene defined by the given path. The near and far clipping planes will be positioned slack bounding sphere radii away from the bounding box's center. A value of 1.0 will make the near and far clipping planes the tightest around the bounding sphere.

        See note about bounding boxes in the sceneRoot version of this method.

      • allowStereo

        @Deprecated
        public void allowStereo​(boolean name_9269)
        Deprecated.
        As of Open Inventor 9700. Use SoStereoCamera instead.
        Allows the camera to render in stereo. Default value is true.

        Warning Deprecated since Open Inventor 9700. Use SoStereoCamera instead.

      • viewAll

        public void viewAll​(SbBox3f bbox,
                            SbViewportRegion vpRegion)
        Sets the camera to view the region defined by the given bounding box. The near and far clipping planes will be positioned the radius of the bounding sphere away from the bounding box's center.

        See note about bounding boxes in the sceneRoot version of this method.

      • setStereoMode

        public void setStereoMode​(SoCamera.StereoModes mode)
        Sets the stereo mode. If the previous mode was MONOSCOPIC, the current position is saved. If the parameter mode is MONOSCOPIC, the saved value is restored in position. When rendering in stereo mode, set left view, render, set right view, render and then restore to monoscopic mode.