-
Notifications
You must be signed in to change notification settings - Fork 64
Writing Custom Gizmos
John Chapman edited this page Mar 23, 2018
·
4 revisions
The following skeleton code shows how gizmo behaviors typically work:
Context& ctx = GetContext();
const AppData& appData = ctx.getAppData();
Ray ray(appData.m_cursorRayOrigin, appData.m_cursorRayDirection);
float intersectionDepth;
bool intersects = // intersect ray with the gizmo primitive and get intersectionDepth
Vec3 intersection = ray.m_origin + ray.m_direction * intersectionDepth; // world space intersection
if (gizmoId == ctx.getActiveId()) { // gizmo is active
if (ctx.isKeyDown(Action_Select)) {
// interaction is ongoing, update outputs, etc.
} else {
// interaction stopped, deactivate the gizmo (return to a hot state)
ctx.setActiveId(Id_Invalid);
}
} else if (gizmoId == ctx.getHotId()) { // gizmo is hot
if (intersects) {
// hot state is valid, can make active
if (ctx.isKeyDown(Action_Select)) {
ctx.setActiveId(gizmoId);
}
} else {
// return to a cold state
ctx.resetId();
}
} else { // gimo is cold
ctx.makeHot(gizmoId, intersectionDepth, intersects);
}