From 12bab816447ec0838fe8d79e69aefb665763dd79 Mon Sep 17 00:00:00 2001 From: MegaMech <7255464+MegaMech@users.noreply.github.com> Date: Mon, 31 Mar 2025 18:28:43 -0600 Subject: [PATCH] Add rotation model to gizmo --- src/engine/editor/Gizmo.cpp | 49 ++++++++++++++++++++++++++----------- src/engine/editor/Gizmo.h | 7 ++---- src/engine/editor/Light.cpp | 8 +++--- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/engine/editor/Gizmo.cpp b/src/engine/editor/Gizmo.cpp index c13e07f34..2ef080a57 100644 --- a/src/engine/editor/Gizmo.cpp +++ b/src/engine/editor/Gizmo.cpp @@ -233,18 +233,41 @@ void Gizmo::Draw() { void Gizmo::DrawHandles() { Mat4 mainMtx; - Gfx* handle = handle_Cylinder_mesh; - Gfx* center = (Gfx*)"__OTR__gizmo/gizmo_center_button"; + Gfx* blueHandle = handle_Cylinder_mesh; + Gfx* greenHandle = handle_Cylinder_mesh; + Gfx* redHandle = handle_Cylinder_mesh; + Gfx* center = nullptr; (Gfx*)"__OTR__gizmo/gizmo_center_button"; + IRotator blueRot; + IRotator greenRot; + IRotator redRot; + FVector scale = {0.05f, 0.05f, 0.05f}; + switch(static_cast(CVarGetInteger("eGizmoMode", 0))) { case TranslationMode::Move: - handle = handle_Cylinder_mesh; + blueHandle = handle_Cylinder_mesh; + greenHandle = handle_Cylinder_mesh; + redHandle = handle_Cylinder_mesh; + _gizmoOffset = 8.0f; + greenRot = {0, 90, 0}; + blueRot = {90, 0, 0}; + scale = {0.05f, 0.05f, 0.05f}; break; case TranslationMode::Rotate: - handle = handle_Cylinder_mesh; - center = NULL; + center = nullptr; // No All_Axis drag button for Rotation + blueHandle = (Gfx*)"__OTR__editor/gizmo/rot_handle_blue"; + greenHandle = (Gfx*)"__OTR__editor/gizmo/rot_handle_green"; + redHandle = (Gfx*)"__OTR__editor/gizmo/rot_handle_red"; + _gizmoOffset = 0.0f; + scale = {0.2f, 0.2f, 0.2f}; break; case TranslationMode::Scale: - handle = (Gfx*)"__OTR__gizmo/scale_handle"; + blueHandle = (Gfx*)"__OTR__editor/gizmo/scale_handle_blue"; + greenHandle = (Gfx*)"__OTR__editor/gizmo/scale_handle_green"; + redHandle = (Gfx*)"__OTR__editor/gizmo/scale_handle_red"; + _gizmoOffset = 8.0f; + greenRot = {0, 90, 0}; + blueRot = {90, 0, 0}; + scale = {0.05f, 0.05f, 0.05f}; break; } @@ -274,27 +297,25 @@ void Gizmo::DrawHandles() { 0xFF, 0, 0, 0x49, 0x49, 0x49); Mat4 RedXMtx; - ApplyMatrixTransformations(RedXMtx, FVector(Pos.x, Pos.y, Pos.z - _gizmoOffset), Rot, {0.05f, 0.05f, 0.05f}); + ApplyMatrixTransformations(RedXMtx, FVector(Pos.x, Pos.y, Pos.z - _gizmoOffset), Rot, scale); Editor_AddMatrix(RedXMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gDisplayListHead++, handle); + gSPDisplayList(gDisplayListHead++, redHandle); handle_f3dlite_material_lights = gdSPDefLights1( 0x7F, 0x7F, 0x7F, 0, 0xFF, 0, 0x49, 0x49, 0x49); Mat4 GreenYMtx; - ApplyMatrixTransformations(GreenYMtx, FVector(Pos.x - _gizmoOffset, Pos.y, Pos.z), IRotator(0, 90, 0), {0.05f, 0.05f, 0.05f}); - + ApplyMatrixTransformations(GreenYMtx, FVector(Pos.x - _gizmoOffset, Pos.y, Pos.z), greenRot, scale); Editor_AddMatrix(GreenYMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gDisplayListHead++, handle); + gSPDisplayList(gDisplayListHead++, greenHandle); handle_f3dlite_material_lights = gdSPDefLights1( 0x7F, 0x7F, 0x7F, 0, 0, 0xFF, 0x49, 0x49, 0x49); Mat4 BlueZMtx; - ApplyMatrixTransformations(BlueZMtx, FVector(Pos.x, Pos.y + _gizmoOffset, Pos.z), IRotator(90, 0, 0), {0.05f, 0.05f, 0.05f}); - + ApplyMatrixTransformations(BlueZMtx, FVector(Pos.x, Pos.y + _gizmoOffset, Pos.z), blueRot, scale); Editor_AddMatrix(BlueZMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gDisplayListHead++, handle); + gSPDisplayList(gDisplayListHead++, blueHandle); } } diff --git a/src/engine/editor/Gizmo.h b/src/engine/editor/Gizmo.h index e387ccc9d..a56c0c7fe 100644 --- a/src/engine/editor/Gizmo.h +++ b/src/engine/editor/Gizmo.h @@ -58,14 +58,11 @@ public: FVector Pos; // Global scene view IRotator Rot = {0, 0, 0}; - float _gizmoOffset = 8.0f; float AllAxisRadius = 4.0f; // Free move selection radius float PickDistance; FVector _cursorOffset; - FVector RedPos = {0, 0, -_gizmoOffset}; // Local model view - FVector GreenPos = {-_gizmoOffset, 0, 0}; // Local model view - FVector BluePos = {0, _gizmoOffset, 0}; // Local model view - + float _gizmoOffset = 8.0f; + float HandleSize = 2.0f; FVector _ray; diff --git a/src/engine/editor/Light.cpp b/src/engine/editor/Light.cpp index 8ca54ed9c..fefc0b1be 100644 --- a/src/engine/editor/Light.cpp +++ b/src/engine/editor/Light.cpp @@ -57,6 +57,9 @@ size_t LightObject::NumLights = 0; void LightObject::Draw() { Mat4 mtx_sun; Editor_MatrixIdentity(mtx_sun); + gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); + gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); + // Calculate camera-to-object distance FVector cameraDir = FVector(LightPos.x - cameras[0].pos[0], LightPos.y - cameras[0].pos[1], LightPos.z - cameras[0].pos[2]); @@ -75,9 +78,8 @@ size_t LightObject::NumLights = 0; Mat4 mtx_arrow; IRotator rot = LightRot; rot.yaw += 0x4000; - FVector scale = LightScale; - ApplyMatrixTransformations(mtx_arrow, LightPos, rot, scale); + ApplyMatrixTransformations(mtx_arrow, LightPos, rot, LightScale); Editor_AddMatrix(mtx_arrow, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gDisplayListHead++, handle_Cylinder_mesh); + gSPDisplayList(gDisplayListHead++, (Gfx*)"__OTR__editor/light/sun_arrow"); } }