SpiecsEngine
 
Loading...
Searching...
No Matches

◆ OnRender()

void Spices::ImguiGizmos::OnRender ( )
overridevirtual

This interface is called On SlateRenderer Render.

Set Gizmo Projection type.

Use Window Draw List.

Locating Gizmo.

Instnce empty camera.

Fill in camera.

Iter by view.

Draw Editor ViewManipulate.

Todo
fix uncorrect manipulate.

Set New Camera transform.

Draw Editor Gizmo.

Get Selected Entity.

Get Transform Component.

Get Entity Model Matrix.

Snapping.

Gozmo Manipulater.

Add to Entity Transform.

Split Channels from Matrix.

Set Gizmo Projection type.

Use Window Draw List.

Locating Gizmo.

Instnce empty camera.

Fill in camera.

Iter by view.

Draw Editor ViewManipulate.

Todo
fix uncorrect manipulate.

Set New Camera transform.

Draw Editor Gizmo.

Get Selected Entity.

Get Transform Component.

Get Entity Model Matrix.

Snapping.

Gozmo Manipulater.

Add to Entity Transform.

Split Channels from Matrix.

Implements Spices::ImguiSlate.

Definition at line 21 of file ImguiGizmos.cpp.

22 {
24
25 {
26 SPICES_PROFILE_ZONEN("Set ImGuizmo Draw Info");
27
31 ImGuizmo::SetOrthographic(false);
32
36 ImGuizmo::SetDrawlist();
37
41 ImGuizmo::SetRect(
46 );
47 }
48
52 Entity CameraEntity;
53 glm::mat4 viewMat = glm::mat4(1.0f);
54 glm::mat4 projectionMat = glm::mat4(1.0f);
55
59 {
60 SPICES_PROFILE_ZONEN("Get Camera Matrix");
61
65 m_FrameInfo.m_World->ViewComponent<CameraComponent>([&](auto e, auto& tComp){
66
67 auto& transComp = m_FrameInfo.m_World->GetComponent<TransformComponent>(e);
68
69 if (tComp.IsActive())
70 {
71 viewMat = glm::inverse(transComp.GetModelMatrix());
72 projectionMat = tComp.GetCamera()->GetPMatrix();
73
74 CameraEntity = Entity(e, m_FrameInfo.m_World.get());
75 return true;
76 }
77
78 return false;
79 });
80 }
81
85 {
86 SPICES_PROFILE_ZONEN("ImGuizmo::ViewManipulate");
87
91 ImGuizmo::ViewManipulate(
92 glm::value_ptr(viewMat),
93 8.0f,
94 ImVec2(m_Owner->GetPanelPos().x, m_Owner->GetPanelPos().y + m_Owner->GetPanelSize().y - 96),
95 ImVec2(96, 96),
96 0x10101010
97 );
98 }
99
103 //{
104 // SPICES_PROFILE_ZONEN("DecomposeTransform");
105
106 // /**
107 // * @brief Split Channels from Matrix.
108 // */
109 // glm::vec3 translation, rotation, scale;
110 // DecomposeTransform(glm::inverse(viewMat), translation, rotation, scale);
111 //}
112
116 {
117 SPICES_PROFILE_ZONEN("Draw Editor Gizmo");
118
120 {
124 Entity entity(
125 static_cast<entt::entity>(*m_FrameInfo.m_PickEntityID.end_k()),
126 m_FrameInfo.m_World.get()
127 );
128
132 auto& tc = entity.GetComponent<TransformComponent>();
133
137 glm::mat4 model = tc.GetModelMatrix();
138
143 float snapValue = 0.5f; // Snap to 0.5m for translation/scale
144 // Snap to 45 degrees for rotation
145 if (m_GizmoType == ImGuizmo::OPERATION::ROTATE)
146 {
147 snapValue = 45.0F;
148 }
149
150 float snapValues[3] = { snapValue, snapValue ,snapValue };
151
155 {
156 SPICES_PROFILE_ZONEN("ImGuizmo::Manipulate");
157
158 ImGuizmo::Manipulate(
159 glm::value_ptr(viewMat),
160 glm::value_ptr(projectionMat),
161 (ImGuizmo::OPERATION)m_GizmoType,
162 ImGuizmo::LOCAL,
163 glm::value_ptr(model),
164 nullptr, snap ? snapValues : nullptr
165 );
166 }
167
171 {
172 SPICES_PROFILE_ZONEN("Add Transform to Manipulatd Entity");
173
174 if (ImGuizmo::IsUsing())
175 {
179 glm::vec3 translation, rotation, scale;
180 DecomposeTransform(model, translation, rotation, scale);
181 rotation = { glm::degrees(rotation.x), glm::degrees(rotation.y), glm::degrees(rotation.z) };
182
183
184 glm::vec3 deltaRotation = rotation - tc.GetRotation();
185 tc.SetPosition(translation);
186 tc.SetRotation(tc.GetRotation() + deltaRotation);
187 tc.SetScale(scale);
188
190 }
191 }
192 }
193 }
194 }
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
static FrameInfo & Get()
Get FrameInfo.
Definition FrameInfo.cpp:14
std::shared_ptr< World > m_World
The shared pointer of specific world.
Definition FrameInfo.h:94
scl::linked_unordered_map< int, std::string > m_PickEntityID
Definition FrameInfo.h:82
int m_GizmoType
Gizmo Type, Transpose, rotate, scale, universal.
Definition ImguiGizmos.h:84
ImguiSlate * m_Owner
The owner, usually is a ImguiViewport class.
Definition ImguiGizmos.h:79
bool bEnableGizmo
Is Enable Gizmo.
Definition ImguiGizmos.h:89
ImVec2 & GetPanelSize()
Get Panel Size.
Definition ImguiUtils.h:114
FrameInfo & m_FrameInfo
The FrameData reference.
Definition ImguiUtils.h:166
ImVec2 & GetPanelPos()
Get Panel Pos.
Definition ImguiUtils.h:120
static bool IsKeyPressed(const int &keycode)
Query If given Key is Pressed.
Definition Input.h:34
@ FrushStableFrame
Definition World.h:48
@ NeedUpdateTLAS
Definition World.h:49
size_t size()
The container's element size.
bool DecomposeTransform(const glm::mat4 &transform, glm::vec3 &outTranslation, glm::vec3 &outRotation, glm::vec3 &outScale)
Decompose matrix to split SRT transform.
Definition Math.cpp:15

References bEnableGizmo, Spices::World::FrushStableFrame, Spices::FrameInfo::Get(), Spices::Input::IsKeyPressed(), Spices::Key::LeftControl, Spices::ImguiSlate::m_FrameInfo, and Spices::World::NeedUpdateTLAS.