From 31a38ebb62cb76224dcb68eca055a9d6b4187233 Mon Sep 17 00:00:00 2001 From: MegaMech <7255464+MegaMech@users.noreply.github.com> Date: Sun, 30 Mar 2025 16:14:16 -0600 Subject: [PATCH] Editor sun face the camera --- src/engine/editor/EditorMath.cpp | 2 +- src/engine/editor/EditorMath.h | 2 +- src/engine/editor/Gizmo.cpp | 2 +- src/engine/editor/Light.cpp | 23 +++++++++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/engine/editor/EditorMath.cpp b/src/engine/editor/EditorMath.cpp index 260ceb5b1..fe365ef10 100644 --- a/src/engine/editor/EditorMath.cpp +++ b/src/engine/editor/EditorMath.cpp @@ -306,7 +306,7 @@ bool IntersectRaySphere(const Ray& ray, const FVector& sphereCenter, float radiu // } // Transform a matrix to a matrix identity -void Editor_Matrixidentity(Mat4 mtx) { +void Editor_MatrixIdentity(Mat4 mtx) { register s32 i; register s32 k; diff --git a/src/engine/editor/EditorMath.h b/src/engine/editor/EditorMath.h index c28ccea48..9e5b87c6a 100644 --- a/src/engine/editor/EditorMath.h +++ b/src/engine/editor/EditorMath.h @@ -42,7 +42,7 @@ void Clear(MtxF* mf); bool IntersectRayTriangle(const Ray& ray, const Triangle& tri, const FVector& objectPos, float& t); bool IntersectRaySphere(const Ray& ray, const FVector& sphereCenter, float radius, float& t); -void Editor_Matrixidentity(Mat4 mtx); +void Editor_MatrixIdentity(Mat4 mtx); void Editor_AddMatrix(Mat4 mtx, int32_t flags); float CalculateAngle(const FVector& start, const FVector& end); void SetDirectionFromRotator(IRotator rot, s8 direction[3]); diff --git a/src/engine/editor/Gizmo.cpp b/src/engine/editor/Gizmo.cpp index b7bad7279..c13e07f34 100644 --- a/src/engine/editor/Gizmo.cpp +++ b/src/engine/editor/Gizmo.cpp @@ -253,7 +253,7 @@ void Gizmo::DrawHandles() { if (center) { Mat4 CenterMtx; - Editor_Matrixidentity(CenterMtx); + Editor_MatrixIdentity(CenterMtx); // Calculate camera-to-object distance FVector cameraDir = FVector(Pos.x - cameras[0].pos[0], Pos.y - cameras[0].pos[1], Pos.z - cameras[0].pos[2]); diff --git a/src/engine/editor/Light.cpp b/src/engine/editor/Light.cpp index 047575348..8ca54ed9c 100644 --- a/src/engine/editor/Light.cpp +++ b/src/engine/editor/Light.cpp @@ -55,14 +55,29 @@ size_t LightObject::NumLights = 0; SetDirectionFromRotator(*Rot, Direction); } void LightObject::Draw() { - Mat4 mtx; + Mat4 mtx_sun; + Editor_MatrixIdentity(mtx_sun); + + // 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]); + cameraDir = cameraDir.Normalize(); + + IRotator centerRot; + SetRotatorFromDirection(cameraDir, ¢erRot); // Account for object not facing the correct direction when exported + centerRot.yaw += 0x4000; + ApplyMatrixTransformations(mtx_sun, LightPos, centerRot, LightScale); + Editor_AddMatrix(mtx_sun, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gDisplayListHead++, sun_LightModel_mesh); + + // Draw Arrow + Mat4 mtx_arrow; IRotator rot = LightRot; rot.yaw += 0x4000; - ApplyMatrixTransformations(mtx, LightPos, rot, LightScale); - Editor_AddMatrix(mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gDisplayListHead++, sun_LightModel_mesh); + FVector scale = LightScale; + ApplyMatrixTransformations(mtx_arrow, LightPos, rot, scale); + Editor_AddMatrix(mtx_arrow, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gDisplayListHead++, handle_Cylinder_mesh); } }