mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Update WorldToScreen
- switch from SharpDX to .NET provided Matrix4x4 and Vector3.Transform - add fix for positions behind the camera
This commit is contained in:
parent
8d402b0797
commit
cd58456c03
1 changed files with 6 additions and 17 deletions
|
|
@ -191,25 +191,14 @@ public sealed unsafe class GameGui : IDisposable, IServiceType
|
||||||
var matrixSingleton = this.getMatrixSingleton();
|
var matrixSingleton = this.getMatrixSingleton();
|
||||||
|
|
||||||
// Read current ViewProjectionMatrix plus game window size
|
// Read current ViewProjectionMatrix plus game window size
|
||||||
var viewProjectionMatrix = default(SharpDX.Matrix);
|
|
||||||
float width, height;
|
|
||||||
var windowPos = ImGuiHelpers.MainViewport.Pos;
|
var windowPos = ImGuiHelpers.MainViewport.Pos;
|
||||||
|
var viewProjectionMatrix = *(Matrix4x4*)(matrixSingleton + 0x1b4);
|
||||||
|
var device = Device.Instance();
|
||||||
|
float width = device->Width;
|
||||||
|
float height = device->Height;
|
||||||
|
|
||||||
unsafe
|
var pCoords = Vector3.Transform(worldPos, viewProjectionMatrix);
|
||||||
{
|
screenPos = new Vector2(pCoords.X / MathF.Abs(pCoords.Z), pCoords.Y / MathF.Abs(pCoords.Z));
|
||||||
var rawMatrix = (float*)(matrixSingleton + 0x1b4).ToPointer();
|
|
||||||
|
|
||||||
for (var i = 0; i < 16; i++, rawMatrix++)
|
|
||||||
viewProjectionMatrix[i] = *rawMatrix;
|
|
||||||
var device = Device.Instance();
|
|
||||||
width = device->Width;
|
|
||||||
height = device->Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
var worldPosDx = worldPos.ToSharpDX();
|
|
||||||
SharpDX.Vector3.Transform(ref worldPosDx, ref viewProjectionMatrix, out SharpDX.Vector3 pCoords);
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue