refactor: remove public SharpDX S2W/W2S APIs

This commit is contained in:
goat 2021-08-22 23:21:43 +02:00
parent 764f9614ab
commit ec06fa5f1e
No known key found for this signature in database
GPG key ID: F18F057873895461

View file

@ -191,7 +191,7 @@ namespace Dalamud.Game.Gui
/// <param name="worldPos">Coordinates in the world.</param> /// <param name="worldPos">Coordinates in the world.</param>
/// <param name="screenPos">Converted coordinates.</param> /// <param name="screenPos">Converted coordinates.</param>
/// <returns>True if worldPos corresponds to a position in front of the camera.</returns> /// <returns>True if worldPos corresponds to a position in front of the camera.</returns>
public bool WorldToScreen(SharpDX.Vector3 worldPos, out SharpDX.Vector2 screenPos) 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();
@ -212,9 +212,10 @@ namespace Dalamud.Game.Gui
height = *(rawMatrix + 1); height = *(rawMatrix + 1);
} }
SharpDX.Vector3.Transform(ref worldPos, ref viewProjectionMatrix, out SharpDX.Vector3 pCoords); var worldPosDx = worldPos.ToSharpDX();
SharpDX.Vector3.Transform(ref worldPosDx, ref viewProjectionMatrix, out SharpDX.Vector3 pCoords);
screenPos = new SharpDX.Vector2(pCoords.X / pCoords.Z, pCoords.Y / pCoords.Z); screenPos = new Vector2(pCoords.X / pCoords.Z, pCoords.Y / pCoords.Z);
screenPos.X = (0.5f * width * (screenPos.X + 1f)) + windowPos.X; screenPos.X = (0.5f * width * (screenPos.X + 1f)) + windowPos.X;
screenPos.Y = (0.5f * height * (1f - screenPos.Y)) + windowPos.Y; screenPos.Y = (0.5f * height * (1f - screenPos.Y)) + windowPos.Y;
@ -224,22 +225,6 @@ namespace Dalamud.Game.Gui
screenPos.Y > windowPos.Y && screenPos.Y < windowPos.Y + height; screenPos.Y > windowPos.Y && screenPos.Y < windowPos.Y + height;
} }
/// <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>
/// <remarks>
/// This overload requires a conversion to SharpDX vectors, however the penalty should be negligible.
/// </remarks>
public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos)
{
var result = this.WorldToScreen(worldPos.ToSharpDX(), out var sharpScreenPos);
screenPos = sharpScreenPos.ToSystem();
return result;
}
/// <summary> /// <summary>
/// Converts screen coordinates to in-world coordinates via raycasting. /// Converts screen coordinates to in-world coordinates via raycasting.
/// </summary> /// </summary>
@ -247,7 +232,7 @@ namespace Dalamud.Game.Gui
/// <param name="worldPos">Converted coordinates.</param> /// <param name="worldPos">Converted coordinates.</param>
/// <param name="rayDistance">How far to search for a collision.</param> /// <param name="rayDistance">How far to search for a collision.</param>
/// <returns>True if successful. On false, worldPos's contents are undefined.</returns> /// <returns>True if successful. On false, worldPos's contents are undefined.</returns>
public bool ScreenToWorld(SharpDX.Vector2 screenPos, out SharpDX.Vector3 worldPos, float rayDistance = 100000.0f) public bool ScreenToWorld(Vector2 screenPos, out Vector3 worldPos, float rayDistance = 100000.0f)
{ {
// The game is only visible in the main viewport, so if the cursor is outside // The game is only visible in the main viewport, so if the cursor is outside
// of the game window, do not bother calculating anything // of the game window, do not bother calculating anything
@ -321,7 +306,7 @@ namespace Dalamud.Game.Gui
} }
} }
worldPos = new SharpDX.Vector3 worldPos = new Vector3
{ {
X = worldPosArray[0], X = worldPosArray[0],
Y = worldPosArray[1], Y = worldPosArray[1],
@ -332,23 +317,6 @@ namespace Dalamud.Game.Gui
return isSuccess; return isSuccess;
} }
/// <summary>
/// Converts screen coordinates to in-world coordinates via raycasting.
/// </summary>
/// <param name="screenPos">Screen coordinates.</param>
/// <param name="worldPos">Converted coordinates.</param>
/// <param name="rayDistance">How far to search for a collision.</param>
/// <returns>True if successful. On false, worldPos's contents are undefined.</returns>
/// <remarks>
/// This overload requires a conversion to SharpDX vectors, however the penalty should be negligible.
/// </remarks>
public bool ScreenToWorld(Vector2 screenPos, out Vector3 worldPos, float rayDistance = 100000.0f)
{
var result = this.ScreenToWorld(screenPos.ToSharpDX(), out var sharpworldPos);
worldPos = sharpworldPos.ToSystem();
return result;
}
/// <summary> /// <summary>
/// Gets a pointer to the game's UI module. /// Gets a pointer to the game's UI module.
/// </summary> /// </summary>