From cd58456c03e1a214389d9873cc169b2fc25ee708 Mon Sep 17 00:00:00 2001 From: pohky Date: Fri, 25 Nov 2022 14:19:02 +0100 Subject: [PATCH] Update WorldToScreen - switch from SharpDX to .NET provided Matrix4x4 and Vector3.Transform - add fix for positions behind the camera --- Dalamud/Game/Gui/GameGui.cs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index ad1a72f32..6b9be88b4 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -191,25 +191,14 @@ public sealed unsafe class GameGui : IDisposable, IServiceType var matrixSingleton = this.getMatrixSingleton(); // Read current ViewProjectionMatrix plus game window size - var viewProjectionMatrix = default(SharpDX.Matrix); - float width, height; var windowPos = ImGuiHelpers.MainViewport.Pos; + var viewProjectionMatrix = *(Matrix4x4*)(matrixSingleton + 0x1b4); + var device = Device.Instance(); + float width = device->Width; + float height = device->Height; - unsafe - { - var rawMatrix = (float*)(matrixSingleton + 0x1b4).ToPointer(); - - for (var i = 0; i < 16; i++, rawMatrix++) - viewProjectionMatrix[i] = *rawMatrix; - var device = Device.Instance(); - width = device->Width; - height = device->Height; - } - - var worldPosDx = worldPos.ToSharpDX(); - SharpDX.Vector3.Transform(ref worldPosDx, ref viewProjectionMatrix, out SharpDX.Vector3 pCoords); - - screenPos = new Vector2(pCoords.X / pCoords.Z, pCoords.Y / pCoords.Z); + var pCoords = Vector3.Transform(worldPos, viewProjectionMatrix); + screenPos = new Vector2(pCoords.X / MathF.Abs(pCoords.Z), pCoords.Y / MathF.Abs(pCoords.Z)); screenPos.X = (0.5f * width * (screenPos.X + 1f)) + windowPos.X; screenPos.Y = (0.5f * height * (1f - screenPos.Y)) + windowPos.Y;