Adding check to WorldToScreen for coordinates being in front, plus documentation

This commit is contained in:
pmgr 2020-04-29 15:39:26 +01:00
parent 143b8a15fc
commit 87bf498097
2 changed files with 18 additions and 9 deletions

View file

@ -141,6 +141,11 @@ namespace Dalamud.Game.Internal.Gui {
return retVal;
}
/// <summary>
/// Opens the in-game map with a flag on the location of the parameter
/// </summary>
/// <param name="mapLink">Link to the map to be opened</param>
/// <returns>True if there were no errors and it could open the map</returns>
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)
/// <summary>
/// Converts in-world coordinates to screen coordinates (upper left corner origin).
/// </summary>
/// <param name="worldPos">Coordinates in the world</param>
/// <param name="screenPos">Converted coordinates</param>
/// <returns>True if worldPos corresponds to a position in front of the camera</returns>
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) {

View file

@ -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);