An immediate-mode 3D view gizmo for Dear ImGui, inspired by the navigation widgets in Blender and Godot.
It provides a set of interactive viewport widgets to intuitively control your camera in 3D scenes.
- Immediate-mode API following Dear ImGui principles.
- Three built-in widgets for camera control:
- Rotate – click and drag the gizmo to orbit the camera around a pivot.
- Dolly – zoom the camera in/out with a dedicated button and drag interaction.
- Pan – move the camera laterally using a pan widget.
- Axis-aligned snapping with smooth animation for precise orientation.
- Fully customizable styles: colors, sizes, labels, highlight effects, and animation settings.
- Single-header implementation with minimal dependencies.
These examples assume you have a camera with position (glm::vec3 or your math library equivalent) and rotation (glm::quat or equivalent).
Renders the main orbit gizmo. Drag to rotate the camera or click an axis to snap to a predefined view.
if (ImViewGuizmo::Rotate(camera_position, camera_rotation, gizmoPos))
{
// Camera was modified, update your camera system
}Renders a zoom button. Click and drag vertically to move the camera forward/backward along its local forward axis.
if (ImViewGuizmo::Zoom(camera_position, camera_rotation, zoomButtonPos))
{
// Camera was modified
}Renders a pan button. Click and drag to move the camera parallel to the view plane.
if (ImViewGuizmo::Pan(camera_position, camera_rotation, panButtonPos))
{
// Camera was modified
}You can check whether the gizmo or its tools are being used:
if (ImViewGuizmo::IsUsing())
// A gizmo tool is currently active
if (ImViewGuizmo::IsOver())
// Mouse is hovering the gizmo or any tool buttonCustomize the appearance of the gizmo via ImViewGuizmo::GetStyle():
auto& style = ImViewGuizmo::GetStyle();
style.scale = 1.5f;
style.axisColors[0] = IM_COL32(255, 0, 0, 255); // X-axis
style.labelColor = IM_COL32(255, 255, 0, 255);
style.animateSnap = true;
style.snapAnimationDuration = 0.5f;You can adjust line lengths, circle radii, highlight effects, tool button sizes, and more.
ImViewGuizmo is a single-header library. Include it like this:
// In exactly one source file:
#define IMVIEWGUIZMO_IMPLEMENTATION
#include "ImViewGuizmo.h"
// In all other files:
#include "ImViewGuizmo.h"- Dear ImGui Optional:
- GLM (OpenGL Mathematics) - used by default for vector and quaternion math, but you can replace it with your own math library if desired.
Here’s a clearer and more structured explanation of how to use your own math library with ImViewGuizmo:
By default, ImViewGuizmo uses GLM for all vector, quaternion, and matrix math. However, GLM is entirely optional. You can substitute your own math library by providing the types and functions ImViewGuizmo expects.
You need types for:
| Concept | Default Type | Your Replacement Example |
|---|---|---|
| 3D vector | glm::vec3 |
MyVec3 |
| 4D vector | glm::vec4 |
MyVec4 |
| Quaternion | glm::quat |
MyQuat |
| 4×4 matrix | glm::mat4 |
MyMat4 |
ImViewGuizmo internally uses a set of basic math functions for vectors, quaternions, and matrices. You must implement equivalents for your types:
Vector Operations
length(v)— magnitude of a vectorlength2(v)— squared magnitudenormalize(v)— unit vectordot(a, b)— dot productcross(a, b)— cross product (for vec3)mix(a, b, t)— linear interpolation- Arithmetic operators:
+,-,*(scalar multiplication)
Quaternion Operations
angleAxis(angle, axis)— create a quaternion from axis/anglequatLookAt(direction, up)— create a rotation quaternion to look in a directiondot(q1, q2)— quaternion dot product*operator for quaternion × quaternion*operator for quaternion × vector
Matrix Operations
mat4_identity()— identity matrixmat4_cast(quat)— convert quaternion to rotation matrixmultiply_mm(a, b)— matrix × matrixmultiply_mv4(matrix, vec4)— matrix × vector4transpose(matrix)— transpose a matrixget_matrix_col(matrix, index)— get a column of a matrixset_matrix_col(matrix, index, vec4)— set a column of a matrix
These functions are grouped in the GizmoMath namespace internally.
Before including ImViewGuizmo.h, define macros to replace the default GLM types:
#define IMVIEWGUIZMO_VEC3 MyVec3
#define IMVIEWGUIZMO_VEC4 MyVec4
#define IMVIEWGUIZMO_QUAT MyQuat
#define IMVIEWGUIZMO_MAT4 MyMat4
#define IMVIEWGUIZMO_LENGTH(v) MyLength(v)
#define IMVIEWGUIZMO_NORMALIZE(v) MyNormalize(v)
#define IMVIEWGUIZMO_DOT(a,b) MyDot(a,b)
#define IMVIEWGUIZMO_CROSS(a,b) MyCross(a,b)
#define IMVIEWGUIZMO_MIX(a,b,t) MyMix(a,b,t)
#define IMVIEWGUIZMO_ANGLEAXIS(angle,axis) MyAngleAxis(angle,axis)
#define IMVIEWGUIZMO_QUATLOOKAT(dir,up) MyQuatLookAt(dir,up)
#include "ImViewGuizmo.h"ImViewGuizmo is licensed under the MIT License. See LICENSE for details.