public class SoCameraInteractor extends Inventor implements SafeDisposable
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:
activateOrbiting()
.
orbit()
.
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/com/openinventor/inventor/viewercomponents/nodes
See also:
SceneInteractor, SceneExaminer
Inventor.ConstructorCommand
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoCameraInteractor(SoCamera camera)
Create a
SoCameraInteractor for the specified camera. |
Modifier and Type | Method and Description |
---|---|
void |
activateOrbiting(SbVec2f startPos)
Set the starting point for interactive orbiting.
|
void |
activatePanning(SbVec2f initPos,
SbViewportRegion vpRegion)
Set the starting point for interactive panning.
|
void |
adjustClippingPlanes(SoNode sceneRoot,
SbViewportRegion vpRegion)
Adjust near and far clipping planes to minimize clipping of objects in the scene.
|
void |
changeViewVolume(float height,
float aspect)
Change camera's view volume.
|
boolean |
dispose()
Explicitly call this method to force object to dispose its unmanaged
resources.
|
void |
dolly(float scaleFactor)
Dolly - Makes the scene appear larger or smaller.
|
void |
dollyInWindow(SbVec2f topLeftCorner,
SbVec2f bottomRightCorner,
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.
|
void |
dollyWithZoomCenter(SbVec2f centerPos,
float scaleFactor,
SbViewportRegion vpRegion)
Modifies the camera to ajust the view around the specified point.
|
SoCamera |
getCamera()
Returns the associated camera.
|
SbVec3f |
getDirectionVector()
Returns the direction vector of the camera.
|
SbVec3f |
getFocalPoint()
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).
|
static SoCameraInteractor |
getNewInstance(SoCamera camera)
Create an instance for the specified camera.
|
SbVec3f |
getViewportCenter()
Deprecated.
As of Open Inventor 9500 See documentation for more details
|
boolean |
isDisposable()
Returns a boolean flag which indicates if it is safe to call
SafeDisposable.dispose() on the object. |
SbRotation |
lookAt(SbVec3f position,
SbVec3f target,
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.
|
void |
orbit(SbRotation rotation)
Orbit the camera by the specified rotation.
|
void |
orbit(SbVec2f newPos)
Orbit the camera based on offset from the previous screen position.
|
void |
pan(SbVec2f newPos,
SbViewportRegion vpRegion)
Pan the camera based on offset from starting point.
|
void |
pivot(float angle)
Pivot the camera.
|
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 world coordinate y-axis.
|
boolean |
popCamera()
Restore saved camera.
|
SbVec3f |
projectToPlane(SbVec2f point,
float distFromEye,
SbViewportRegion vpRegion)
Project specified 2D point on the plane parallel to the near plane that is at
distFromEye units from the eye, see also
SbViewVolume.getPlanePoint . |
SbVec2f |
projectToScreen(SbVec3f point,
SbViewportRegion vpRegion)
Map a 3D point in world coordinates to a 2D point in normalized screen coordinates (0 <= x,y <= 1), see also
SbViewVolume.projectToScreen . |
void |
pushCamera()
Save current camera.
|
void |
roll(float angle)
Roll the camera.
|
void |
rotate(float angle)
Rotate the camera around the center specified by
setRotationCenter() and the axis specified by setRotationAxis() . |
void |
rotate(SbRotation rot)
Rotate the camera.
|
void |
setOrientation(SbRotation rot)
Set the orientation of the camera.
|
void |
setPosition(SbVec2f pos,
float distFromEye,
SbViewportRegion vpRegion)
Move camera to the specified position.
|
void |
setPosition(SbVec3f pos)
Move camera to the specified position.
|
void |
setRotationAxis(SbVec3f axis)
Set the axis of rotation.
|
void |
setRotationCenter(SbVec3f pos)
Set the center of rotation.
|
void |
synchronize(SoCamera camera)
Copy field values from the specified camera to the camera of this interactor.
|
void |
tilt(float angle)
Tilt the camera.
|
void |
translate(SbVec2f displacement,
SbViewportRegion vpRegion)
Move camera by the specified 2D displacement.
|
void |
translate(SbVec3f trans)
Move camera by the specified 3D displacement.
|
void |
viewAll(SoNode node,
SbViewportRegion vpRegion)
Move the camera to view the scene defined by the given node.
|
void |
viewAll(SoPath path,
SbViewportRegion vpRegion)
Move the camera to view the scene defined by the given path.
|
void |
viewAxis(SbVec3f direction,
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.
|
void |
viewIn(SbBox3f bbox)
Move camera to the center of the specified box.
|
void |
viewIn(SoNode node,
SbViewportRegion vpRegion)
Move camera to the center of the scene defined by the specified node.
|
void |
viewIn(SoPath path,
SbViewportRegion vpRegion)
Move camera to the center of the scene defined by the specified path.
|
void |
viewX()
Calls viewX((boolean)false).
|
void |
viewX(boolean reverse)
NOTE: The camera
position is not changed, so the camera may not be looking toward the scene.
|
void |
viewY()
Calls viewY((boolean)false).
|
void |
viewY(boolean reverse)
Rotate camera to look parallel to the Y axis with +Z up.
|
void |
viewZ()
Calls viewZ((boolean)false).
|
void |
viewZ(boolean reverse)
Rotate camera to look parallel to the Z axis with +Y up.
|
void |
zoom(float zoom)
Zoom - Makes the scene appear larger or smaller.
|
void |
zoomInWindow(SbVec2f topLeftCorner,
SbVec2f bottomRightCorner,
SbViewportRegion vpRegion)
Zooms to the region defined by the given corners in normalized screen coordinates.
|
getAddress, getNativeResourceHandle, startInternalThreads, stopInternalThreads
public SoCameraInteractor(SoCamera camera)
SoCameraInteractor
for the specified camera.
The camera should be an SoPerspectiveCamera
or SoOrthographicCamera
object. Create an empty object if camera pointer is NULL or invalidpublic void viewZ()
public void viewY()
public void viewX()
public boolean isDisposable()
SafeDisposable
SafeDisposable.dispose()
on the object.isDisposable
in interface SafeDisposable
true
if the object can be disposed in a safe mannerpublic boolean dispose()
Inventor
dispose
in interface SafeDisposable
dispose
in class Inventor
true
if this object native resources were successfully
disposed; false
if it was already disposed or no
native resources has been registered for this object.public void setPosition(SbVec2f pos, float distFromEye, SbViewportRegion vpRegion)
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 regionpublic void orbit(SbRotation rotation)
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()
.
rotation
- Incremental rotation, i.e. this rotation is multiplied with the current camera orientation.public void orbit(SbVec2f newPos)
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.
newPos
- new position, 2D point in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent
method getNormalizedPosition().public void pushCamera()
popCamera()
.public void setPosition(SbVec3f pos)
pos
- new position in world coordinatespublic void pan(SbVec2f newPos, SbViewportRegion vpRegion)
activatePanning()
method should be called at the start of the operation.
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 regionpublic void pointAt(SbVec3f targetPoint)
SoCamera
method pointAt()
.
targetPoint
- target pointpublic void translate(SbVec2f displacement, SbViewportRegion vpRegion)
displacement
- 2D displacement in normalized screen coordinates: 0 <= x,y <= 1
vpRegion
- the actual viewport regionpublic void translate(SbVec3f trans)
trans
- translation value in world coordinatespublic void activateOrbiting(SbVec2f startPos)
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()
.
startPos
- starting position, 2D point in normalized screen coordinates (0 <= x,y <= 1). Typically this value is obtained from the SoEvent
method getNormalizedPosition().public SbVec3f getFocalPoint()
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.
public void dolly(float scaleFactor)
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'.
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.
dolly()
method computes a scale factor from the 'delta' parameter and multiplies the camera's
height field by this scale factor.
public void changeViewVolume(float height, float aspect)
height
- new camera height or heightAngle
aspect
- new camera aspect ratiopublic void zoom(float zoom)
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.
zoom
- new zoom valuepublic void viewY(boolean reverse)
viewAll()
will move the camera so that the scene is visible again.
reverse
- If false, rotate to look in the -Y direction, else in +Y direction.@Deprecated public SbVec3f getViewportCenter()
getFocalPoint()
instead. public boolean popCamera()
public void synchronize(SoCamera camera)
public static SoCameraInteractor getNewInstance(SoCamera camera)
SoPerspectiveCamera
or SoOrthographicCamera
object. Returns null if the camera parameter is null.public SoCamera getCamera()
public void viewAll(SoPath path, SbViewportRegion vpRegion)
public void setRotationAxis(SbVec3f axis)
rotate(float)
method.
axis
- new rotations axispublic void viewIn(SoNode node, SbViewportRegion vpRegion)
node
- root node of the scene
vpRegion
- the actual viewport regionpublic void setOrientation(SbRotation rot)
rot
- new orientationpublic void viewAll(SoNode node, SbViewportRegion vpRegion)
public void setRotationCenter(SbVec3f pos)
rotate(float)
and orbit()
methods.
pos
- position in world coordinatespublic void viewIn(SbBox3f bbox)
public void viewX(boolean reverse)
viewAll()
will move the camera so that the scene is visible again.
reverse
- If false, rotate to look in the -X direction, else in +X direction.public void viewZ(boolean reverse)
viewAll()
will move the camera so that the scene is visible again.
reverse
- If false, rotate to look in the -Z direction, else in +Z direction.public void rotate(float angle)
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()
.
angle
- angle in radianspublic void viewIn(SoPath path, SbViewportRegion vpRegion)
path
- path to the scene
vpRegion
- the actual viewport regionpublic void viewAxis(SbVec3f direction, SbVec3f up)
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 vectorpublic SbVec3f projectToPlane(SbVec2f point, float distFromEye, SbViewportRegion vpRegion)
SbViewVolume.getPlanePoint
.
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
public SbVec3f getDirectionVector()
public void dollyInWindow(SbVec2f topLeftCorner, SbVec2f bottomRightCorner, SbViewportRegion vpRegion)
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.
public void roll(float angle)
angle
- angle in radianspublic void activatePanning(SbVec2f initPos, SbViewportRegion vpRegion)
pan()
method with the new cursor or touch position.
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 regionpublic SbRotation lookAt(SbVec3f position, SbVec3f target, SbVec3f up)
position
- of the camera
target
- position of the target
up
- up vector of the camerapublic void dollyWithZoomCenter(SbVec2f centerPos, float scaleFactor, SbViewportRegion vpRegion)
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.
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 regionpublic void tilt(float angle)
angle
- angle in radianspublic SbVec2f projectToScreen(SbVec3f point, SbViewportRegion vpRegion)
SbViewVolume.projectToScreen
.
point
- point to project in world coordinates
vpRegion
- the actual viewport region
public void rotate(SbRotation rot)
rot
- new rotationpublic void zoomInWindow(SbVec2f topLeftCorner, SbVec2f bottomRightCorner, SbViewportRegion vpRegion)
dollyInWindow
method is recommended when using a perspective camera.
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 regionpublic void pivot(float angle)
angle
- angle in radianspublic void adjustClippingPlanes(SoNode sceneRoot, SbViewportRegion vpRegion)
Generated on January 23, 2025, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com