Things mode gizmos
This commit is contained in:
parent
2f155d3fe9
commit
f9e4187a10
2 changed files with 126 additions and 13676 deletions
13724
Data/sandbox-log.txt
13724
Data/sandbox-log.txt
File diff suppressed because it is too large
Load diff
|
@ -956,11 +956,55 @@ void Editor::UpdateModeThings()
|
|||
|
||||
void Editor::RenderModeThings()
|
||||
{
|
||||
// Le wireframe
|
||||
for (kp3d::Thing& thing: sandbox->map.things)
|
||||
thing.RenderBox(
|
||||
&thing == m_selected_thing ? kp3d::Vec3{0.33f, 0.33f, 1.0f} :
|
||||
(&thing == m_hovered_thing ? kp3d::Vec3{1.0f, 1.0f, 1.0f} : kp3d::Vec3{0.5f, 0.5f, 0.5f})
|
||||
);
|
||||
|
||||
// Le gizmo
|
||||
if (!m_selected_thing)
|
||||
return;
|
||||
ImGuizmo::Enable(true);
|
||||
ImGuizmo::SetRect(0, 0, sandbox->GetWidth(), sandbox->GetHeight());
|
||||
ImGuizmo::SetDrawlist(ImGui::GetBackgroundDrawList());
|
||||
enum { M, V, P };
|
||||
float tmp[16];
|
||||
m_selected_thing->transform.rotation = {
|
||||
kp3d::ToDegrees(m_selected_thing->transform.rotation.x),
|
||||
kp3d::ToDegrees(m_selected_thing->transform.rotation.y),
|
||||
kp3d::ToDegrees(m_selected_thing->transform.rotation.z)
|
||||
};
|
||||
ImGuizmo::RecomposeMatrixFromComponents(&m_selected_thing->transform.translation.x, &m_selected_thing->transform.rotation.x, &m_selected_thing->transform.scale.x, tmp);
|
||||
kp3d::Mat4 cam_translation_matrix, cam_rotation_matrix;
|
||||
cam_translation_matrix.InitTranslation(-sandbox->camera.position);
|
||||
cam_rotation_matrix.InitRotation(sandbox->camera.forward, sandbox->camera.up, sandbox->camera.right);
|
||||
kp3d::Mat4 cam_matrix = cam_rotation_matrix * cam_translation_matrix;
|
||||
bool v = ImGuizmo::Manipulate(
|
||||
cam_matrix.mat.data(),
|
||||
sandbox->projection.mat.data(),
|
||||
static_cast<ImGuizmo::OPERATION>(ImGuizmo::UNIVERSAL),
|
||||
ImGuizmo::LOCAL,
|
||||
tmp,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
editing_gizmo = ImGuizmo::IsOver();
|
||||
// if (v)
|
||||
{
|
||||
float translation[3], rotation[3], scale[3];
|
||||
ImGuizmo::DecomposeMatrixToComponents(tmp, translation, rotation, scale);
|
||||
m_selected_thing->transform.translation = {translation[0], translation[1], translation[2]};
|
||||
m_selected_thing->transform.rotation = {
|
||||
kp3d::ToRadians(rotation[0]),
|
||||
kp3d::ToRadians(rotation[1]),
|
||||
kp3d::ToRadians(rotation[2])
|
||||
};
|
||||
m_selected_thing->transform.scale = {scale[0], scale[1], scale[2]};
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::RenderUI()
|
||||
|
@ -1022,11 +1066,41 @@ void Editor::RenderUI()
|
|||
{
|
||||
if (ImGui::Begin("Selection Info", &show_selection_info))
|
||||
{
|
||||
if (m_mode != MODE_NORMAL)
|
||||
if (m_mode == MODE_BUILD)
|
||||
{
|
||||
ImGui::Text("No selection");
|
||||
}
|
||||
else
|
||||
else if (m_mode == MODE_THINGS)
|
||||
{
|
||||
if (m_selected_thing)
|
||||
{
|
||||
ImGui::SeparatorText("Transform");
|
||||
if (ImGui::CollapsingHeader("Edit Transformation..."))
|
||||
{
|
||||
ImGui::Text("Translation:");
|
||||
ImGui::InputFloat("X##thingt", &m_selected_thing->transform.translation.x);
|
||||
ImGui::InputFloat("Y##thingt", &m_selected_thing->transform.translation.y);
|
||||
ImGui::InputFloat("Z##thingt", &m_selected_thing->transform.translation.z);
|
||||
ImGui::Text("Rotation:");
|
||||
ImGui::InputFloat("X##thingr", &m_selected_thing->transform.rotation.x);
|
||||
ImGui::InputFloat("Y##thingr", &m_selected_thing->transform.rotation.y);
|
||||
ImGui::InputFloat("Z##thingr", &m_selected_thing->transform.rotation.z);
|
||||
ImGui::Text("Scale:");
|
||||
ImGui::InputFloat("X##things", &m_selected_thing->transform.scale.x);
|
||||
ImGui::InputFloat("Y##things", &m_selected_thing->transform.scale.y);
|
||||
ImGui::InputFloat("Z##things", &m_selected_thing->transform.scale.z);
|
||||
}
|
||||
ImGui::SeparatorText("Properties");
|
||||
ImGui::CheckboxFlags("Visible", (unsigned int*)(&m_selected_thing->flags), kp3d::Thing::FLAG_VISIBLE);
|
||||
ImGui::CheckboxFlags("Grounded", (unsigned int*)(&m_selected_thing->flags), kp3d::Thing::FLAG_GROUNDED);
|
||||
ImGui::CheckboxFlags("Collisions", (unsigned int*)(&m_selected_thing->flags), kp3d::Thing::FLAG_COLLISIONS);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Text("No selection");
|
||||
}
|
||||
}
|
||||
else if (m_mode == MODE_NORMAL)
|
||||
{
|
||||
if (!kp3d::editor_hovered_batch.empty())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue