From 87bf4980979cc6bd1376415d999e9201840c5744 Mon Sep 17 00:00:00 2001
From: pmgr <26606291+pmgr@users.noreply.github.com>
Date: Wed, 29 Apr 2020 15:39:26 +0100
Subject: [PATCH] Adding check to WorldToScreen for coordinates being in front,
plus documentation
---
Dalamud/Game/Internal/Gui/GameGui.cs | 23 +++++++++++++++++------
Dalamud/Interface/DalamudDataWindow.cs | 4 +---
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/Dalamud/Game/Internal/Gui/GameGui.cs b/Dalamud/Game/Internal/Gui/GameGui.cs
index 764b49d39..aaa800460 100644
--- a/Dalamud/Game/Internal/Gui/GameGui.cs
+++ b/Dalamud/Game/Internal/Gui/GameGui.cs
@@ -141,6 +141,11 @@ namespace Dalamud.Game.Internal.Gui {
return retVal;
}
+ ///
+ /// Opens the in-game map with a flag on the location of the parameter
+ ///
+ /// Link to the map to be opened
+ /// True if there were no errors and it could open the map
public bool OpenMapWithMapLink(MapLinkPayload mapLink)
{
var uiObjectPtr = getUIObject();
@@ -174,7 +179,13 @@ namespace Dalamud.Game.Internal.Gui {
return this.openMapWithFlag(uiMapObjectPtr, mapLinkString);
}
- public Vector2 WorldToScreen(Vector3 worldCoords)
+ ///
+ /// Converts in-world coordinates to screen coordinates (upper left corner origin).
+ ///
+ /// Coordinates in the world
+ /// Converted coordinates
+ /// True if worldPos corresponds to a position in front of the camera
+ public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos)
{
// Get base object with matrices
var matrixSingleton = this.getMatrixSingleton();
@@ -193,14 +204,14 @@ namespace Dalamud.Game.Internal.Gui {
height = *(rawMatrix + 1);
}
- Vector3.Transform(ref worldCoords, ref viewProjectionMatrix, out Vector3 pCoords);
+ Vector3.Transform( ref worldPos, ref viewProjectionMatrix, out Vector3 pCoords);
- var normalProjCoords = new Vector2(pCoords.X / pCoords.Z, pCoords.Y / pCoords.Z);
+ screenPos = new Vector2(pCoords.X / pCoords.Z, pCoords.Y / pCoords.Z);
- normalProjCoords.X = 0.5f * width * (normalProjCoords.X + 1f);
- normalProjCoords.Y = 0.5f * height * (1f - normalProjCoords.Y);
+ screenPos.X = 0.5f * width * (screenPos.X + 1f);
+ screenPos.Y = 0.5f * height * (1f - screenPos.Y);
- return normalProjCoords;
+ return pCoords.Z > 0;
}
public Vector3 ScreenToWorld(Vector2 screenCoords) {
diff --git a/Dalamud/Interface/DalamudDataWindow.cs b/Dalamud/Interface/DalamudDataWindow.cs
index 1fac5f67e..d55476f2b 100644
--- a/Dalamud/Interface/DalamudDataWindow.cs
+++ b/Dalamud/Interface/DalamudDataWindow.cs
@@ -108,9 +108,7 @@ namespace Dalamud.Interface
stateString +=
$" HomeWorld: {pc.HomeWorld.GameData.Name} CurrentWorld: {pc.CurrentWorld.GameData.Name} FC: {pc.CompanyTag}\n";
- if (this.drawActors) {
- var screenCoords = this.dalamud.Framework.Gui.WorldToScreen(actor.Position);
-
+ if (this.drawActors && this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords)) {
ImGui.PushID("ActorWindow" + i);
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
ImGui.SetNextWindowBgAlpha(0.35f);