Editor sun face the camera

This commit is contained in:
MegaMech
2025-03-30 16:14:16 -06:00
parent 95706a1171
commit 31a38ebb62
4 changed files with 22 additions and 7 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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]);
+1 -1
View File
@@ -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]);
+19 -4
View File
@@ -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, &centerRot);
// 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);
}
}