thanks for the code and your contribution!
i have one question. currently i am using a world2screen purely based on slimdx operations. it works but has some quirks and flaws (code below for the ones interested).
i was trying to use your code in hope for better results but there is one problem:
the matrix invert fails all the time. my guess is that i initialize the matrix in the wrong way (data from memory is fine and so is the viewmatrix imo)
how i create the matrix:
Code:
var bCamera = WowReader.ReadRaw(cam + 0x1C, 36);
var viewMatrix = new Matrix4x4();
viewMatrix.M11 = BitConverter.ToSingle(bCamera, 0);
viewMatrix.M12 = BitConverter.ToSingle(bCamera, 4);
viewMatrix.M13 = BitConverter.ToSingle(bCamera, 8);
viewMatrix.M21 = BitConverter.ToSingle(bCamera, 12);
viewMatrix.M22 = BitConverter.ToSingle(bCamera, 16);
viewMatrix.M23 = BitConverter.ToSingle(bCamera, 20);
viewMatrix.M31 = BitConverter.ToSingle(bCamera, 24);
viewMatrix.M32 = BitConverter.ToSingle(bCamera, 28);
viewMatrix.M33 = BitConverter.ToSingle(bCamera, 32);
the invert afterwards will fail.
googeling on this topic and reading docs did not help...
cant figure out whats wrong.
i have a hard time wrapping my head around this topic reading docs. in the end it is just a "nice to have" feature and there are other parts of the code that are more important, but it annoys me to hell that the w2s im am using is not working as it should...
here the slimDX version i currently use:
Code:
public Vector2 world2screen(Vector3 pos)
{
IntPtr cambase = (IntPtr)WowReader.ReadInt64(basemodule + 0x2546398);
IntPtr cam = (IntPtr)WowReader.ReadInt64(cambase + 0x3330);
float X = WowReader.ReadFloat(cam + 0x10);
float Y = WowReader.ReadFloat(cam + 0x14);
float Z = WowReader.ReadFloat(cam + 0x18);
float FOV = WowReader.ReadFloat(cam + 0x40);
//not sure here
float NearClip = 0.2f;
float FarClip = 2112f;
float Aspect = 2.2f;
var bCamera = WowReader.ReadRaw(cam + 0x1C, 36);
var m = new SlimDX.Matrix();
m[0, 0] = BitConverter.ToSingle(bCamera, 0);
m[0, 1] = BitConverter.ToSingle(bCamera, 4);
m[0, 2] = BitConverter.ToSingle(bCamera, 8);
m[1, 0] = BitConverter.ToSingle(bCamera, 12);
m[1, 1] = BitConverter.ToSingle(bCamera, 16);
m[1, 2] = BitConverter.ToSingle(bCamera, 20);
m[2, 0] = BitConverter.ToSingle(bCamera, 24);
m[2, 1] = BitConverter.ToSingle(bCamera, 28);
m[2, 2] = BitConverter.ToSingle(bCamera, 32);
var Projection = SlimDX.Matrix.PerspectiveFovRH(FOV * 0.5f, Aspect, NearClip, FarClip);
var eye = new SlimDX.Vector3(X, Y, Z);
var lookAt = new SlimDX.Vector3(X + m[0, 0], Y + m[0, 1], Z + m[0, 2]);
var up = new SlimDX.Vector3(0f, 0f, 1f);
var View = SlimDX.Matrix.LookAtRH(eye, lookAt, up);
var World = SlimDX.Matrix.Identity;
var WorldPosition = new SlimDX.Vector3(pos.X, pos.Y, pos.Z);
var ScreenPosition = SlimDX.Vector3.Project(WorldPosition, 0f, 0f, 2560, 1440, NearClip, FarClip, World * View * Projection);
return new Vector2(ScreenPosition.X, ScreenPosition.Y);
}