SoRayPickAction(3)
π SoRayPickAction(3) π
Library Functions Manual β and yes bestie, this is SoRayPickAction(3), she's the ray-intersection queen of the scene graph and we're about to stan π
β¨ NAME β¨
SoRayPickAction β the class that does ray intersection with scene graphs. no cap, that's literally her whole job π―
πΈ SYNOPSIS πΈ
#include <Inventor/actions/SoRayPickAction.h>
Inherits SoPickAction. so she's got that pick-action bloodline, iykyk π§¬
π Public Member Functions
virtual SoType getTypeId (void) constβ the type-id moment, virtual, const, classic.SoRayPickAction (const SbViewportRegion &viewportregion)β the constructor, takes a viewport region π«Άvirtual ~SoRayPickAction ()β the destructor, virtual, she cleans up after herself.void setPoint (const SbVec2s &viewportPoint)β drop a point on her.void setNormalizedPoint (const SbVec2f &normpoint)β the normalized version, fancy β¨void setRadius (const float radiusinpixels)β radius, in pixels fr.void setRay (const SbVec3f &start, const SbVec3f &direction, float neardistance=-1.0, float fardistance=-1.0)β hand her a whole custom ray, near and far defaults are-1.0π₯void setPickAll (const SbBool flag)β you want ALL the hits? say less.SbBool isPickAll (void) constβ and this tells you if you did that.const SoPickedPointList & getPickedPointList (void) constβ the whole list of picked points, hand it over πSoPickedPoint * getPickedPoint (const int index=0) constβ just one, defaults to index0.void computeWorldSpaceRay (void)β go compute that world space ray bestie.SbBool hasWorldSpaceRay (void) constβ do we have one? asking for me.void setObjectSpace (void)β object space mode, activate.void setObjectSpace (const SbMatrix &matrix)β or object space with a matrix, she's flexible like that.SbBool intersect (const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2, SbVec3f &intersection, SbVec3f &barycentric, SbBool &front) constβ triangle intersect, with barycentric coords AND a front flag, she's thorough πSbBool intersect (const SbVec3f &v0, const SbVec3f &v1, SbVec3f &intersection) constβ the lowkey two-vector version.SbBool intersect (const SbVec3f &point) constβ just a point, simple, minimal, elegant.SbBool intersect (const SbBox3f &box, const SbBool usefullviewvolume=1)β box intersect,usefullviewvolumedefaults to1.SbBool intersect (const SbBox3f &box, SbVec3f &intersection, const SbBool usefullviewvolume=1)β same box but she also gives you the intersection point,usefullviewvolume=1again.const SbViewVolume & getViewVolume (void)β grab the view volume πconst SbLine & getLine (void)β grab the line.SbBool isBetweenPlanes (const SbVec3f &intersection) constβ is it between the planes? const, obviously.SoPickedPoint * addIntersection (const SbVec3f &objectspacepoint)β add an intersection in object space, she'll hand you a picked point back.void reset (void)β factory reset her, periodt.
π Public Member Functions inherited from SoPickAction
the family tree, exact signatures, no edits bestie:
void setViewportRegion (const SbViewportRegion &newregion)
const SbViewportRegion & getViewportRegion (void)
void enableCulling (const SbBool flag)
SbBool isCullingEnabled () const
π¦ Public Member Functions inherited from SoAction
look at this legacy, she inherited the whole wardrobe:
virtual ~SoAction ()
virtual SbBool isOfType (SoType type) const
virtual void apply (SoNode *root)
virtual void apply (SoPath *path)
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=0)
void apply (SoAction *beingApplied)
virtual void invalidateState (void)
AppliedCode getWhatAppliedTo (void) const
SoNode * getNodeAppliedTo (void) const
SoPath * getPathAppliedTo (void) const
const SoPathList * getPathListAppliedTo (void) const
const SoPathList * getOriginalPathListAppliedTo (void) const
SbBool isLastPathListAppliedTo (void) const
PathCode getPathCode (int &numindices, const int *&indices)
void traverse (SoNode *const node)
SbBool hasTerminated (void) const
const SoPath * getCurPath (void)
SoState * getState (void) const
PathCode getCurPathCode (void) const
virtual SoNode * getCurPathTail (void)
void usePathCode (int &numindices, const int *&indices)
void pushCurPath (const int childindex, SoNode *node=NULL)
void popCurPath (const PathCode prevpathcode)
void pushCurPath (void)
void popPushCurPath (const int childindex, SoNode *node=NULL)
void popCurPath (void)
void switchToPathTraversal (SoPath *path)
void switchToNodeTraversal (SoNode *node)
β Static Public Member Functions
static SoType getClassTypeId (void)β class type id, static, as a treat.static void addMethod (const SoType type, SoActionMethod method)β register a method.static void enableElement (const SoType type, const int stackindex)β enable an element at a stack index.static void initClass (void)β init the class, the classic ritual π
π Static Public Member Functions inherited from SoPickAction
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)
πΈ Static Public Member Functions inherited from SoAction
static void initClass (void)
static void initClasses (void)
static SoType getClassTypeId (void)
static void nullAction (SoAction *action, SoNode *node)
π§ Protected Member Functions
virtual const SoEnabledElementsList & getEnabledElements (void) constβ protected, virtual, gives you the enabled elements list.virtual void beginTraversal (SoNode *node)β protected, virtual, kicks off the traversal.
π Protected Member Functions inherited from SoPickAction
SoPickAction (const SbViewportRegion &viewportregion)
virtual ~SoPickAction ()
π Protected Member Functions inherited from SoAction
SoAction (void)
virtual void endTraversal (SoNode *node)
void setTerminated (const SbBool flag)
virtual SbBool shouldCompactPathList (void) const
β¨ Static Protected Member Functions
static SoEnabledElementsList * getClassEnabledElements (void)
static SoActionMethodList * getClassActionMethods (void)
π Static Protected Member Functions inherited from SoPickAction
static SoEnabledElementsList * getClassEnabledElements (void)
static SoActionMethodList * getClassActionMethods (void)
π«Ά Static Protected Member Functions inherited from SoAction
static SoEnabledElementsList * getClassEnabledElements (void)
static SoActionMethodList * getClassActionMethods (void)
π Additional Inherited Members
Public Types inherited from SoAction
enum AppliedCode { NODE = 0, PATH = 1, PATH_LIST = 2 }
enum PathCode { NO_PATH = 0, IN_PATH = 1, BELOW_PATH = 2, OFF_PATH = 3 }
Protected Attributes inherited from SoPickAction
SbViewportRegion vpRegion
Protected Attributes inherited from SoAction
SoState * state
SoActionMethodList * traversalMethods
π Detailed Description π
The SoRayPickAction class does ray intersection with scene graphs. that's the whole vibe, that's her brand π
okay so, for your scene graph geometry to actually interact with stuff, you need to be able to do intersection testing for rays. that functionality? yeah, it's provided by the SoRayPickAction class. she's the one π₯
SoRayPickAction can be used to pass arbitrary rays through the scene for intersection detections, by using the setRay() method. arbitrary rays!! go off β¨
and because a very common operation is checking for intersections along the ray from the mousecursor upon mouseclicks (we've all been there), she 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 π
β οΈ okay this part matters bestie. 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. she can't read your mind, she needs a camera π
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"
yeah that's the bug bestie, do not do that π
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());
see? camera in the user scenegraph. slay π
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();
there's your realroot bestie, go get her π¦
π Constructor & Destructor Documentation π
π SoRayPickAction::SoRayPickAction (const SbViewportRegion & viewportregion)
constructor. she's born π
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 &).
references SoRayPickAction().
referenced by addMethod(), and SoRayPickAction().
π¦ SoRayPickAction::~SoRayPickAction (void ) [virtual]
destructor, free temporary resources used by action. she cleans up her own mess, as she should π§Ήβ¨
β¨ Member Function Documentation β¨
okay so bestie, we're in the deep end now β all the member functions, one by one, no skips. let's go π
SoType SoRayPickAction::getTypeId (void ) const [virtual]
slay, this one gives you the type ID of an action that inherits from SoAction. it's for run-time type checking and "downward" casting, iykyk.
usage example, bestie:
void bar(SoAction * action)
{
if (action->getTypeId() == SoGLRenderAction::getClassTypeId()) {
// safe downward cast, know the type
SoGLRenderAction * glrender = (SoGLRenderAction *)action;
}
return; // ignore if not renderaction
}
if you're an app programmer wanting to extend the library with new actions, listen up: this method needs to be overridden in all subclasses. it's typically done as part of setting up the full type system for extension classes, usually using the pre-defined macros available through Inventor/nodes/SoSubAction.h: SO_ACTION_SOURCE, SO_ACTION_INIT_CLASS, and SO_ACTION_CONSTRUCTOR.
for more info on writing Coin extensions, check 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.
void SoRayPickAction::addMethod (const SoType type, SoActionMethod method) [static]
okay so this one is internal to the library β not likely to be of interest to the application programmer, fr fr.
References: SoPickAction::SoPickAction(), and SoRayPickAction().
Referenced by: SoDragger::initClass().
void SoRayPickAction::enableElement (const SoType type, const int stackindex) [static]
yep, this is another internal one, bestie. not likely to be of interest to the application programmer.
const SoEnabledElementsList & SoRayPickAction::getEnabledElements (void ) const [protected], [virtual]
this returns a list of the elements used by action instances of this class during traversal operations. periodt.
Reimplemented from SoPickAction.
void SoRayPickAction::setPoint (const SbVec2s & viewportpoint)
sets the viewport-space point. this point gets calculated into a line from the near clipping plane to the far clipping plane, and the intersection ray follows that line.
it's a convenient way to detect object intersection below the cursor. so handy.
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.
important caveat: 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. so don't come for me, bestie.
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. big main character energy.
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. obsessed.
References: SbPList::getLength().
Referenced by: getPickedPoint(), SoHandleEventAction::getPickedPointList(), and SoBaseKit::rayPick().
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 were picked during the last raypick action. careful with that one.
References: getPickedPointList().
Referenced by: SoHandleEventAction::getPickedPoint().
void SoRayPickAction::computeWorldSpaceRay (void )
internal API alert β not likely to be of interest to the application programmer, bestie.
References: SbVec3d::dot(), SbViewVolume::getDepth(), SbLine::getDirection(), SbViewVolume::getHeight(), SbViewVolume::getNearDist(), SbLine::getPosition(), SbViewVolume::getProjectionDirection(), SbViewVolume::getProjectionType(), SbViewportRegion::getViewportOriginPixels(), SbViewportRegion::getViewportSizePixels(), SbViewVolume::getWidth(), SbViewVolume::narrow(), SbVec3d::normalize(), SbViewVolume::PERSPECTIVE, SoDebugError::postWarning(), SbViewVolume::projectPointToLine(), SbVec2s::setValue(), SbVec3d::setValue(), and SoAction::state.
Referenced by: SoCamera::rayPick().
SbBool SoRayPickAction::hasWorldSpaceRay (void ) const
another internal one, not likely to be of interest to the application programmer.
Referenced by: SoSeparator::rayPick(), and SoVRMLGroup::rayPick().
void SoRayPickAction::setObjectSpace (void )
yep, internal. not likely to be of interest to the application programmer.
References: SoAction::state.
Referenced by: SoShape::computeObjectSpaceRay(), SoShape::computeObjectSpaceRay(), and SoText2::rayPick().
void SoRayPickAction::setObjectSpace (const SbMatrix & matrix)
also internal, bestie. 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
internal β not likely to be of interest to the application programmer.
References: SbVec3d::cross(), SbVec3d::dot(), SbVec3d::setValue(), and SbVec3f::setValue().
Referenced by: intersect(), intersect(), SoShape::invokeLineSegmentCallbacks(), SoShape::invokePointCallbacks(), SoShape::invokeTriangleCallbacks(), SoImage::rayPick(), and SoText2::rayPick().
SbBool SoRayPickAction::intersect (const SbVec3f & v0_in, const SbVec3f & v1_in, SbVec3f & intersection) const
internal again. not likely to be of interest to the application programmer.
References: intersect(), SbVec3d::setValue(), and SbVec3f::setValue().
SbBool SoRayPickAction::intersect (const SbVec3f & point_in) const
internal β you know the drill. not likely to be of interest to the application programmer.
References: SbVec3d::setValue().
SbBool SoRayPickAction::intersect (const SbBox3f & box, const SbBool usefullviewvolume = 1)
internal. not likely to be of interest to the application programmer.
References: intersect().
SbBool SoRayPickAction::intersect (const SbBox3f & box, SbVec3f & intersection, const SbBool usefullviewvolume = 1)
internal. not likely to be of interest to the application programmer.
References: SbBox3f::getMax(), SbBox3f::getMin(), SbVec3d::setValue(), and SbVec3f::setValue().
const SbViewVolume & SoRayPickAction::getViewVolume (void )
internal β not likely to be of interest to the application programmer.
References: SoAction::getState().
const SbLine & SoRayPickAction::getLine (void )
internal. not likely to be of interest to the application programmer.
SbBool SoRayPickAction::isBetweenPlanes (const SbVec3f & intersection_in) const
internal. 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 SoText2::rayPick().
SoPickedPoint * SoRayPickAction::addIntersection (const SbVec3f & objectspacepoint_in)
internal. 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 SoText2::rayPick().
void SoRayPickAction::reset (void )
truncates the internal picked points list. clean slate, bestie.
Since: Coin 2.2
void SoRayPickAction::beginTraversal (SoNode * node) [protected], [virtual]
this virtual method is called from SoAction::apply(), and it's 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.
the 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. no human wrote this, wild.
and that's the whole page, bestie. this was Coin, version 2.5.0, for SoRayPickAction(3). stay iconic πβ¨
π¦ where this page comes from
- fedora 43: Coin2-devel 2.5.0-52.fc43 Β· GPL-2.0-only
- fedora 43: Coin2-devel 2.5.0-52.fc43 Β· GPL-2.0-only
- fedora 44: Coin2-devel 2.5.0-54.fc44 Β· GPL-2.0-only
- fedora 44: Coin2-devel 2.5.0-54.fc44 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms