Merge pull request #102 from pmgr/master

This commit is contained in:
goaaats 2020-04-29 16:51:59 +02:00 committed by GitHub
commit a58de19abc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View file

@ -141,6 +141,11 @@ namespace Dalamud.Game.Internal.Gui {
return retVal; 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) public bool OpenMapWithMapLink(MapLinkPayload mapLink)
{ {
var uiObjectPtr = getUIObject(); var uiObjectPtr = getUIObject();
@ -174,7 +179,13 @@ namespace Dalamud.Game.Internal.Gui {
return this.openMapWithFlag(uiMapObjectPtr, mapLinkString); 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 // Get base object with matrices
var matrixSingleton = this.getMatrixSingleton(); var matrixSingleton = this.getMatrixSingleton();
@ -193,14 +204,14 @@ namespace Dalamud.Game.Internal.Gui {
height = *(rawMatrix + 1); 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); screenPos.X = 0.5f * width * (screenPos.X + 1f);
normalProjCoords.Y = 0.5f * height * (1f - normalProjCoords.Y); screenPos.Y = 0.5f * height * (1f - screenPos.Y);
return normalProjCoords; return pCoords.Z > 0;
} }
public Vector3 ScreenToWorld(Vector2 screenCoords) { public Vector3 ScreenToWorld(Vector2 screenCoords) {

View file

@ -108,9 +108,7 @@ namespace Dalamud.Interface
stateString += stateString +=
$" HomeWorld: {pc.HomeWorld.GameData.Name} CurrentWorld: {pc.CurrentWorld.GameData.Name} FC: {pc.CompanyTag}\n"; $" HomeWorld: {pc.HomeWorld.GameData.Name} CurrentWorld: {pc.CurrentWorld.GameData.Name} FC: {pc.CompanyTag}\n";
if (this.drawActors) { if (this.drawActors && this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords)) {
var screenCoords = this.dalamud.Framework.Gui.WorldToScreen(actor.Position);
ImGui.PushID("ActorWindow" + i); ImGui.PushID("ActorWindow" + i);
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y)); ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
ImGui.SetNextWindowBgAlpha(0.35f); ImGui.SetNextWindowBgAlpha(0.35f);