From 683a322dad5e63594e70857b35fb790c1cf3f4b4 Mon Sep 17 00:00:00 2001 From: Jade Macho Date: Tue, 10 Jan 2023 19:05:52 +0100 Subject: [PATCH] Improve WorldToScreen-ing points in front but off to the side --- Dalamud/Game/Gui/GameGui.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index 301f7a634..d3b479642 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -184,8 +184,18 @@ public sealed unsafe class GameGui : IDisposable, IServiceType /// /// Coordinates in the world. /// Converted coordinates. - /// True if worldPos corresponds to a position in front of the camera. + /// True if worldPos corresponds to a position in front of the camera and screenPos is in the viewport. public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos) + => this.WorldToScreen(worldPos, out screenPos, out var inView) && inView; + + /// + /// Converts in-world coordinates to screen coordinates (upper left corner origin). + /// + /// Coordinates in the world. + /// Converted coordinates. + /// True if screenPos corresponds to a position inside the camera viewport. + /// True if worldPos corresponds to a position in front of the camera. + public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos, out bool inView) { // Get base object with matrices var matrixSingleton = this.getMatrixSingleton(); @@ -203,9 +213,12 @@ public sealed unsafe class GameGui : IDisposable, IServiceType screenPos.X = (0.5f * width * (screenPos.X + 1f)) + windowPos.X; screenPos.Y = (0.5f * height * (1f - screenPos.Y)) + windowPos.Y; - return pCoords.Z > 0 && - screenPos.X > windowPos.X && screenPos.X < windowPos.X + width && - screenPos.Y > windowPos.Y && screenPos.Y < windowPos.Y + height; + var inFront = pCoords.Z > 0; + inView = inFront && + screenPos.X > windowPos.X && screenPos.X < windowPos.X + width && + screenPos.Y > windowPos.Y && screenPos.Y < windowPos.Y + height; + + return inFront; } ///