Toast Engine
Loading...
Searching...
No Matches
gizmo_layout.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <cstdint>
14#include <glm/glm.hpp>
15#include <utility>
16
17namespace toast {
18
21enum class GizmoTool : uint8_t {
22 select,
23 translate,
24 rotate,
25 scale,
26 ruler,
27 volume_faces,
28};
29
32enum class GizmoHandle : int8_t {
33 none = -1,
34 axis_x = 0,
35 axis_y = 1,
36 axis_z = 2,
37 plane_xy = 3,
38 plane_yz = 4,
39 plane_xz = 5,
40 center = 6,
41
42 size_neg_x = 7,
43 size_pos_x = 8,
44 size_neg_y = 9,
45 size_pos_y = 10,
46 size_neg_z = 11,
47 size_pos_z = 12,
48};
49
50namespace gizmo_layout {
51
52[[nodiscard]]
53constexpr auto isSizeHandle(GizmoHandle handle) noexcept -> bool {
54 return handle >= GizmoHandle::size_neg_x && handle <= GizmoHandle::size_pos_z;
55}
56
57[[nodiscard]]
58constexpr auto sizeHandleAxis(GizmoHandle handle) noexcept -> int {
59 return (static_cast<int>(handle) - static_cast<int>(GizmoHandle::size_neg_x)) / 2;
60}
61
62[[nodiscard]]
63constexpr auto sizeHandleSign(GizmoHandle handle) noexcept -> float {
64 return (static_cast<int>(handle) - static_cast<int>(GizmoHandle::size_neg_x)) % 2 == 0 ? -1.0f : 1.0f;
65}
66
67constexpr float k_screen_size = 0.15f;
68
69// Translate: arrow shaft + pyramid head per axis, small plane quads, center free-move handle
70constexpr float k_shaft_length = 0.8f;
71constexpr float k_shaft_half_size = 0.02f;
72constexpr float k_head_length = 0.25f;
73constexpr float k_head_half_size = 0.06f;
74
76constexpr float k_plane_offset = 0.25f;
77constexpr float k_plane_size = 0.2f;
78constexpr float k_center_half_size = 0.06f;
79
81constexpr float k_axis_hit_radius = 0.05f;
82constexpr float k_center_hit_radius = 0.12f;
83
84// Rotate: one flat ring per axis, lying in the plane perpendicular to that axis
85constexpr float k_ring_radius = 0.9f;
86constexpr float k_ring_thickness = 0.05f;
87constexpr int k_ring_segments = 48;
88
89// Scale: same shaft as translate, but a cube head instead of a pyramid, plus a center cube for uniform scale
90constexpr float k_scale_head_half_size = 0.07f;
91
92constexpr float k_size_dot_half_size = 0.05f;
93constexpr float k_size_dot_hit_radius = 0.09f;
94constexpr float k_min_collider_extent = 0.01f;
95
97inline auto ringBasis(const glm::vec3& axis) -> std::pair<glm::vec3, glm::vec3> {
98 const glm::vec3 reference = std::abs(glm::dot(axis, glm::vec3(0, 0, 1))) > 0.99f ? glm::vec3(1, 0, 0) : glm::vec3(0, 0, 1);
99 const glm::vec3 u = glm::normalize(glm::cross(axis, reference));
100 const glm::vec3 v = glm::cross(axis, u);
101 return {u, v};
102}
103
104}
105}
auto ringBasis(const glm::vec3 &axis) -> std::pair< glm::vec3, glm::vec3 >
Deterministic in-plane basis (u,v) perpendicular to axis.
Definition gizmo_layout.hpp:97
constexpr float k_axis_hit_radius
Hit tolerances, in the same gizmo-local unit space as the geometry above.
Definition gizmo_layout.hpp:81
GizmoTool
Mirrors editor.WorkspaceViewModel.GizmoTool / proto SetGizmoTool - 0 Select, 1 Translate,...
Definition gizmo_layout.hpp:21
GizmoHandle
Which part of the active gizmo a ray/click is interacting with, axis_x/y/z and center are reused acro...
Definition gizmo_layout.hpp:32
constexpr float k_plane_offset
Plane-handle quads sit near the origin, offset along each of the plane two axes.
Definition gizmo_layout.hpp:76
constexpr float k_screen_size
world-units of gizmo size per world-unit of camera distance
Definition gizmo_layout.hpp:67
constexpr float k_ring_thickness
band width, used for both rendering and hit-testing
Definition gizmo_layout.hpp:86