Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoCamera Class Referenceabstract

Abstract base class for camera nodes. More...

#include <Inventor/nodes/SoCamera.h>

+ Inheritance diagram for SoCamera:

Public Types

enum  ViewportMapping {
  CROP_VIEWPORT_FILL_FRAME = 0 ,
  CROP_VIEWPORT_LINE_FRAME = 1 ,
  CROP_VIEWPORT_NO_FRAME = 2 ,
  ADJUST_CAMERA = 3 ,
  LEAVE_ALONE = 4
}
 Viewport mapping. More...
 
enum  StereoMode {
  MONOSCOPIC ,
  LEFT_VIEW ,
  RIGHT_VIEW
}
 Stereo mode. More...
 

Public Member Functions

virtual SoType getTypeId () const
 Returns the type identifier for this specific instance.
 
void pointAt (const 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.
 
virtual void scaleHeight (float scaleFactor)=0
 Scales the height of the camera.
 
virtual SbViewVolume getViewVolume (float useAspectRatio=0.0) const =0
 Returns a view volume object, based on the camera's viewing parameters.
 
virtual SbViewVolume getViewVolume (float aspectRatio, float nearDist, float farDist, SbVec3f position, SbRotation rotation) const =0
 Computes a view volume from the given parameters.
 
void viewAll (SoNode *sceneRoot, const SbViewportRegion &vpRegion, float slack=1.0)
 Sets the camera to view the scene rooted by the given node.
 
void viewAll (SoPath *path, const SbViewportRegion &vpRegion, float slack=1.0)
 Sets the camera to view the scene defined by the given path.
 
void viewAll (const SbBox3f &bbox, const SbViewportRegion &vpRegion)
 Sets the camera to view the region defined by the given bounding box.
 
SbViewportRegion getViewportBounds (const SbViewportRegion &region) const
 Returns the viewport region this camera would use to render into the given viewport region, accounting for cropping.
 
void setStereoMode (StereoMode mode)
 Sets the stereo mode.
 
StereoMode getStereoMode () const
 Queries the stereo mode.
 
Deprecated
virtual SoDEPRECATED void setStereoAdjustment (float adjustment)
 Sets the stereo offset (the distance of each eye from the camera position).
 
SoDEPRECATED float getStereoAdjustment () const
 Queries the stereo offset.
 
virtual SoDEPRECATED void setStereoAbsoluteAdjustments (SbBool absolute)
 Specifies if stereo adjustments are absolute.
 
SoDEPRECATED SbBool getStereoAbsoluteAdjustment () const
 Queries the stereo absolute adjustment state.
 
virtual SoDEPRECATED void setBalanceAdjustment (float adjustment, SbBool nearFrac=false)
 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.
 
SoDEPRECATED float getBalanceAdjustment () const
 Queries the parallax balance.
 
SoDEPRECATED SbBool isBalanceAdjustmentNearFrac () const
 Returns TRUE if the stereo balance adjustement is defined as a fraction of the camera near distance.
 
virtual SoDEPRECATED void allowStereo (SbBool)
 Allows the camera to render in stereo.
 
- Public Member Functions inherited from SoNode
virtual void setOverride (const SbBool state)
 Turns the override flag on or off.
 
virtual SbBool isOverride () const
 Returns the state of the override flag.
 
virtual SoNodecopy (SbBool copyConnections=FALSE) const
 Creates and returns an exact copy of the node.
 
virtual SbBool affectsState () const
 Returns TRUE if a node has an effect on the state during traversal.
 
virtual void touch ()
 Marks an instance as modified, simulating a change to it.
 
- Public Member Functions inherited from SoFieldContainer
void setToDefaults ()
 Sets all fields in this object to their default values.
 
SbBool hasDefaultValues () const
 Returns TRUE if all of the object's fields have their default values.
 
SbBool fieldsAreEqual (const SoFieldContainer *fc) const
 Returns TRUE if this object's fields are exactly equal to fc's fields.
 
void copyFieldValues (const SoFieldContainer *fc, SbBool copyConnections=FALSE)
 Copies the contents of fc's fields into this object's fields.
 
SoNONUNICODE SbBool set (const char *fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
SbBool set (const SbString &fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
void get (SbString &fieldDataString)
 Returns the values of the fields of this object in the Open Inventor ASCII file format in the given string.
 
virtual int getFields (SoFieldList &list) const
 Appends references to all of this object's fields to resultList, and returns the number of fields appended.
 
virtual int getAllFields (SoFieldList &list) const
 Returns a list of fields, including the eventIn's and eventOut's.
 
virtual SoFieldgetField (const SbName &fieldName) const
 Returns a the field of this object whose name is fieldName.
 
virtual SoFieldgetEventIn (const SbName &fieldName) const
 Returns a the eventIn with the given name.
 
virtual SoFieldgetEventOut (const SbName &fieldName) const
 Returns the eventOut with the given name.
 
SbBool getFieldName (const SoField *field, SbName &fieldName) const
 Returns the name of the given field in the fieldName argument.
 
SbBool enableNotify (SbBool flag)
 Notification at this Field Container is enabled (if flag == TRUE) or disabled (if flag == FALSE).
 
SbBool isNotifyEnabled () const
 Notification is the process of telling interested objects that this object has changed.
 
virtual void setUserData (void *data)
 Sets application data.
 
void * getUserData (void) const
 Gets user application data.
 
- Public Member Functions inherited from SoBase
virtual SbName getName () const
 Returns the name of an instance.
 
virtual void setName (const SbName &name)
 Sets the name of an instance.
 
void setSynchronizable (const bool b)
 Sets this to be a ScaleViz synchronizable object.
 
bool isSynchronizable () const
 Gets the ScaleViz synchronizable state of this object.
 
- Public Member Functions inherited from SoRefCounter
void ref () const
 Adds a reference to an instance.
 
void unref () const
 Removes a reference from an instance.
 
void unrefNoDelete () const
 unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.
 
int getRefCount () const
 Returns current reference count.
 
void lock () const
 lock this instance.
 
void unlock () const
 unlock this instance.
 
- Public Member Functions inherited from SoTypedObject
SbBool isOfType (const SoType &type) const
 Returns TRUE if this object is of the type specified in type or is derived from that type.
 
template<typename TypedObjectClass >
SbBool isOfType () const
 Returns TRUE if this object is of the type of class TypedObjectClass or is derived from that class.
 

Static Public Member Functions

static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
- Static Public Member Functions inherited from SoNode
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
static SoNodegetByName (const SbName &name)
 A node's name can be set using SoBase::setName().
 
static int getByName (const SbName &name, SoNodeList &list)
 A node's name can be set using SoBase::setName().
 
- Static Public Member Functions inherited from SoFieldContainer
static SoType getClassTypeId ()
 Returns the type of this class.
 
- Static Public Member Functions inherited from SoBase
static SoType getClassTypeId ()
 Returns type identifier for this class.
 
- Static Public Member Functions inherited from SoTypedObject
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 

Public Attributes

SoSFEnum 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.
 
SoSFVec3f position
 The location of the camera viewpoint.
 
SoSFRotation orientation
 The orientation of the camera viewpoint, defined as a rotation of the viewing direction from its default (0,0,-1) vector.
 
SoSFFloat aspectRatio
 The ratio of camera viewing width to height.
 
SoSFFloat nearDistance
 The distance from the camera viewpoint to the near clipping plane.
 
SoSFFloat farDistance
 The distance from the camera viewpoint to the far clipping plane.
 
SoSFFloat focalDistance
 The distance from the viewpoint to the point of focus.
 

Detailed Description

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

SEE ALSO

SoOrthographicCamera, SoPerspectiveCamera, SoCameraKit, SoCameraInteractor

Definition at line 188 of file SoCamera.h.

Member Enumeration Documentation

◆ StereoMode

Stereo mode.

Enumerator
MONOSCOPIC 

Monoscopic (i.e., non-stereo) viewing.

LEFT_VIEW 

Left eye view.

RIGHT_VIEW 

Right eye view.

Definition at line 518 of file SoCamera.h.

◆ ViewportMapping

Viewport mapping.

Enumerator
CROP_VIEWPORT_FILL_FRAME 

Crops the viewport within the current window, so that the aspect ratio matches that of the camera.

As the window size changes, the aspect ratio remains unchanged. The cropped region is drawn as a filled gray area.

CROP_VIEWPORT_LINE_FRAME 

Crops the viewport, but draws a thin frame around the viewport.

CROP_VIEWPORT_NO_FRAME 

Crops the viewport, but gives no visual feedback as to the viewport dimensions within the window.

ADJUST_CAMERA 

Adjusts the camera aspect ratio and height to make it fit within the given window.

(The camera's fields are not affected, just the values sent to the graphics library.)

LEAVE_ALONE 

Do nothing.

Camera image may become stretched out of proportion

Definition at line 195 of file SoCamera.h.

Member Function Documentation

◆ allowStereo()

virtual SoDEPRECATED void SoCamera::allowStereo ( SbBool  )
virtual

Allows the camera to render in stereo.

Default value is TRUE.

Reimplemented in SoStereoCamera.

◆ getBalanceAdjustment()

SoDEPRECATED float SoCamera::getBalanceAdjustment ( ) const

Queries the parallax balance.

◆ getClassTypeId()

static SoType SoCamera::getClassTypeId ( )
static

Returns the type identifier for this class.


◆ getStereoAbsoluteAdjustment()

SoDEPRECATED SbBool SoCamera::getStereoAbsoluteAdjustment ( ) const

Queries the stereo absolute adjustment state.

◆ getStereoAdjustment()

SoDEPRECATED float SoCamera::getStereoAdjustment ( ) const

Queries the stereo offset.

◆ getStereoMode()

StereoMode SoCamera::getStereoMode ( ) const

Queries the stereo mode.

◆ getTypeId()

virtual SoType SoCamera::getTypeId ( ) const
virtual

Returns the type identifier for this specific instance.

Reimplemented from SoNode.

Reimplemented in SoOrthographicCamera, SoPerspectiveCamera, and SoStereoCamera.

◆ getViewportBounds()

SbViewportRegion SoCamera::getViewportBounds ( const SbViewportRegion region) const

Returns the viewport region this camera would use to render into the given viewport region, accounting for cropping.

◆ getViewVolume() [1/2]

virtual SbViewVolume SoCamera::getViewVolume ( float  aspectRatio,
float  nearDist,
float  farDist,
SbVec3f  position,
SbRotation  rotation 
) const
pure virtual

Computes a view volume from the given parameters.

Implemented in SoOrthographicCamera, and SoPerspectiveCamera.

◆ getViewVolume() [2/2]

virtual SbViewVolume SoCamera::getViewVolume ( float  useAspectRatio = 0.0) const
pure virtual

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
float aspect = viewer->getViewportRegion().getViewportAspectRatio();
SoCamera* camera = viewer->getCamera();
SbViewVolume viewVol = camera->getViewVolume( aspect );
if (aspect < 1)
viewVol.scale( 1 / aspect );
3D viewing volume class.
void scale(float factor)
Scales width and height of view volume by given factor.
virtual SbViewVolume getViewVolume(float useAspectRatio=0.0) const =0
Returns a view volume object, based on the camera's viewing parameters.

Implemented in SoOrthographicCamera, and SoPerspectiveCamera.

◆ isBalanceAdjustmentNearFrac()

SoDEPRECATED SbBool SoCamera::isBalanceAdjustmentNearFrac ( ) const

Returns TRUE if the stereo balance adjustement is defined as a fraction of the camera near distance.

◆ pointAt()

void SoCamera::pointAt ( const 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."

◆ scaleHeight()

virtual void SoCamera::scaleHeight ( float  scaleFactor)
pure virtual

Scales the height of the camera.

Perspective cameras scale their heightAngle fields, and orthographic cameras scale their height fields.

Implemented in SoOrthographicCamera, and SoPerspectiveCamera.

◆ setBalanceAdjustment()

virtual SoDEPRECATED void SoCamera::setBalanceAdjustment ( float  adjustment,
SbBool  nearFrac = false 
)
virtual

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.

Reimplemented in SoStereoCamera.

◆ setStereoAbsoluteAdjustments()

virtual SoDEPRECATED void SoCamera::setStereoAbsoluteAdjustments ( SbBool  absolute)
virtual

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);
SoDEPRECATED float getBalanceAdjustment() const
Queries the parallax balance.
SoDEPRECATED float getStereoAdjustment() const
Queries the stereo offset.

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.

Reimplemented in SoStereoCamera.

◆ setStereoAdjustment()

virtual SoDEPRECATED void SoCamera::setStereoAdjustment ( float  adjustment)
virtual

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.

Reimplemented in SoStereoCamera.

◆ setStereoMode()

void SoCamera::setStereoMode ( StereoMode  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.

◆ viewAll() [1/3]

void SoCamera::viewAll ( const SbBox3f bbox,
const 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.

◆ viewAll() [2/3]

void SoCamera::viewAll ( SoNode sceneRoot,
const SbViewportRegion vpRegion,
float  slack = 1.0 
)

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.

Warning:
The SoGetBoundingBoxAction will call ref() and unref() on the specified node. If the node's reference count before calling viewAll() is zero (the default), the call to unref() will cause the node to be destroyed.

◆ viewAll() [3/3]

void SoCamera::viewAll ( SoPath path,
const SbViewportRegion vpRegion,
float  slack = 1.0 
)

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.

Member Data Documentation

◆ aspectRatio

SoSFFloat SoCamera::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.

Definition at line 252 of file SoCamera.h.

◆ farDistance

SoSFFloat SoCamera::farDistance

The distance from the camera viewpoint to the far clipping plane.

Definition at line 262 of file SoCamera.h.

◆ focalDistance

SoSFFloat SoCamera::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.

Definition at line 269 of file SoCamera.h.

◆ nearDistance

SoSFFloat SoCamera::nearDistance

The distance from the camera viewpoint to the near clipping plane.

Definition at line 257 of file SoCamera.h.

◆ orientation

SoSFRotation SoCamera::orientation

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

Definition at line 246 of file SoCamera.h.

◆ position

SoSFVec3f SoCamera::position

The location of the camera viewpoint.

Definition at line 240 of file SoCamera.h.

◆ viewportMapping

SoSFEnum SoCamera::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.

Use enum ViewportMapping. Default is ADJUST_CAMERA.

Definition at line 235 of file SoCamera.h.


The documentation for this class was generated from the following file: