Skip to content

Commit

Permalink
[editor] the transform gizmo now has a snap value of 0.1, this allows…
Browse files Browse the repository at this point in the history
… for more deterministic manipulation
  • Loading branch information
PanosK92 committed Jan 8, 2025
1 parent 4c29da1 commit 3a4a0af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
31 changes: 18 additions & 13 deletions editor/ImGui/ImGui_TransformGizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace ImGui::TransformGizmo
{
const Spartan::Math::Vector3 snap = Spartan::Math::Vector3(0.1f, 0.1f, 0.1f);

bool first_use = true;
Spartan::Math::Vector3 position_previous;
Spartan::Math::Quaternion rotation_previous;
Expand Down Expand Up @@ -79,9 +81,7 @@ namespace ImGui::TransformGizmo
// enable/disable gizmo
ImGuizmo::Enable(entity != nullptr);
if (!entity)
{
return;
}

// switch between position, rotation and scale operations, with W, E and R respectively
static ImGuizmo::OPERATION transform_operation = ImGuizmo::TRANSLATE;
Expand All @@ -101,29 +101,34 @@ namespace ImGui::TransformGizmo
}
}

ImGuizmo::MODE transform_space = ImGuizmo::WORLD;

// Get some data
const Spartan::Math::Matrix& matrix_projection = camera->GetProjectionMatrix().Transposed();
// get matrices
const Spartan::Math::Matrix& matrix_view = camera->GetViewMatrix().Transposed();

const Spartan::Math::Matrix& matrix_projection = camera->GetProjectionMatrix().Transposed();

// begin
const bool is_orthographic = false;
ImGuizmo::SetOrthographic(is_orthographic);
ImGuizmo::BeginFrame();

// map transform to ImGuizmo
Spartan::Math::Vector3 position = entity->GetPosition();
Spartan::Math::Vector3 scale = entity->GetScale();
Spartan::Math::Quaternion rotation = entity->GetRotation();

Spartan::Math::Vector3 position = entity->GetPosition();
Spartan::Math::Vector3 scale = entity->GetScale();
Spartan::Math::Quaternion rotation = entity->GetRotation();
Spartan::Math::Matrix transform_matrix = Spartan::Math::Matrix::GenerateRowFirst(position, rotation, scale);

// set viewport rectangle
ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());

ImGuizmo::Manipulate(&matrix_view.m00, &matrix_projection.m00, transform_operation, transform_space, &transform_matrix.m00, nullptr, nullptr);
ImGuizmo::Manipulate(
&matrix_view.m00,
&matrix_projection.m00,
transform_operation,
ImGuizmo::WORLD,
&transform_matrix.m00,
nullptr,
&snap.x
);

// map imguizmo to transform
if (ImGuizmo::IsUsing())
Expand Down Expand Up @@ -154,6 +159,6 @@ namespace ImGui::TransformGizmo

static bool allow_picking()
{
return !ImGuizmo::IsOver() && !ImGuizmo::IsUsing();
return !ImGuizmo::IsOver() && !ImGuizmo::IsUsing();
}
}
3 changes: 1 addition & 2 deletions runtime/World/Components/PhysicsBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,7 @@ namespace Spartan

// determine how much detail is needed for this shape
const bool is_enterable = can_player_fit(GetEntity(), vertices, size);
const bool is_low_poly = vertices.size() < 1000;
const bool convex_hull = !is_enterable && !is_low_poly;
const bool convex_hull = !is_enterable;

if (convex_hull)
{
Expand Down

0 comments on commit 3a4a0af

Please sign in to comment.