public static Vector2[] WorldToScreen(Matrix4x4 viewMatrix, Size2 screenSize, params Vector3[] points) { Vector2[] worlds = new Vector2[points.Length]; for (int i = 0; i < worlds.Length; i++) worlds[i] = WorldToScreen(viewMatrix, screenSize, points[i]); return worlds; }
public static Matrix4x4 ReadMatrix(IntPtr handle, Int64 _lpBaseAddress) { Matrix4x4 tmp = new Matrix4x4(); byte[] Buffer = WinAPI.ReadMemory(handle, _lpBaseAddress, 64); tmp.M11 = BitConverter.ToSingle(Buffer, (0 * 4)); tmp.M12 = BitConverter.ToSingle(Buffer, (1 * 4)); tmp.M13 = BitConverter.ToSingle(Buffer, (2 * 4)); tmp.M14 = BitConverter.ToSingle(Buffer, (3 * 4)); tmp.M21 = BitConverter.ToSingle(Buffer, (4 * 4)); tmp.M22 = BitConverter.ToSingle(Buffer, (5 * 4)); tmp.M23 = BitConverter.ToSingle(Buffer, (6 * 4)); tmp.M24 = BitConverter.ToSingle(Buffer, (7 * 4)); tmp.M31 = BitConverter.ToSingle(Buffer, (8 * 4)); tmp.M32 = BitConverter.ToSingle(Buffer, (9 * 4)); tmp.M33 = BitConverter.ToSingle(Buffer, (10 * 4)); tmp.M34 = BitConverter.ToSingle(Buffer, (11 * 4)); tmp.M41 = BitConverter.ToSingle(Buffer, (12 * 4)); tmp.M42 = BitConverter.ToSingle(Buffer, (13 * 4)); tmp.M43 = BitConverter.ToSingle(Buffer, (14 * 4)); tmp.M44 = BitConverter.ToSingle(Buffer, (15 * 4)); return tmp; }
public static Vector2 WorldToScreen(Matrix4x4 viewMatrix, Size2 screenSize, Vector3 point) { Vector2 returnVector = Vector2.Zero; float w = viewMatrix.M41 * point.X + viewMatrix.M42 * point.Y + viewMatrix.M43 * point.Z + viewMatrix.M44; if (w >= 0.01f) { float inverseWidth = 1f / w; returnVector.X = (screenSize.Width / 2f) + (0.5f * ( (viewMatrix.M11 * point.X + viewMatrix.M12 * point.Y + viewMatrix.M13 * point.Z + viewMatrix.M14) * inverseWidth) * screenSize.Width + 0.5f); returnVector.Y = (screenSize.Height / 2f) - (0.5f * ( (viewMatrix.M21 * point.X + viewMatrix.M22 * point.Y + viewMatrix.M23 * point.Z + viewMatrix.M24) * inverseWidth) * screenSize.Height + 0.5f); } return returnVector; }