Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

SoRayPickAction Class Reference

The SoRayPickAction class does ray intersection with scene graphs. More...

#include <Inventor/actions/SoRayPickAction.h>

Inheritance diagram for SoRayPickAction::

SoPickAction SoAction List of all members.

Public Methods

 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, float neardistance=-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=TRUE)
SbBool intersect (const SbBox3f &box, SbVec3f &intersection, const SbBool usefullviewvolume=TRUE)
const SbViewVolume & getViewVolume (void)
const SbLine & getLine (void)
SbBool isBetweenPlanes (const SbVec3f &intersection) const
SoPickedPoint * addIntersection (const SbVec3f &objectspacepoint)

Static Public Methods

void initClass (void)

Protected Methods

virtual void beginTraversal (SoNode *node)

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.

Note that one common mistake when using a raypick action 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 doing

  SoNode * realroot = viewer->getSceneManager()->getSceneGraph();


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.

SoRayPickAction::~SoRayPickAction (  void    )  [virtual]
 

Destructor, free temporary resources used by action.


Member Function Documentation

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.

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.

void SoRayPickAction::setRay (  const SbVec3f &    start,
const SbVec3f &    direction,
float    neardistance = -1.0,
float    fardistance = -1.0
) 
 

Sets the ray in world-space coordinates.

void SoRayPickAction::setPickAll (  const SbBool    flag ) 
 

Lets you decide whether only the closest object or all the objects the ray intersects with should be picked.

Default value of the "pick all" flag is FALSE.

SbBool SoRayPickAction::isPickAll (  void    )  const
 

Returns whether only the closest object or all the objects the ray intersects with is picked.

const SoPickedPointList & SoRayPickAction::getPickedPointList (  void    )  const
 

Returns a list of the picked points.

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.

void SoRayPickAction::computeWorldSpaceRay (  void    ) 
 

For internal use only.

SbBool SoRayPickAction::hasWorldSpaceRay (  void    )  const
 

For internal use only.

void SoRayPickAction::setObjectSpace (  void    ) 
 

For internal use only.

void SoRayPickAction::setObjectSpace (  const SbMatrix &    matrix ) 
 

For internal use only.

SbBool SoRayPickAction::intersect (  const SbVec3f &    v0,
const SbVec3f &    v1,
const SbVec3f &    v2,
SbVec3f &    intersection,
SbVec3f &    barycentric,
SbBool &    front
)  const
 

For internal use only.

SbBool SoRayPickAction::intersect (  const SbVec3f &    v0,
const SbVec3f &    v1,
SbVec3f &    intersection
)  const
 

For internal use only.

SbBool SoRayPickAction::intersect (  const SbVec3f &    point )  const
 

For internal use only.

SbBool SoRayPickAction::intersect (  const SbBox3f &    box,
const SbBool    usefullviewvolume = TRUE
) 
 

For internal use only.

SbBool SoRayPickAction::intersect (  const SbBox3f &    box,
SbVec3f &    intersection,
const SbBool    usefullviewvolume = TRUE
) 
 

For internal use only.

const SbViewVolume & SoRayPickAction::getViewVolume (  void    ) 
 

For internal use only.

const SbLine & SoRayPickAction::getLine (  void    ) 
 

For internal use only.

SbBool SoRayPickAction::isBetweenPlanes (  const SbVec3f &    intersection )  const
 

For internal use only.

SoPickedPoint * SoRayPickAction::addIntersection (  const SbVec3f &    objectspacepoint ) 
 

For internal use only.

void SoRayPickAction::beginTraversal (  SoNode *    node )  [protected, virtual]
 

Overloaded to set up internal data.

Reimplemented from SoPickAction.


The documentation for this class was generated from the following files:
Generated on Sat Jan 12 11:41:13 2002 for Coin by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001