Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
IPickable Interface Referenceabstract

Abstract interface for objects that can be selected and interacted with using the mouse. More...

#include <IPickable.h>

Inheritance diagram for IPickable:
[legend]

Public Member Functions

virtual ~IPickable ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual std::optional< float > intersectsRay (const Math::Ray &ray) const =0
 Tests if a ray intersects this object's geometry.
 
virtual void handleClick (const Math::Ray &ray, float distance)=0
 Handles a mouse click on this object.
 
virtual void setHovered (bool hovered)=0
 Sets the hover state of this object.
 
virtual bool getHovered () const =0
 Gets the current hover state of this object.
 
virtual uint32_t getObjectID () const =0
 Gets the unique identifier for this object.
 

Detailed Description

Abstract interface for objects that can be selected and interacted with using the mouse.

This interface defines the contract for objects that support ray-based picking, hover states, and click handling. It is used by the scene manager to implement interactive object manipulation and selection.

The picking system uses CPU-based ray-object intersection tests, with some implementations delegating to GPU compute shaders for complex geometry.

Note
Implementations must maintain their own hover state and respond to state changes appropriately (e.g., visual feedback).
See also
SceneManager::updateHoverState()
SceneManager::handleMouseButton()
MathUtils::findFirstHit()

Definition at line 28 of file IPickable.h.

Constructor & Destructor Documentation

◆ ~IPickable()

virtual IPickable::~IPickable ( )
virtualdefault

Virtual destructor for proper cleanup of derived classes.

Member Function Documentation

◆ getHovered()

virtual bool IPickable::getHovered ( ) const
pure virtual

Gets the current hover state of this object.

Returns
true if the object is currently being hovered over, false otherwise.

Implemented in Gizmo, and SceneObject.

◆ getObjectID()

virtual uint32_t IPickable::getObjectID ( ) const
pure virtual

Gets the unique identifier for this object.

This ID is used to:

  • Correlate pick results with specific objects
  • Drive hover/selection highlighting through shader uniforms
  • Identify objects in the scene hierarchy
Returns
The object's unique identifier.
Note
This should return the same ID as IDrawable::getObjectID() for objects implementing a derived IDrawable interface and this interface.
See also
Scene::allocateObjectID()
IDrawable::getObjectID()

Implemented in Gizmo, and SceneObject.

Here is the caller graph for this function:

◆ handleClick()

virtual void IPickable::handleClick ( const Math::Ray ray,
float  distance 
)
pure virtual

Handles a mouse click on this object.

Called by the scene manager when the user clicks on this object. Implementations can respond by:

  • Changing selection state
  • Spawning interaction gizmos
  • Triggering object-specific behaviors
  • Emitting signals for UI updates
Parameters
rayThe picking ray that intersected this object.
distanceThe distance along the ray to the intersection point.
Note
This is only called if rayIntersection() returned a valid distance.
See also
SceneManager::handleMouseButton()
SceneObject::handleClick()
Gizmo::handleClick()

Implemented in Gizmo, and SceneObject.

Here is the caller graph for this function:

◆ intersectsRay()

virtual std::optional< float > IPickable::intersectsRay ( const Math::Ray ray) const
pure virtual

Tests if a ray intersects this object's geometry.

Implementations should test the ray against the object's bounding volume or exact geometry and return the distance to the intersection point if hit.

Parameters
rayThe picking ray in world space coordinates.
Returns
std::optional<float> containing the distance along the ray to the intersection point if hit, or std::nullopt if no intersection.
Note
For performance, implementations should first test against an AABB before performing exact mesh intersection tests.

Example implementation:

std::optional<float> SceneObject::intersectsRay(const MathUtils::Ray& ray) const {
float aabbDist;
if (!intersectsAABB(ray, aabbDist)) {
return std::nullopt;
}
float meshDist;
if (intersectsMesh(ray, meshDist)) {
return meshDist;
}
return std::nullopt;
}
std::optional< float > intersectsRay(const Math::Ray &ray) const override
Tests if a ray intersects this object's geometry.
See also
SceneObject::intersectsRay()
Gizmo::intersectsRay()
MathUtils::intersectsRay()

Implemented in Gizmo, and SceneObject.

Here is the caller graph for this function:

◆ setHovered()

virtual void IPickable::setHovered ( bool  hovered)
pure virtual

Sets the hover state of this object.

Called by the scene manager when the mouse cursor enters or leaves this object. Implementations should update their internal state and may trigger visual feedback (e.g., highlighting).

The actual visual feedback is typically handled through the rendering system via uniform buffers (isHovered[objectID]).

Parameters
hoveredtrue if the mouse is hovering over this object, false otherwise.
See also
SceneManager::updateHoverState()
Scene::draw()

Implemented in Gizmo, and SceneObject.


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