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

Interactive 3D manipulation widget for transforming scene objects. More...

#include <Gizmo.h>

Inheritance diagram for Gizmo:
[legend]
Collaboration diagram for Gizmo:
[legend]

Public Member Functions

 Gizmo (GizmoType type, SceneManager *sceneManager, SceneObject *target)
 Constructs a gizmo for the specified target object.
 
 ~Gizmo ()
 Destructor - frees object IDs and cleans up handles.
 
void draw () const override
 Renders all handles with custom depth-test-disabled rendering.
 
uint32_t getObjectID () const override
 Gets the gizmo's unique identifier.
 
MeshgetMesh () const override
 Gets the shared mesh used for all handles.
 
ShadergetShader () const override
 Gets the shader used for gizmo rendering.
 
std::optional< float > intersectsRay (const Math::Ray &ray) const override
 Tests if a ray intersects any of the gizmo's handles.
 
void handleClick (const Math::Ray &ray, float distance) override
 Handles mouse click on a gizmo handle.
 
void setHovered (bool hovered) override
 Sets the gizmo's hover state.
 
bool getHovered () const override
 Gets the gizmo's hover state.
 
void handleRelease ()
 Handles mouse release - deactivates the active handle.
 
void handleDrag (const Math::Ray &ray)
 Updates the active handle during a drag operation.
 
SceneObjectgetTarget () const
 Gets the object this gizmo is manipulating.
 
IHandlegetActiveHandle () const
 Gets the currently active (being dragged) handle.
 
bool getIsDragging () const
 Checks if a drag operation is in progress.
 
- Public Member Functions inherited from IDrawable
virtual ~IDrawable ()=default
 Virtual destructor for proper cleanup of derived classes.
 
- Public Member Functions inherited from IPickable
virtual ~IPickable ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Detailed Description

Interactive 3D manipulation widget for transforming scene objects.

A Gizmo is a visual overlay that appears on selected objects, providing intuitive handles for translation, rotation, or scaling. It manages multiple IHandle instances (one per axis) and coordinates their rendering and interaction.

Architecture:

  • Gizmo owns and renders all handles as a batch
  • Implements ICustomDrawable for special rendering (depth-test disabled)
  • Implements IPickable for ray-based handle selection
  • Handles perform the actual transformation math

Rendering approach:

  • All handles share the same mesh (arrow/circle/cube)
  • Instanced rendering with per-handle transforms and colors
  • Rendered without depth testing to stay visible over scene
  • Hover highlighting shows which handle the cursor is over

Interaction flow:

  1. User hovers -> rayIntersection() identifies handle -> setHovered(true)
  2. User clicks -> handleClick() activates handle, calls setDragState()
  3. User drags -> handleDrag() updates via handle's onDrag()
  4. User releases -> handleRelease() deactivates handle
Note
Only one handle can be active (dragging) at a time.
See also
IHandle
TranslateHandle
RotateHandle
ScaleHandle
SceneManager::setGizmoFor()

Definition at line 62 of file Gizmo.h.

Constructor & Destructor Documentation

◆ Gizmo()

Gizmo::Gizmo ( GizmoType  type,
SceneManager sceneManager,
SceneObject target 
)

Constructs a gizmo for the specified target object.

Parameters
typeThe type of gizmo (translate/rotate/scale).
sceneManagerPointer to the scene manager (for object ID allocation).
targetThe scene object this gizmo will manipulate.
Note
Allocates object IDs for the gizmo and all its handles.

Definition at line 13 of file Gizmo.cpp.

Here is the call graph for this function:

◆ ~Gizmo()

Gizmo::~Gizmo ( )

Destructor - frees object IDs and cleans up handles.

Definition at line 41 of file Gizmo.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ draw()

void Gizmo::draw ( ) const
overridevirtual

Renders all handles with custom depth-test-disabled rendering.

Disables depth testing so gizmo stays visible through other objects, then uses instanced rendering to draw all handles in one call.

Each handle is colored based on its axis (R/G/B for X/Y/Z). The active handle (if dragging) uses its own object ID for precise picking, otherwise all handles share the gizmo's object ID.

Implements ICustomDrawable.

Definition at line 46 of file Gizmo.cpp.

Here is the call graph for this function:

◆ getActiveHandle()

IHandle * Gizmo::getActiveHandle ( ) const
inline

Gets the currently active (being dragged) handle.

Returns
Pointer to the active handle, or nullptr if none.

Definition at line 177 of file Gizmo.h.

◆ getHovered()

bool Gizmo::getHovered ( ) const
overridevirtual

Gets the gizmo's hover state.

Returns
true if hovered, false otherwise.

Implements IPickable.

Definition at line 122 of file Gizmo.cpp.

◆ getIsDragging()

bool Gizmo::getIsDragging ( ) const
inline

Checks if a drag operation is in progress.

Returns
true if currently dragging a handle, false otherwise.

Definition at line 183 of file Gizmo.h.

◆ getMesh()

Mesh * Gizmo::getMesh ( ) const
inlineoverridevirtual

Gets the shared mesh used for all handles.

Returns
Pointer to the handle mesh (arrow/circle/cube).

Implements IDrawable.

Definition at line 103 of file Gizmo.h.

Here is the caller graph for this function:

◆ getObjectID()

uint32_t Gizmo::getObjectID ( ) const
overridevirtual

Gets the gizmo's unique identifier.

Returns
The gizmo's object ID.

Implements IDrawable.

Definition at line 126 of file Gizmo.cpp.

◆ getShader()

Shader * Gizmo::getShader ( ) const
overridevirtual

Gets the shader used for gizmo rendering.

Returns
Pointer to the gizmo shader.

Implements IDrawable.

Definition at line 114 of file Gizmo.cpp.

Here is the caller graph for this function:

◆ getTarget()

SceneObject * Gizmo::getTarget ( ) const
inline

Gets the object this gizmo is manipulating.

Returns
Pointer to the target scene object.

Definition at line 171 of file Gizmo.h.

◆ handleClick()

void Gizmo::handleClick ( const Math::Ray ray,
float  distance 
)
overridevirtual

Handles mouse click on a gizmo handle.

Activates the hovered handle and initializes its drag state.

Parameters
rayThe ray that hit the handle.
distanceDistance along the ray to the hit point.
Note
Only called if rayIntersection() returned a valid distance.

Implements IPickable.

Definition at line 92 of file Gizmo.cpp.

Here is the call graph for this function:

◆ handleDrag()

void Gizmo::handleDrag ( const Math::Ray ray)

Updates the active handle during a drag operation.

Calls onDrag() on the active handle with the current mouse ray.

Parameters
rayThe current mouse ray in world space.

Definition at line 106 of file Gizmo.cpp.

Here is the call graph for this function:

◆ handleRelease()

void Gizmo::handleRelease ( )

Handles mouse release - deactivates the active handle.

Clears activeHandle and sets isDragging to false.

Definition at line 101 of file Gizmo.cpp.

◆ intersectsRay()

std::optional< float > Gizmo::intersectsRay ( const Math::Ray ray) const
overridevirtual

Tests if a ray intersects any of the gizmo's handles.

Tests each handle's AABB for intersection and returns the closest hit. Updates hoveredHandle to support hover highlighting.

Parameters
rayThe picking ray in world space.
Returns
Distance to the closest handle hit, or std::nullopt if no hit.
Note
Sets hoveredHandle as a side effect (hence mutable).

Implements IPickable.

Definition at line 68 of file Gizmo.cpp.

Here is the call graph for this function:

◆ setHovered()

void Gizmo::setHovered ( bool  hovered)
overridevirtual

Sets the gizmo's hover state.

Parameters
hoveredtrue if mouse is over any handle, false otherwise.

Implements IPickable.

Definition at line 118 of file Gizmo.cpp.


The documentation for this class was generated from the following files: