1

I have tried to convert the XYZ from a player in world of warcraft to a XY on screen. To do this i found the player XYZ, Camera Matrix, Camera XYZ, Fov, NearClip, FarClip and CameraAspect.

The parameters i found in-game:

Camera Matrix

[-0.79|-0.51|-0.34]
[ 0.55|-0.84| 0.00]
[-0.28|-0.18| 0.94]

Player (target)

X: -9468
Y: 46
Z: 56

Camera

X: -9438
Y: 75
Z: 67

Fov: 1.57
FarClip: 28
NearClip: 28
CameraAspect: 3.7

If everything is calculated, it shold show X:774 Y:433 when using a 1920 by 1080 screen. A friend gave me this pice of code, but i don't understand it :/

using System;
using SlimDX;

#pragma warning disable 649
#pragma warning disable 169

namespace VanillaMagic
{
    public static class Camera
    {
        internal static IntPtr BaseAddress
        {
            get
            {
                var ptr = WoW.hook.Memory.Read<IntPtr>(Offsets.Camera.CameraPtr, true);
                return WoW.hook.Memory.Read<IntPtr>(ptr + Offsets.Camera.CameraPtrOffset);
            }
        }

        private static Offsets.CGCamera cam => WoW.hook.Memory.Read<Offsets.CGCamera>(BaseAddress);

        public static float X => cam.Position.X;
        public static float Y => cam.Position.Y;
        public static float Z => cam.Position.Z;
        public static float FOV => cam.FieldOfView;
        public static float NearClip => cam.NearClip;
        public static float FarClip => cam.FarClip;
        public static float Aspect => cam.Aspect;

        private static Matrix Matrix
        {
            get
            {
                var bCamera = WoW.hook.Memory.ReadBytes(BaseAddress + Offsets.Camera.CameraMatrix, 36);
                var m = new 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);

                return m;
            }
        }

        public static Vector2 WorldToScreen(float x, float y, float z)
        {
            var Projection = Matrix.PerspectiveFovRH(FOV * 0.5f, Aspect, NearClip, FarClip);

            var eye = new Vector3(X, Y, Z);
            var lookAt = new Vector3(X + Matrix[0, 0], Y + Matrix[0, 1], Z + Matrix[0, 2]);
            var up = new Vector3(0f, 0f, 1f);

            var View = Matrix.LookAtRH(eye, lookAt, up);
            var World = Matrix.Identity;

            var WorldPosition = new Vector3(x, y, z);

            var ScreenPosition = Vector3.Project(WorldPosition, 0f, 0f, WindowHelper.WindowWidth, WindowHelper.WindowHeight, NearClip, FarClip, World*View*Projection);
            return new Vector2(ScreenPosition.X, ScreenPosition.Y-20f);
        }
    }
}

Can someone help me out with the math, and how this gets calculated?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ferib
  • 11
  • 1
  • without knowing the coordinate systems is hard to help read: [Understanding 4x4 homogenous transform matrices](http://stackoverflow.com/a/28084380/2521214) and [3D graphic pipeline](http://stackoverflow.com/a/21100338/2521214) so you want to construct 4x4 matrix which represents your camera coordinate system then multiply its inverse by perspective transform matrix (set by your screen aspect,znear,zfar,view angle) and then you just multiply the result matrix by any `(X,Y,Z,1.0)` you want to convert do the perspective division and use just `x,y` of the result... – Spektre May 05 '17 at 07:17

0 Answers0