soraypickaction(3)
NAME
SoRayPickAction
SYNOPSIS
#include <Inventor/actions/SoRayPickAction.h> Inherits SoPickAction.
Detailed Description
The SoRayPickAction class does ray intersection with scene graphs.
For interaction with the scene graph geometry, it is necessary to be
able to do intersection testing for rays. This functionality is
provided by the SoRayPickAction class.
SoRayPickAction can be used to pass arbitrary rays through the scene for intersection detections, by using the setRay() method.
Because a very common operation is to check for intersections along the
ray from the mousecursor upon mouseclicks, it also contains convenience
methods for setting up a ray from the near plane to the far plane from
the 2D mousecursor coordinates. See the setPoint() and
setNormalizedPoint() methods. A simple usage example for this case is
presented below.
Note that one common mistake when using a raypick action to intersect
from a point under the mousecursor after a mouseclick is that one tries
to apply it to a scenegraph that does not contain a camera explicitly
set up by the application programmer. Without a camera as part of the
traversal, the raypick action does not know which view volume to send
the ray through.
- In this regard, be aware that the getSceneGraph() call in the
So*-libraries' viewer classes will return the root of the user-supplied scenegraph, not the 'real' internal scenegraph root used by the viewer (which should always contain a camera node). So raypicks done from the application code will fail when doing this: - // initializing viewer scenegraph
SoSeparator * root = new SoSeparator;
root->ref(); - SoEventCallback * ecb = new SoEventCallback;
ecb->addEventCallback(SoMouseButtonEvent::getClassTypeId(), event_cb, viewer);
root->addChild(ecb); - root->addChild(new SoCone);
- viewer->setSceneGraph( root );
// -- [snip] ------------------------ - // attempting raypick in the event_cb() callback method
SoRayPickAction rp( viewer->getViewportRegion() );
rp.setPoint(mouseevent->getPosition());
rp.apply(viewer->getSceneGraph());
// BUG: results will not be what you expected, as no camera was
// part of the 'user's scenegraph' - While this is the correct way to do it:
// initializing viewer scenegraph
SoSeparator * root = new SoSeparator;
root->ref();- // Need to set up our own camera in the 'user scenegraph', or else
// the raypick action will fail because the camera is hidden in the
// viewer-specific root of the scenegraph.
SoPerspectiveCamera * pcam = new SoPerspectiveCamera;
root->addChild(pcam); - SoEventCallback * ecb = new SoEventCallback;
ecb->addEventCallback(SoMouseButtonEvent::getClassTypeId(), event_cb, viewer);
root->addChild(ecb); - root->addChild(new SoCone);
- viewer->setSceneGraph( root );
pcam->viewAll( root, viewer->getViewportRegion() );
// -- [snip] ------------------------ - // attempting raypick in the event_cb() callback method
SoRayPickAction rp( viewer->getViewportRegion() );
rp.setPoint(mouseevent->getPosition());
rp.apply(viewer->getSceneGraph()); - Or if you do want the convenience of having the viewer set up a camera for you implicitly, you can get hold of the root-node of the 'complete' scenegraph by simply calling:
SoNode * realroot = viewer->getSceneManager()->getSceneGraph();- Public Member Functions
- virtual SoType getTypeId (void) const
SoRayPickAction (const SbViewportRegion &viewportregion) virtual ~SoRayPickAction ()
void setPoint (const SbVec2s &viewportPoint) void setNormalizedPoint (const SbVec2f &normpoint) void setRadius (const float radiusinpixels)
void setRay (const SbVec3f &start, const SbVec3f &direction, floatneardistance=-1.0, float fardistance=-1.0) - void setPickAll (const SbBool flag)
SbBool isPickAll (void) const
const SoPickedPointList & getPickedPointList (void) const SoPickedPoint * getPickedPoint (const int index=0) const void computeWorldSpaceRay (void) SbBool hasWorldSpaceRay (void) const
void setObjectSpace (void)
void setObjectSpace (const SbMatrix &matrix) SbBool intersect (const SbVec3f &v0, const SbVec3f &v1, const SbVec3f&v2, SbVec3f &intersection, SbVec3f &barycentric, SbBool &front) const - SbBool intersect (const SbVec3f &v0, const SbVec3f &v1, SbVec3f
&intersection) const
- SbBool intersect (const SbVec3f &point) const
SbBool intersect (const SbBox3f &box, const SbBool usefullviewvolume=1)
SbBool intersect (const SbBox3f &box, SbVec3f &intersection, const
SbBool usefullviewvolume=1)
- const SbViewVolume & getViewVolume (void)
const SbLine & getLine (void)
SbBool isBetweenPlanes (const SbVec3f &intersection) const SoPickedPoint * addIntersection (const SbVec3f &objectspacepoint) void reset (void) - Static Public Member Functions
- static SoType getClassTypeId (void) static void addMethod (const SoType type, SoActionMethod method) static void enableElement (const SoType type, const int stackindex) static void initClass (void)
- Protected Member Functions
- virtual const SoEnabledElementsList & getEnabledElements (void) const virtual void beginTraversal (SoNode *node)
- Static Protected Member Functions
- static SoEnabledElementsList * getClassEnabledElements (void) static SoActionMethodList * getClassActionMethods (void)
Constructor & Destructor Documentation
- SoRayPickAction::SoRayPickAction (const SbViewportRegion & viewportregion)
- Constructor.
- Some node types need a viewportregion to know exactly how they are
positioned within the scene. For an in-depth explanation of why the
viewportregion argument is needed, see the documentation of SoGetBoundingBox::SoGetBoundingBox(const SbViewportRegion &). - SoRayPickAction::~SoRayPickAction (void) [virtual]
- Destructor, free temporary resources used by action.
Member Function Documentation
- SoType SoRayPickAction::getTypeId (void) const [virtual]
- Returns the type identification of an action derived from a class
inheriting SoAction. This is used for run-time type checking and 'downward' casting. - Usage example:
void bar(SoAction * action)
{if (action->getTypeId() == SoGLRenderAction::getClassTypeId()) {// safe downward cast, know the type
SoGLRenderAction * glrender = (SoGLRenderAction *)action;}
return; // ignore if not renderaction} - For application programmers wanting to extend the library with new
actions: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the pre-defined macros available through Inventor/nodes/SoSubAction.h: SO_ACTION_SOURCE,
SO_ACTION_INIT_CLASS and SO_ACTION_CONSTRUCTOR. - For more information on writing Coin extensions, see the SoAction class documentation.
- Returns the actual type id of an object derived from a class inheriting SoAction. Needs to be overridden in all subclasses.
- Reimplemented from SoPickAction.
- SoType SoRayPickAction::getClassTypeId (void) [static]
- Returns the run-time type object associated with instances of this
class. - Reimplemented from SoPickAction.
- Referenced by SoShape::invokeTriangleCallbacks(), and
SoNode::rayPickS(). - void SoRayPickAction::addMethod (const SoType type, SoActionMethod method)
- [static]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - Reimplemented from SoPickAction.
- Referenced by SoBaseKit::~SoBaseKit(), and
SoGeoSeparator::~SoGeoSeparator(). - void SoRayPickAction::enableElement (const SoType type, const int
- stackindex) [static]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - Reimplemented from SoPickAction.
- const SoEnabledElementsList & SoRayPickAction::getEnabledElements (void)
- const [protected, virtual]
Returns a list of the elements used by action instances of this class
upon traversal operations. - Reimplemented from SoPickAction.
- SoEnabledElementsList * SoRayPickAction::getClassEnabledElements (void)
- [static, protected]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - This method not available in the original OIV API, see SoSubAction.h for explanation.
- Reimplemented from SoPickAction.
- SoActionMethodList * SoRayPickAction::getClassActionMethods (void) [static,
- protected]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - This method not available in the original OIV API, see SoSubAction.h for explanation.
- Reimplemented from SoPickAction.
- void SoRayPickAction::initClass (void) [static]
- Initializes the run-time type system for this class, and sets up the
enabled elements and action method list. - Reimplemented from SoPickAction.
- Referenced by SoAction::initClasses().
- void SoRayPickAction::setPoint (const SbVec2s & viewportpoint)
- Sets the viewport-space point. This point is calculated into a line
from the near clipping plane to the far clipping plane, and the
intersection ray follows the line. - This is a convenient way to detect object intersection below the
cursor. - void SoRayPickAction::setNormalizedPoint (const SbVec2f & normpoint)
- Sets the viewport-space point which the ray is sent through. The
coordinate is normalized, ranging from (0, 0) to (1, 1). - See also:
setPoint()
- void SoRayPickAction::setRadius (const float radiusinpixels)
- Sets the radius of the picking ray, in screen pixels. Default value is 5.0.
- The radius of the intersection ray will only influence the pick
operation's behavior versus lines and points, and has no effect on
picking of shapes / polygons. - void SoRayPickAction::setRay (const SbVec3f & start, const SbVec3f &
- direction, float neardistance = -1.0, float fardistance = -1.0) Sets the intersection ray in world-space coordinates.
- Use this method if you want to send any ray through the scene to detect
intersections, independently of mouse cursor position upon clicks and
scene graph camera settings. - References SoDebugError::postWarning().
- void SoRayPickAction::setPickAll (const SbBool flag)
- Lets you decide whether or not all the objects the ray intersects with
should be picked. If not, only the intersection point of the object
closest to the camera will be picked. - Default value of the 'pick all' flag is FALSE.
- Referenced by SoHandleEventAction::getPickedPoint(), and
SoHandleEventAction::getPickedPointList(). - SbBool SoRayPickAction::isPickAll (void) const
- Returns whether only the closest object or all the objects the ray
intersects with is picked. - See also:
setPickAll()
- const SoPickedPointList & SoRayPickAction::getPickedPointList (void) const
- Returns a list of the picked points.
- Referenced by getPickedPoint(), and
SoHandleEventAction::getPickedPointList(). - SoPickedPoint * SoRayPickAction::getPickedPoint (const int index = 0) const
- Returns the picked point with index in the list of picked points.
- Returns NULL if less than index + 1 points where picked during the last raypick action.
- References getPickedPointList().
- Referenced by SoHandleEventAction::getPickedPoint().
- void SoRayPickAction::computeWorldSpaceRay (void)
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SbViewVolume::getDepth(), SbLine::getDirection(),
SbViewVolume::getHeight(), SbViewVolume::getNearDist(),
SbLine::getPosition(), SbViewVolume::getProjectionDirection(),
SbViewVolume::getProjectionType(),
SbViewportRegion::getViewportOriginPixels(),
SbViewportRegion::getViewportSizePixels(), SbViewVolume::getWidth(),
SbViewVolume::narrow(), SbViewVolume::PERSPECTIVE,
SoDebugError::postWarning(), SbViewVolume::projectPointToLine(),
SbVec3d::setValue(), and SoAction::state. - SbBool SoRayPickAction::hasWorldSpaceRay (void) const
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- void SoRayPickAction::setObjectSpace (void)
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SoAction::state.
- Referenced by SoShape::computeObjectSpaceRay(), and
SoShape::endSolidShape(). - void SoRayPickAction::setObjectSpace (const SbMatrix & matrix)
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SoAction::state.
- SbBool SoRayPickAction::intersect (const SbVec3f & v0_in, const SbVec3f &
- v1_in, const SbVec3f & v2_in, SbVec3f & intersection, SbVec3f & barycentric, SbBool & front) const This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SbVec3d::cross(), SbVec3d::dot(), SbVec3f::setValue(), and
SbVec3d::setValue(). - Referenced by intersect(), SoShape::invokeLineSegmentCallbacks(),
SoShape::invokeTriangleCallbacks(), and
SoShape::shouldPrimitiveCount(). - SbBool SoRayPickAction::intersect (const SbVec3f & v0_in, const SbVec3f &
- v1_in, SbVec3f & intersection) const This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References intersect(), SbVec3f::setValue(), and SbVec3d::setValue().
- SbBool SoRayPickAction::intersect (const SbVec3f & point_in) const
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SbVec3d::setValue().
- SbBool SoRayPickAction::intersect (const SbBox3f & box, const SbBool
- usefullviewvolume = 1)
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - References intersect().
- SbBool SoRayPickAction::intersect (const SbBox3f & box, SbVec3f &
- intersection, const SbBool usefullviewvolume = 1) This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SbBox3f::getMax(), SbBox3f::getMin(), SbVec3f::setValue(),
and SbVec3d::setValue(). - const SbViewVolume & SoRayPickAction::getViewVolume (void)
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- References SoAction::getState().
- const SbLine & SoRayPickAction::getLine (void)
- This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
- SbBool SoRayPickAction::isBetweenPlanes (const SbVec3f & intersection_in)
- const
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - References SbVec3d::setValue(), and SoAction::state.
- Referenced by SoShape::invokeLineSegmentCallbacks(),
SoShape::invokePointCallbacks(), SoShape::invokeTriangleCallbacks(),
SoImage::rayPick(), and SoShape::shouldPrimitiveCount(). - SoPickedPoint * SoRayPickAction::addIntersection (const SbVec3f &
- objectspacepoint_in)
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. - References SoAction::getCurPath(), SbVec3d::setValue(), and
SoAction::state. - Referenced by SoShape::invokeLineSegmentCallbacks(),
SoShape::invokePointCallbacks(), SoShape::invokeTriangleCallbacks(),
SoImage::rayPick(), and SoShape::shouldPrimitiveCount(). - void SoRayPickAction::reset (void)
- Truncates the internal picked points list.
- Since:
Coin 2.2
- void SoRayPickAction::beginTraversal (SoNode * node) [protected, virtual]
- This virtual method is called from SoAction::apply(), and is the entry point for the actual scenegraph traversal.
- It can be overridden to initialize the action at traversal start, for
specific initializations in the action subclasses inheriting SoAction. - Default method just calls traverse(), which any overridden
implementation of the method must do too (or call
SoAction::beginTraversal()) to trigger the scenegraph traversal. - Reimplemented from SoPickAction.
- References SoPickAction::beginTraversal(), SoAction::getState(),
SoState::pop(), SoState::push(), SoAction::state, and
SoPickAction::vpRegion.
Author
- Generated automatically by Doxygen for Coin from the source code.