SoCameraInteractor Class Reference
[Viewer Components]

VSG extension Utility class to manipulate a camera. More...

#include <Inventor/ViewerComponents/SoCameraInteractor.h>

Inheritance diagram for SoCameraInteractor:
SoRefCounter

List of all members.

Public Member Functions

 SoCameraInteractor (SoCamera *camera)
virtual void zoom (float zoom)
virtual void dolly (float scaleFactor)
virtual void changeViewVolume (float height, float aspect)
SoCameragetCamera () const
SbVec3f getFocalPoint () const
void setPosition (const SbVec3f &pos)
void setPosition (const SbVec2f &pos, float distFromEye, const SbViewportRegion &vpRegion)
void translate (const SbVec3f &trans)
void translate (const SbVec2f &displacement, const SbViewportRegion &vpRegion)
void pointAt (const SbVec3f &targetPoint)
SbRotation lookAt (const SbVec3f &position, const SbVec3f &target, const SbVec3f &up)
SbVec3f getDirectionVector () const
void roll (float angle)
void pivot (float angle)
void tilt (float angle)
void rotate (const SbRotation &rot)
void setOrientation (const SbRotation &rot)
void setRotationCenter (const SbVec3f &pos)
void setRotationAxis (const SbVec3f &axis)
void rotate (float angle)
void viewAxis (const SbVec3f &direction, const SbVec3f &up)
void viewX (bool reverse=false)
void viewY (bool reverse=false)
void viewZ (bool reverse=false)
void viewIn (const SbBox3f &bbox)
void viewIn (SoPath *path, const SbViewportRegion &vpRegion)
void viewIn (SoNode *node, const SbViewportRegion &vpRegion)
void viewAll (SoPath *path, const SbViewportRegion &vpRegion)
void viewAll (SoNode *node, const SbViewportRegion &vpRegion)
SbVec3f projectToPlane (const SbVec2f &point, float distFromEye, const SbViewportRegion &vpRegion) const
SbVec2f projectToScreen (const SbVec3f &point, const SbViewportRegion &vpRegion) const
void adjustClippingPlanes (SoNode *sceneRoot, const SbViewportRegion &vpRegion)
void zoomInWindow (const SbVec2f &topLeftCorner, const SbVec2f &bottomRightCorner, const SbViewportRegion &vpRegion)
void dollyInWindow (const SbVec2f &topLeftCorner, const SbVec2f &bottomRightCorner, const SbViewportRegion &vpRegion)
void dollyWithZoomCenter (const SbVec2f &centerPos, float scaleFactor, const SbViewportRegion &vpRegion)
void activatePanning (const SbVec2f &initPos, const SbViewportRegion &vpRegion)
void pan (const SbVec2f &newPos, const SbViewportRegion &vpRegion)
void activateOrbiting (const SbVec2f &startPos)
void orbit (const SbRotation &rotation)
void orbit (const SbVec2f &newPos)
void pushCamera ()
SbBool popCamera ()
void synchronize (SoCamera *camera)

Static Public Member Functions

static SoCameraInteractorgetNewInstance (SoCamera *camera)

Deprecated



SoDEPRECATED SbVec3f getViewportCenter () const

Detailed Description

VSG extension Utility class to manipulate a camera.

This class provides some useful algorithms to manipulate a camera (translation, rotation, zoom, etc).

This class is not, strictly speaking, a true interactor. It does not respond to input events. However it provides the camera manipulation algorithms you need to build an interactor that provides behavior similar to the Open Inventor viewer classes, for example SoWinExaminerViewer. An interactor could handle system-dependent events or Open Inventor events (using SoEventCallback). It could also be triggered from the user interface (buttons, sliders, etc).

Start by creating an instance of SoCameraInteractor by giving the camera to be manipulated either to the constructor of SoCameraInteractor or to the getNewInstance() method. Then, for example, to provide examinerViewer-like rotation behavior:

To provide the viewer's automatic adjustment of near and far clip planes behavior, call the adjustClippingPlanes() method before each render traversal.

To see an example "viewer" implemented using this class, please see the SceneExaminer class provided as source code in the Open Inventor SDK:

.../source/Inventor/ViewerComponents/nodes

[C++] Reference counting:

This is a reference counted object, similar to a node or path. It can only be destroyed by incrementing and decrementing the reference count. The initial reference count is 0. You may use the ref() and unref() methods, but we recommend using the SoRef "smart pointer" template. An SoCameraInteractor instance increments and decrements the camera's reference count when created and destroyed.

EXAMPLE

SEE ALSO

SceneInteractor, SceneExaminer


Constructor & Destructor Documentation

SoCameraInteractor::SoCameraInteractor ( SoCamera camera  ) 

Create a SoCameraInteractor for the specified camera.

The camera should be an SoPerspectiveCamera or SoOrthographicCamera object. Create an empty object if camera pointer is NULL or invalid


Member Function Documentation

void SoCameraInteractor::activateOrbiting ( const SbVec2f startPos  ) 

Set the starting point for interactive orbiting.

This method should be called when starting an interaction. Typically this is triggered by a mouse button or touch event. On subsequent mouse move or touch events, call the orbit() method with the new cursor or touch position.

Orbit is often used in an "examiner" type of viewer to allow the user to rotate the camera around a point of interest in the scene. To implement orbit around the camera's "focal point", call setRotationCenter() with the value returned from getFocalPoint().

Parameters:
startPos starting position, 2D point in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent method getNormalizedPosition().
void SoCameraInteractor::activatePanning ( const SbVec2f initPos,
const SbViewportRegion vpRegion 
)

Set the starting point for interactive panning.

This method should be called when starting an interaction. Typically this is triggered by a mouse button or touch event. On subsequent mouse move or touch events, call the pan() method with the new cursor or touch position.

Parameters:
initPos initial position in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent method getNormalizedPosition().
vpRegion the actual viewport region
void SoCameraInteractor::adjustClippingPlanes ( SoNode sceneRoot,
const SbViewportRegion vpRegion 
)

Adjust near and far clipping planes to minimize clipping of objects in the scene.

Equivalent to the auto clip planes feature in the viewer classes. Typically called before each render traversal.

virtual void SoCameraInteractor::changeViewVolume ( float  height,
float  aspect 
) [virtual]

Change camera's view volume.

Allows changing the view volume height and width with a single call. For a perspective camera, the height parameter is heightAngle in radians. For an orthographic camera, the height parameter is height in world coordinates.

Parameters:
height new camera height or heightAngle
aspect new camera aspect ratio
virtual void SoCameraInteractor::dolly ( float  scaleFactor  )  [virtual]

Dolly - Makes the scene appear larger or smaller.

For a perspective camera, moves the camera forward or backward along the view vector (details below). For an orthographic camera, changes the height field to give a similar visual effect (moving an orthographic camera forward and backward has no visual effect). This is the preferred way to implement the visual effect of "zooming" in and out for a perspective camera. For a perspective camera, dolly means the same thing it means for a camera on a movie set.

Note: 'scaleFactor' is the inverse of what you might expect. To make the scene appear 2X larger, specify a scaleFactor of 0.5. This is because scaleFactor multiplies the camera 'focalDistance' or 'height'.

  • Perspective camera: The camera has a "focal point" located focalDistance units from the camera position along the view direction vector ( orientation). Unlike a real camera, neither focal point nor focal distance has effect on the appearance of the image. The focal point is just a reference point for some algorithms. You can think of it as the "look at" point. The dolly() method computes a scale factor from the 'delta' parameter. A new "focal distance" is computed as the current value of the camera's focalDistance field multiplied by this scale factor. Then the camera's position field is modified so the camera is the new focal distance away from the focal point.
  • Orthographic camera: The dolly() method computes a scale factor from the 'delta' parameter and multiplies the camera's height field by this scale factor.
void SoCameraInteractor::dollyInWindow ( const SbVec2f topLeftCorner,
const SbVec2f bottomRightCorner,
const SbViewportRegion vpRegion 
)

Moves the camera forward or backward along the view vector to view the region defined by the given corners in normalized screen coordinates.

  • Perspective camera: The visual result is similar to zoomInWindow(), but this method changes the camera position (closer or farther away) and focalDisance fields instead of changing the heightAngle. This is the recommended method when using a perspective camera, because it avoids the limitations of very small or very large heightAngle values.
  • Orthographic camera: This method does nothing because moving the camera closer or farther away does not change the visual result.
void SoCameraInteractor::dollyWithZoomCenter ( const SbVec2f centerPos,
float  scaleFactor,
const SbViewportRegion vpRegion 
)

Modifies the camera to ajust the view around the specified point.

The algorithm is the same as the dolly() method (for a perspective camera the position field is changed, for an orthographic camera the height field is changed) and the delta parameter is used the same way.

Parameters:
centerPos zoom center in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent method getNormalizedPosition().
scaleFactor zoom scale
vpRegion the actual viewport region
SoCamera* SoCameraInteractor::getCamera (  )  const

Returns the associated camera.

SbVec3f SoCameraInteractor::getDirectionVector (  )  const

Returns the direction vector of the camera.

SbVec3f SoCameraInteractor::getFocalPoint (  )  const

Returns the camera's "focal point", located focalDistance units from the camera position along the view direction vector (defined by the camera's orientation field).

This is the reference point for some algorithms. For example, orbit() is often used in an "examiner" type of viewer to allow the user to rotate the camera around a point of interest in the scene. To implement orbit around the camera's focal point, call the setRotationCenter() method with the focal point before calling the orbit() method.

Returns:
focal point in world coordinates
static SoCameraInteractor* SoCameraInteractor::getNewInstance ( SoCamera camera  )  [static]

Create an instance for the specified camera.

The camera should be an SoPerspectiveCamera or SoOrthographicCamera object. Returns null if the camera parameter is null.

SoDEPRECATED SbVec3f SoCameraInteractor::getViewportCenter (  )  const

Returns the viewport center.

On other words, returns the camera's "focal point", located focalDistance units from the camera position along the view direction vector ( orientation).

Returns:
center in world coordinates
Deprecated:

Deprecated since Open Inventor 9500
Use getFocalPoint() instead.
SbRotation SoCameraInteractor::lookAt ( const SbVec3f position,
const SbVec3f target,
const SbVec3f up 
)

Returns the rotation needed to point a camera at position toward the given target point while keeping the "up" direction of the camera parallel to the specified up vector.

This method does NOT modify the camera node. Set the returned rotation in the camera's orientation field.

Parameters:
position of the camera
target position of the target
up up vector of the camera
void SoCameraInteractor::orbit ( const SbVec2f newPos  ) 

Orbit the camera based on offset from the previous screen position.

This method can be used to implement an interactive orbit operation in response to mouse move or touch events. The activateOrbiting() method should be called at the start of the operation. This method uses an SbSphereSheetProjector to compute a rotation value based on the specified point and the previously specified point.

Parameters:
newPos new position, 2D point in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent method getNormalizedPosition().
void SoCameraInteractor::orbit ( const SbRotation rotation  ) 

Orbit the camera by the specified rotation.

"Orbit" means to rotate the camera around a fixed point in 3D space. The rotation point is specified using the setRotationCenter() method. This method automatically calls the setRotationAxis() method with the axis defined by the SbRotation parameter.

Orbit is often used in an "examiner" type of viewer to allow the user to rotate the camera around a point of interest in the scene. Orbit based on mouse or touch events can be implemented using the orbit() method. This method can be used, for example, to animate the camera to a new viewpoint. To implement orbit around the camera's "focal point", call setRotationCenter() with the value returned from getFocalPoint().

Parameters:
rotation Incremental rotation, i.e. this rotation is multiplied with the current camera orientation.
void SoCameraInteractor::pan ( const SbVec2f newPos,
const SbViewportRegion vpRegion 
)

Pan the camera based on offset from starting point.

This method can be used to implement an interactive panning operation in response to move move or touch events. The activatePanning() method should be called at the start of the operation.

Parameters:
newPos new position in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent method getNormalizedPosition().
vpRegion the actual viewport region
void SoCameraInteractor::pivot ( float  angle  ) 

Pivot the camera.

Incremental in-place rotation left/right (around the camera's up vector, i.e. local Y axis). Rotations are cumulative. Camera position does not change. Positive values pivot the camera left.

Parameters:
angle angle in radians
void SoCameraInteractor::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 world coordinate y-axis.

If this is not possible, it uses the positive z-axis as "up". Equivalent to calling the SoCamera method pointAt().

Parameters:
targetPoint target point
SbBool SoCameraInteractor::popCamera (  ) 

Restore saved camera.

The values of the camera fields are restored to the last pushed values. Returns true if successful, false if the vector of pushed cameras is empty.

SbVec3f SoCameraInteractor::projectToPlane ( const SbVec2f point,
float  distFromEye,
const SbViewportRegion vpRegion 
) const

Project specified 2D point on the plane parallel to the near plane that is at distFromEye units from the eye, see also SbViewVolume::getPlanePoint.

Parameters:
point point to project in normalized screen coordinates (0 <= x,y <= 1)
distFromEye the distance at which the point would be back projected
vpRegion the actual viewport region
Returns:
projected point in world coordinates
SbVec2f SoCameraInteractor::projectToScreen ( const SbVec3f point,
const SbViewportRegion vpRegion 
) const

Map a 3D point in world coordinates to a 2D point in normalized screen coordinates (0 <= x,y <= 1), see also SbViewVolume::projectToScreen.

Parameters:
point point to project in world coordinates
vpRegion the actual viewport region
Returns:
2D point in normalized screen coordinates (0 <= x,y <= 1)
void SoCameraInteractor::pushCamera (  ) 

Save current camera.

The values of the camera fields are saved and can be restored by calling popCamera().

void SoCameraInteractor::roll ( float  angle  ) 

Roll the camera.

Incremental in-place rotation around the view direction vector (camera's local Z axis). Rotations are cumulative. Camera position does not change. Positive values roll the camera counter-clockwise.

Parameters:
angle angle in radians
void SoCameraInteractor::rotate ( float  angle  ) 

Rotate the camera around the center specified by setRotationCenter() and the axis specified by setRotationAxis().

The default rotation axis is (0,0,0), so calling this method will not have any visible effect until a rotation axis is set. The rotation axis is automatically set by some methods, e.g. orbit().

Parameters:
angle angle in radians
void SoCameraInteractor::rotate ( const SbRotation rot  ) 

Rotate the camera.

Incremental in-place rotation. Rotations are cumulative. Camera position does not change (rotationCenter and rotationAxis do not apply).

Parameters:
rot new rotation
void SoCameraInteractor::setOrientation ( const SbRotation rot  ) 

Set the orientation of the camera.

Replaces any previous rotations applied to the camera. Camera position does not change.

Parameters:
rot new orientation
void SoCameraInteractor::setPosition ( const SbVec2f pos,
float  distFromEye,
const SbViewportRegion vpRegion 
)

Move camera to the specified position.

Parameters:
pos new position (2D point in normalized screen coordinates: 0 <= x,y <= 1)
distFromEye the distance at which the point would be back projected.
vpRegion the actual viewport region
void SoCameraInteractor::setPosition ( const SbVec3f pos  ) 

Move camera to the specified position.

Parameters:
pos new position in world coordinates
void SoCameraInteractor::setRotationAxis ( const SbVec3f axis  ) 

Set the axis of rotation.

Default is (0, 0, 0). This vector is used by the rotate(float) method.

Parameters:
axis new rotations axis
void SoCameraInteractor::setRotationCenter ( const SbVec3f pos  ) 

Set the center of rotation.

Default is (0, 0, 0). This position is used by the rotate(float) and orbit() methods.

Parameters:
pos position in world coordinates
void SoCameraInteractor::synchronize ( SoCamera camera  ) 

Copy field values from the specified camera to the camera of this interactor.

If the two cameras are not the same type, common fields are copied and the height or heightAngle field is computed.

void SoCameraInteractor::tilt ( float  angle  ) 

Tilt the camera.

Incremental in-place rotation up/down (around the camera's local X axis). Rotations are cumulative. Camera position does not change. Positive values tilt the camera up.

Parameters:
angle angle in radians
void SoCameraInteractor::translate ( const SbVec2f displacement,
const SbViewportRegion vpRegion 
)

Move camera by the specified 2D displacement.

Parameters:
displacement 2D displacement in normalized screen coordinates: 0 <= x,y <= 1
vpRegion the actual viewport region
void SoCameraInteractor::translate ( const SbVec3f trans  ) 

Move camera by the specified 3D displacement.

Parameters:
trans translation value in world coordinates
void SoCameraInteractor::viewAll ( SoNode node,
const SbViewportRegion vpRegion 
)

Move the camera to view the scene defined by the given node.

Equivalent to calling the SoCamera method viewAll(). The camera position is changed, but not the orientation.

  • Orthographic camera: the height field is changed.
  • Perspective camera: the heightAngle field is NOT changed.
void SoCameraInteractor::viewAll ( SoPath path,
const SbViewportRegion vpRegion 
)

Move the camera to view the scene defined by the given path.

Equivalent to calling the SoCamera method viewAll(). The camera position is changed, but not the orientation.

  • Orthographic camera: the height field is changed.
  • Perspective camera: the heightAngle field is NOT changed.
void SoCameraInteractor::viewAxis ( const SbVec3f direction,
const SbVec3f up 
)

Moves and rotates the camera to be aligned with the given direction vector while keeping the up direction of the camera parallel to the specified up vector.

The camera position and orientation are changed to look at the point of interest, but the focalDistance is not changed.

Parameters:
direction The new view direction vector: this is the vector from the camera's position to the target point. Any future call to the method getDirectionVector() will return the same vector.
up The new up direction vector
void SoCameraInteractor::viewIn ( SoNode node,
const SbViewportRegion vpRegion 
)

Move camera to the center of the scene defined by the specified node.

Compute the bounding box of the scene and move the camera to the center of this box. The near and far clipping planes will be adjusted to see the inside of the box.

Parameters:
node root node of the scene
vpRegion the actual viewport region
void SoCameraInteractor::viewIn ( SoPath path,
const SbViewportRegion vpRegion 
)

Move camera to the center of the scene defined by the specified path.

Compute the bounding box of the scene and move the camera to the center of this box. The near and far clipping planes will be adjusted to see the inside of the box.

Parameters:
path path to the scene
vpRegion the actual viewport region
void SoCameraInteractor::viewIn ( const SbBox3f bbox  ) 

Move camera to the center of the specified box.

The near and far clipping planes will be adjusted to see the inside of the box. If the box is empty, nothing happens.

void SoCameraInteractor::viewX ( bool  reverse = false  ) 

NOTE: The camera position is not changed, so the camera may not be looking toward the scene.

Calling viewAll() will move the camera so that the scene is visible again.

Parameters:
reverse If false, rotate to look in the -X direction, else in +X direction.
void SoCameraInteractor::viewY ( bool  reverse = false  ) 

Rotate camera to look parallel to the Y axis with +Z up.

NOTE: The camera position is not changed, so the camera may not be looking toward the scene. Calling viewAll() will move the camera so that the scene is visible again.

Parameters:
reverse If false, rotate to look in the -Y direction, else in +Y direction.
void SoCameraInteractor::viewZ ( bool  reverse = false  ) 

Rotate camera to look parallel to the Z axis with +Y up.

NOTE: The camera position is not changed, so the camera may not be looking toward the scene. Calling viewAll() will move the camera so that the scene is visible again.

Parameters:
reverse If false, rotate to look in the -Z direction, else in +Z direction.
virtual void SoCameraInteractor::zoom ( float  zoom  )  [virtual]

Zoom - Makes the scene appear larger or smaller.

Sets the camera's heightAngle field (for a perspective camera) or height field (for an orthographic camera) to the specified value. For a perspective camera, the value is in radians and the default is 0.785398. For an orthographic camera the value is in World Coordinates and the default is 2.

Conceptually, zoom means approximately the same thing as it does for a real camera - changing the "focal length" of the lens. Making the heightAngle (or height) larger corresponds to using a wide-angle lens, so the scene appears smaller. Making the heightAngle (or height) smaller corresponds to using a telephoto lens, so the scene appears larger.

NOTE: For a perspective camera, we strongly recommend implementing the visual effect of "zoom" by moving the camera closer to, or farther away from, the scene (see dolly()). Very small and very large values of heightAngle can produce undesirable results.

Parameters:
zoom new zoom value
void SoCameraInteractor::zoomInWindow ( const SbVec2f topLeftCorner,
const SbVec2f bottomRightCorner,
const SbViewportRegion vpRegion 
)

Zooms to the region defined by the given corners in normalized screen coordinates.

  • Perspective camera: This method modifies the heightAngle field.
    Modifying the heightAngle field changes the projection, similar to changing the focal length of a camera. Making the heightAngle very small or very large may cause rendering artifacts. Therefore the dollyInWindow method is recommended when using a perspective camera.
  • Orthographic camera: This method modifies the height field.
Parameters:
topLeftCorner top left corner in normalized screen coordinates (0 <= x,y <= 1)
bottomRightCorner bottom right corner in normalized screen coordinates (0 <= x,y <= 1)
vpRegion the actual viewport region

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

Open Inventor Toolkit reference manual, generated on 12 Feb 2024
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/