Interactive 3D manipulation widget for transforming scene objects.
More...
#include <Gizmo.h>
|
| | 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.
|
| |
| Mesh * | getMesh () const override |
| | Gets the shared mesh used for all handles.
|
| |
| Shader * | getShader () 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.
|
| |
| SceneObject * | getTarget () const |
| | Gets the object this gizmo is manipulating.
|
| |
| IHandle * | getActiveHandle () const |
| | Gets the currently active (being dragged) handle.
|
| |
| bool | getIsDragging () const |
| | Checks if a drag operation is in progress.
|
| |
| virtual | ~IDrawable ()=default |
| | Virtual destructor for proper cleanup of derived classes.
|
| |
| virtual | ~IPickable ()=default |
| | Virtual destructor for proper cleanup of derived classes.
|
| |
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:
- User hovers -> rayIntersection() identifies handle -> setHovered(true)
- User clicks -> handleClick() activates handle, calls setDragState()
- User drags -> handleDrag() updates via handle's onDrag()
- 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.
◆ Gizmo()
Constructs a gizmo for the specified target object.
- Parameters
-
| type | The type of gizmo (translate/rotate/scale). |
| sceneManager | Pointer to the scene manager (for object ID allocation). |
| target | The 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.
◆ ~Gizmo()
Destructor - frees object IDs and cleans up handles.
Definition at line 41 of file Gizmo.cpp.
◆ 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.
◆ 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.
◆ 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.
◆ getTarget()
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
-
| ray | The ray that hit the handle. |
| distance | Distance 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.
◆ 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
-
| ray | The current mouse ray in world space. |
Definition at line 106 of file Gizmo.cpp.
◆ 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
-
| ray | The 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.
◆ setHovered()
| void Gizmo::setHovered |
( |
bool |
hovered | ) |
|
|
overridevirtual |
Sets the gizmo's hover state.
- Parameters
-
| hovered | true 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: