[Help] Camera, Coordinates, WorldToScren etc. menu

Shout-Out

User Tag List

Results 1 to 3 of 3
  1. #1
    radegast's Avatar Member
    Reputation
    5
    Join Date
    Jan 2008
    Posts
    32
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help] Camera, Coordinates, WorldToScren etc.

    Hi,
    I tried to understand how to convert world coordinates to screen coordinates. I read appropriate stuff in this forum, but I'm stil missing something.
    I used code, found in this forum, it works, but partially.

    Code:
            float x, y, z;
            RECT rc = {0,0,1024,768};
    
            const float M_DEG2RAD = 0.01745329251f;
    
    
            float x = bobber.fPos[0];
            float y = bobber.fPos[1];
            float z = bobber.fPos[2];
    
    
    
            //CVec3 vDiff = vWoWPos - camera.vPos;
            float fDiff[3];
            fDiff[0] = x-camera.fPos[0];
            fDiff[1] = y-camera.fPos[1];
            fDiff[2] = z-camera.fPos[2];
    
            //float fProd = vDiff*camera.matView[0];
            float fProd =
                    fDiff[0]*camera.fViewMat[0][0] +
                    fDiff[1]*camera.fViewMat[0][1] +
                    fDiff[2]*camera.fViewMat[0][2];
    
            if( fProd < 0 )
                    return FALSE;
    
    
            //CVec3 vView = vDiff*!camera.matView;
            float fInv[3][3];
    
            fInv[0][0] = camera.fViewMat[1][1]*camera.fViewMat[2][2]-camera.fViewMat[1][2]*camera.fViewMat[2][1];
            fInv[1][0] = camera.fViewMat[1][2]*camera.fViewMat[2][0]-camera.fViewMat[1][0]*camera.fViewMat[2][2];
            fInv[2][0] = camera.fViewMat[1][0]*camera.fViewMat[2][1]-camera.fViewMat[1][1]*camera.fViewMat[2][0];
    
            float fDet = camera.fViewMat[0][0]*fInv[0][0]+camera.fViewMat[0][1]*fInv[1][0]+camera.fViewMat[0][2]*fInv[2][0];
            float fInvDet = 1.0f / fDet;
    
            fInv[0][1] = camera.fViewMat[0][2]*camera.fViewMat[2][1]-camera.fViewMat[0][1]*camera.fViewMat[2][2];
            fInv[0][2] = camera.fViewMat[0][1]*camera.fViewMat[1][2]-camera.fViewMat[0][2]*camera.fViewMat[1][1];
            fInv[1][1] = camera.fViewMat[0][0]*camera.fViewMat[2][2]-camera.fViewMat[0][2]*camera.fViewMat[2][0];
            fInv[1][2] = camera.fViewMat[0][2]*camera.fViewMat[1][0]-camera.fViewMat[0][0]*camera.fViewMat[1][2];
            fInv[2][1] = camera.fViewMat[0][1]*camera.fViewMat[2][0]-camera.fViewMat[0][0]*camera.fViewMat[2][1];
            fInv[2][2] = camera.fViewMat[0][0]*camera.fViewMat[1][1]-camera.fViewMat[0][1]*camera.fViewMat[1][0];
    
            camera.fViewMat[0][0] = fInv[0][0]*fInvDet;
            camera.fViewMat[0][1] = fInv[0][1]*fInvDet;
            camera.fViewMat[0][2] = fInv[0][2]*fInvDet;
            camera.fViewMat[1][0] = fInv[1][0]*fInvDet;
            camera.fViewMat[1][1] = fInv[1][1]*fInvDet;
            camera.fViewMat[1][2] = fInv[1][2]*fInvDet;
            camera.fViewMat[2][0] = fInv[2][0]*fInvDet;
            camera.fViewMat[2][1] = fInv[2][1]*fInvDet;
            camera.fViewMat[2][2] = fInv[2][2]*fInvDet;
    
            float fView[3];
            fView[0] = fInv[0][0]*fDiff[0]+fInv[1][0]*fDiff[1]+fInv[2][0]*fDiff[2];
            fView[1] = fInv[0][1]*fDiff[0]+fInv[1][1]*fDiff[1]+fInv[2][1]*fDiff[2];
            fView[2] = fInv[0][2]*fDiff[0]+fInv[1][2]*fDiff[1]+fInv[2][2]*fDiff[2];
    
            //CVec3 vCam( -vView.fY,-vView.fZ,vView.fX );
            float fCam[3];
            fCam[0] = -fView[1];
            fCam[1] = -fView[2];
            fCam[2] =  fView[0];
    
            float    fScreenX = (rc.right-rc.left)/2.0f;
            float    fScreenY = (rc.bottom-rc.top)/2.0f;
    
            // Thanks pat0! Aspect ratio fix
            float    fTmpX    = fScreenX/tan(((camera.fFov*44.0f)/2.0f)*M_DEG2RAD);
            float    fTmpY    = fScreenY/tan(((camera.fFov*35.0f)/2.0f)*M_DEG2RAD);
    
            POINT pctMouse;
    
            pctMouse.x = fScreenX + fCam[0]*fTmpX/fCam[2];
    
            pctMouse.y = fScreenY + fCam[1]*fTmpY/fCam[2];
    Code:
    struct SCameraInfo
    {
            DWORD   dwFoo1[2];
            float   fPos[3];
            float   fViewMat[3][3];
            DWORD dwFoo2[2];  //[2]
            float   fFov;
    };
    I found another way(didn't try yet), which calculates it from camera's position and rotation:
    Code:
    BOOL scrPos(float x, float y, float z, POINT *pt){
    	// return scrpos relative to leftup corner, x positive to right, y positive to downward
    	// to be compatible with MouseClick
    	/* some transformation, by wanyancan.
    		transed := ({
       {1, 0, 0, -camx},
       {0, 1, 0, -camy},
       {0, 0, 1, -camz},
       {0, 0, 0, 1}
      })
    zroted := ({
        {cosY, -sinY, 0, 0},
        {sinY, cosY, 0, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 1}
       }).transed
    xroted := ({
        {1, 0, 0, 0},
        {0, cos[alpha], sin[alpha], 0},
        {0, -sin[alpha], cos[alpha], 0},
        {0, 0, 0, 1}
       }).zroted
    pos := xroted.({
        {myx},
        {myy},
        {myz},
        {1}
       })  = {{-camx cosY + cosY myx + camy sinY - 
       myy sinY}, {cosY myy cos[alpha] + 
       myx sinY cos[alpha] + (-camy cosY - camx sinY) cos[alpha] - 
       camz sin[alpha] + myz sin[alpha]}, {-camz cos[alpha] + 
       myz cos[alpha] - cosY myy sin[alpha] - 
       myx sinY sin[alpha] - (-camy cosY - camx sinY) sin[alpha]}, {1}}
    	*/
    	float camX = ReadFloat(LPCVOID(G_CAMPOS+4)); // camera position
    	float camY = ReadFloat(LPCVOID(G_CAMPOS));
    	float camZ = ReadFloat(LPCVOID(G_CAMPOS+8));
    	float camRotX = ReadFloat(LPCVOID(G_CAMROT));  // camera horizontal direction (0 , 2*pi) north is 0, positive counter-clockwise
    	float camRotY = ReadFloat(LPCVOID(G_CAMROT+4)); // camera vertical direction (-pi/2, pi/2) look upward is positive 
    	float alpha = asinf(camRotX);
    	float cosY = cosf(camRotY);
    	float sinY = sinf(camRotY);
    
    	float pos0 = -camX*cosY+cosY*x+camY*sinY-y*sinY;
    	float pos1 = cosY*y*cosf(alpha)+x*sinY*cosf(alpha)+(-camY*cosY-camX*sinY)*cosf(alpha)-camZ*sinf(alpha) + z*sinf(alpha);
    	float pos2 = -camZ*cosf(alpha)+z*cosf(alpha)-cosY*y*sinf(alpha)-x*sinY*sin(alpha)-(-camY*cosY-camX*sinY)*sin(alpha);
    	if (pos1<0.1)
    		return FALSE;
    	float fov = 3.1415926/2*0.7;  // field of view , view angle is about 0.7
    
    	RECT rect;
    	GetClientRect(wowhwnd, &rect);
    	float modifier = 1.0f;
    	if(1.0*rect.right/rect.bottom>1.5) 
    		modifier *=1.15;  // widescreen modifier
    	float scrX = -pos0/pos1/tanf(fov/2*1.08*modifier) * rect.right/2;
    	float scrY = -pos2/pos1/tanf(fov/2*0.85) * rect.bottom/2;
    
    	//printf("cam (%.1f,%.1f,%.1f), camRot (%.1f,%.1f), obj(%.1f,%.1f,%.1f) scr (%.1f, %.1f)\n", camX, camY, camZ, camRotX, camRotY, x,y,z, scrX, scrY);
    	if (abs(scrX)*3>rect.right || abs(scrY)*3>rect.bottom)
    		return FALSE;  // out of center 1/3 rectangle.
    	pt->x = scrX+rect.right/2; pt->y = scrY+rect.bottom/2;
    	return TRUE;
    }
    My questions:

    1/ Is the struct SCameraInfo stil valid? I found this: Cataclysm - WoWDev
    2/ What is EXACTLY float fViewMat[3][3]; in SCameraInfo?? Is it ViewMatrix, as showed here?
    [Help] Camera, Coordinates, WorldToScren etc.-mv-png
    3/ What is the correct way of using fViewMat[3][3] ?? In first included code it computes inverse matrice to fViewMat[3][3] etc.etc. ... please point me to clarification, what it exactly does to get screen coordinates of any object in world.
    4/ Where I can find information, needed for Projection Matrix construction? The code above works for 1024/768 window only, because of hardcoded constants.

    Thanx for answer

    PS: sorry for my english .)

    [Help] Camera, Coordinates, WorldToScren etc.
  2. #2
    TOM_RUS's Avatar Legendary
    Reputation
    914
    Join Date
    May 2008
    Posts
    699
    Thanks G/R
    0/52
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is what i'm using in my overlay and it seems to work:
    Code:
        [StructLayout(LayoutKind.Sequential)]
        struct WoWCamera
        {
            public IntPtr vtable;               // 0x00
            public int field4;                  // 0x04
            public SharpDX.Vector3 Position;    // 0x08
            public SharpDX.Matrix3x3 ViewMat;   // 0x14
            public float Fov;                   // 0x38
    
            public float NearClip
            {
                get { return Memory.Read<float>(Memory.BaseAddress + Offsets.World_NearClip_x86); }
            }
    
            public float FarClip
            {
                get
                {
                    float farClip = Memory.Read<float>(Memory.BaseAddress + Offsets.World_FarClip_x86);
                    float minFarClip = Memory.Read<float>(Memory.BaseAddress + Offsets.World_MinFarClip_x86);
    
                    return Math.Max(farClip, minFarClip);
                }
            }
        }
    
    =======================================================================
    
            public const int WorldFrame_x86 = 0xD93E30; // CGWorldFrame::s_currentWorldFrame
            public const int WorldFrame_ActiveCamera_x86 = 0x7610;
    
            public const int World_NearClip_x86 = 0xBC3F00; // World::GetNearClip
            public const int World_FarClip_x86 = 0xE6A12C; // World::GetFarClip
            public const int World_MinFarClip_x86 = 0xBC3F04; // World::GetFarClip
    
    =======================================================================
    
                device.SetRenderState(RenderState.ZEnable, false);
                device.SetRenderState(RenderState.Lighting, false);
                device.SetRenderState(RenderState.CullMode, Cull.None);
                Matrix projMat = Matrix.OrthoOffCenterLH(0, form.Width, form.Height, 0, 0, 1);
                device.SetTransform(TransformState.Projection, projMat);
    
    =======================================================================
    
                WoWCamera camera = Memory.Read<WoWCamera>(Memory.Read<IntPtr>(Memory.Read<IntPtr>(Memory.BaseAddress + Offsets.WorldFrame_x86) + Offsets.WorldFrame_ActiveCamera_x86));
    
                SharpDX.Vector3 vEyePt = camera.Position;
                SharpDX.Vector3 vLookatPt = vEyePt + camera.ViewMat.Row1;
                SharpDX.Vector3 vUpVec = new SharpDX.Vector3(0.0f, 0.0f, 1.0f);
    
                Viewport viewport = device.Viewport;
    
                SharpDX.Matrix proj = SharpDX.Matrix.PerspectiveFovRH(camera.Fov * 0.6f, viewport.AspectRatio, camera.NearClip, camera.FarClip);
                SharpDX.Matrix view = SharpDX.Matrix.LookAtRH(vEyePt, vLookatPt, vUpVec);
                SharpDX.Matrix world = SharpDX.Matrix.Identity;
    
                SharpDX.Vector3 worldPos = obj.Position;
                SharpDX.Vector3 screenPos = viewport.WorldToScreen(worldPos, world, view, proj, out bool onScreen);
    
    ==========================================================================================
    
            public static Vector3 WorldToScreen(this Viewport viewport, Vector3 v, Matrix world, Matrix view, Matrix projection, out bool onScreen)
            {
                SharpDX.Vector3 result = viewport.Project(v, projection, view, world);
                // viewport.MaxDepth = 0.94f;
                onScreen = result.Z < viewport.MaxDepth;
                return result;
            }

  3. #3
    radegast's Avatar Member
    Reputation
    5
    Join Date
    Jan 2008
    Posts
    32
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi TOM_RUS. Thanks for answer.

    Yesterday I tried this d3d way too. It worked for me but not so exactly. I used ptrs+offsets found in : ([WoW] [6.0.3 19116] Release Info Dump Thread). They look the same you posted, but with different names.

    Now I see, my camera struct was obsolete.
    Actualy I tried it with some random FOV values choosen, also with 1,57. Now i think my second problem in ProjMatrix construction was znearPlane and zfarPlane. I didnt know it, so i chose it, obviously not so good :/

    I'll try your way today and I hope it will be OK.


    Exists somewere any complete structure, describing wow.exe construction? I mean classes, methods, variables ... like // CGWorldFrame::s_currentWorldFrame you used in comments ... (and others too).

    Thanks

Similar Threads

  1. [Question] Need help to change Camera view
    By Svempy in forum WoW ME Questions and Requests
    Replies: 7
    Last Post: 07-11-2010, 06:36 AM
  2. Helpful Sites For Displays... Etc
    By Ground Zero in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 11-12-2008, 10:46 AM
  3. [Help] With "Drivers/etc/hosts.file" I wanna play my own server!
    By adnano in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 12-30-2007, 10:20 PM
  4. Everything you ever need [Commands Help Instructions How to add stuff etc] [Updates]
    By Dryice in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 11-12-2007, 02:35 PM
  5. DTV/Old IF etc. coordinates requests :P
    By Nezdragon in forum World of Warcraft General
    Replies: 0
    Last Post: 09-17-2006, 03:25 PM
All times are GMT -5. The time now is 09:16 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search