direct3d for world to screen menu

User Tag List

Results 1 to 12 of 12
  1. #1
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    direct3d for world to screen

    i'm referring to this thread:http://www.mmowned.com/forums/wow-me...ame-world.html

    i'm trying to use this for world to screen projection

    Code:
    struct SCameraInfo
    {
    	DWORD	dwFoo1[2];
    	float	fPos[3];
    	float	fViewMat[3][3];
    	DWORD	dwFoo2[2];
    	float	fFov;
    };
    
    #define WOW_CAMERA_PTR1		0xB0D578
    #define WOW_CAMERA_OFFSET	0x7E24
    
    bool WorldToScreen( float x, float y, float z, POINT *pt )
    {
    	SCameraInfo cam = read<SCameraInfo>(read<int>(read<int>(WOW_CAMERA_PTR1)+WOW_CAMERA_OFFSET));
    
    	D3DXVECTOR3 Out, In( x, y, z );
    	D3DVIEWPORT9 Viewport;
    	D3DXMATRIX Proj, View, World;
    
    	float fAspect = ((float)1024) / 768;
    	D3DXMatrixPerspectiveFovRH( &Proj, cam.fFov*0.6, fAspect, 1.0f, 10000.0f );
    
    	D3DXVECTOR3 vEyePt( cam.fPos[0], cam.fPos[1], cam.fPos[2] );
    	D3DXVECTOR3 vLookatPt( Localplayer.X(), Localplayer.Y(), Localplayer.Z() );
    	D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    	D3DXMatrixLookAtRH( &View, &vEyePt, &vLookatPt, &vUpVec );
    
    	m_pDevice->GetViewport(&Viewport);
    	D3DXMatrixIdentity(&World);
    
    	D3DXVec3Project( &Out, &In, &Viewport, &Proj, &View, &World );
    
    	pt->x = Out.x;
    	pt->y = Out.y;
    
    	return ( Out.z < 1.f );
    }
    if i draw a rectangle at position of the npcs:


    depending on my camera rotation this cluster of rectangles rotates really strange
    but i can't what i did wrong, so i hope maybe somebody here does see it

    direct3d for world to screen
  2. #2
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by mnbvc View Post
    i'm referring to this thread:http://www.mmowned.com/forums/wow-me...ame-world.html

    i'm trying to use this for world to screen projection

    Code:
    struct SCameraInfo
    {
    	DWORD	dwFoo1[2];
    	float	fPos[3];
    	float	fViewMat[3][3];
    	DWORD	dwFoo2[2];
    	float	fFov;
    };
    
    #define WOW_CAMERA_PTR1		0xB0D578
    #define WOW_CAMERA_OFFSET	0x7E24
    
    bool WorldToScreen( float x, float y, float z, POINT *pt )
    {
    	SCameraInfo cam = read<SCameraInfo>(read<int>(read<int>(WOW_CAMERA_PTR1)+WOW_CAMERA_OFFSET));
    
    	D3DXVECTOR3 Out, In( x, y, z );
    	D3DVIEWPORT9 Viewport;
    	D3DXMATRIX Proj, View, World;
    
    	float fAspect = ((float)1024) / 768;
    	D3DXMatrixPerspectiveFovRH( &Proj, cam.fFov*0.6, fAspect, 1.0f, 10000.0f );
    
    	D3DXVECTOR3 vEyePt( cam.fPos[0], cam.fPos[1], cam.fPos[2] );
    	D3DXVECTOR3 vLookatPt( Localplayer.X(), Localplayer.Y(), Localplayer.Z() );
    	D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    	D3DXMatrixLookAtRH( &View, &vEyePt, &vLookatPt, &vUpVec );
    
    	m_pDevice->GetViewport(&Viewport);
    	D3DXMatrixIdentity(&World);
    
    	D3DXVec3Project( &Out, &In, &Viewport, &Proj, &View, &World );
    
    	pt->x = Out.x;
    	pt->y = Out.y;
    
    	return ( Out.z < 1.f );
    }
    if i draw a rectangle at position of the npcs:


    depending on my camera rotation this cluster of rectangles rotates really strange
    but i can't what i did wrong, so i hope maybe somebody here does see it
    You need to keep checking every second to see if mobs have moved... Because you only check once... they move... you click and u missed em.
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

  3. #3
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't bother posting if you have nothing useful to say...

  4. #4
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WoW uses the Z axis as the 'up' axis.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  5. #5
    Herleybob's Avatar Contributor
    Reputation
    178
    Join Date
    Jul 2007
    Posts
    663
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure you mis-understood him. What he was saying is that you need to create a loop to always check for the location of the mob. you only checked once and then the mobs moved but the squares didn't.

    Nom Nom Nom :P

  6. #6
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i do never check for the position of the npcs in this function because the npc position are the x/y/z values i pass to this function :disbelief:

    calling the function with the right parameters and then drawing it is really not my problem...


    i tested it with this function i found anywhere here, and everything is fine
    Code:
    BOOL WtS( float x, float y, float z, POINT *pt)
    {
    	SCameraInfo camera = read<SCameraInfo>(read<int>(read<int>(WOW_CAMERA_PTR1)+WOW_CAMERA_OFFSET));
    
    	RECT rc = {0,0,1024,768};
    	
    	//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 + vCam.fX*fTmpX/vCam.fZ;
    	pctMouse.x = fScreenX + fCam[0]*fTmpX/fCam[2];
    	//pctMouse.y = fScreenY + vCam.fY*fTmpY/vCam.fZ;
    	pctMouse.y = fScreenY + fCam[1]*fTmpY/fCam[2];
    
    	if( pctMouse.x < 0 || pctMouse.y < 0 || pctMouse.x > rc.right || pctMouse.y > rc.bottom )
    		return FALSE;
    
    	pt->x = pctMouse.x;
    	pt->y = pctMouse.y;
    
    	return TRUE;
    }
    but now i want to do it using the direct3d stuff because if i want to do what the guy in the other thread did (rendering in wow game world), and there i will need it



    Originally Posted by MaiN View Post
    WoW uses the Z axis as the 'up' axis.
    maybe i understood it wrong: http://www.toymaker.info/Games/html/matrices.html
    but this should be solved by using the "righthanded" view und projection matrix creation functions which i'm using
    Last edited by mnbvc; 03-23-2010 at 11:24 AM.

  7. #7
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by mnbvc View Post
    maybe i understood it wrong: Direct3D Matrices
    but this should be solved by using the "righthanded" view und projection matrix creation functions which i'm using
    No it shouldn't. WoW still does not use the right handed cartesian coordinate system.

    Code:
    public static Matrix Projection
    {
        get
        {
            SSimpleCamera internCam = Camera.InternalCamera;
            return Matrix.PerspectiveFovRH(Camera.FOV * 0.6f, internCam.AspectRatio, internCam.NearZ, internCam.FarZ);
        }
    }
    
    public static Matrix View
    {
        get
        {
            SSimpleCamera internCam = Camera.InternalCamera;
            WoWPoint eye = internCam.Position;
            WoWPoint at = eye + Camera.Forward;
            return Matrix.LookAtRH(eye, at, new Vector3(0, 0, 1));
        }
    }
    
    public static bool WorldToScreen(Vector3 position, out Vector3 screen)
    {
        screen = Vector3.Project(position, Endscene.RenderingDevice.Viewport, Projection, View, Matrix.Identity);
    
        return screen.Z < 1f;
    }
    Credits to Kynox for lots of the code and the structs.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  8. #8
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, you are right, thank you


    here the working code, maybe anybody wants to use it for something :P
    Code:
    #define WOW_CAMERA_PTR1		0xBF2AF8
    #define WOW_CAMERA_OFFSET	0x7E24
    
    struct SCameraInfo
    {
    	DWORD	dwFoo1[2]; // 00
    	float	fPos[3]; // 02
    	float	fViewMat[3][3]; // 05
    	float	zNearPlane; // 14
    	float	zFarPlane; // 15
    	float	fFov; //16
    	float	aspect; // 17
    };
    
    LPDIRECT3DDEVICE9 m_pDevice;
    D3DVIEWPORT9 Viewport;
    
    void ProjectionMatrix(D3DXMATRIX *Proj)
    {
    	D3DXMatrixPerspectiveFovRH( Proj, cam->fFov*0.6, cam->aspect, cam->zNearPlane, cam->zFarPlane );
    }
    
    void ViewMatrix(D3DXMATRIX *View)
    {
    	D3DXVECTOR3 vEyePt( cam.fPos[0], cam.fPos[1], cam.fPos[2] );
    	D3DXVECTOR3 vLookatPt( cam.fPos[0]+cam.fViewMat[0][0], cam.fPos[1]+cam.fViewMat[0][1], cam.fPos[2]+cam.fViewMat[0][2] );
    	D3DXVECTOR3 vUpVec( 0.0f, 0.0f, 1.0f );
    	D3DXMatrixLookAtRH( View, &vEyePt, &vLookatPt, &vUpVec );
    }
    
    bool WorldToScreen( D3DXVECTOR3 in, D3DXVECTOR3 *out )
    {
    	cam = read<SCameraInfo>(read<int>(read<int>(WOW_CAMERA_PTR1)+WOW_CAMERA_OFFSET));
    	
    	m_pDevice->GetViewport(&Viewport);
    
    	D3DXMATRIX Proj, View, World;
    	ProjectionMatrix(&Proj);
    	ViewMatrix(&View);
    	D3DXMatrixIdentity(&World);
    
    	D3DXVec3Project( out, &in, &Viewport, &Proj, &View, &World );
    
    	return ( out->z < 1.f );
    }
    Last edited by mnbvc; 03-25-2010 at 06:37 PM.

  9. #9
    Herleybob's Avatar Contributor
    Reputation
    178
    Join Date
    Jul 2007
    Posts
    663
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think ima use this. thanks! I may be contacting you later on...

    Nom Nom Nom :P

  10. #10
    mnbvc's Avatar Banned
    Reputation
    120
    Join Date
    Jul 2009
    Posts
    273
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i changed the camera struct und the projectionmatrix function, it wasn't 100% correct

  11. #11
    speedy7's Avatar Member
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    7
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish the CameraInfo would be pure d3d code so we could use this for diablo 3.

  12. #12
    Greedyone's Avatar Member
    Reputation
    1
    Join Date
    Aug 2011
    Posts
    16
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello!
    Copypasted Function from Post #6 here, adapted to my Delphi project but i have a problem: Screen X-coordinate returned by this function gives value which is shifted towards centre of the screen. Below you can see screenshots which shows: the closer fishing bobber to the centre of scren by X, the more precise position of red circle.
    I can conclude that next part of code is the reason of shift:
    // 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);
    Where the values 44.0f and 35.0f are taken from?
    Do they depends of screen resolution (or from monitor ratio 4:3, 16/9)?


    Here is pic with bobber close to the middle:
    direct3d for world to screen-img3-jpg


    and here 2 pics with shift:

    direct3d for world to screen-img1-jpg


    direct3d for world to screen-img2-jpg



    P.S. My scrren resolution is 1280x1024
    Last edited by Greedyone; 12-29-2011 at 01:57 AM.

Similar Threads

  1. Reputation Calculator Tool for World of Warcraft
    By Little_skip in forum World of Warcraft General
    Replies: 0
    Last Post: 01-09-2008, 12:44 PM
  2. The New Expansion Pack for World of warcraft whats your Opinion on it?
    By Anthony14 in forum World of Warcraft General
    Replies: 21
    Last Post: 09-29-2007, 01:10 PM
  3. Cheat Engine Freezes for World of Warcraft
    By gamerx256 in forum World of Warcraft General
    Replies: 2
    Last Post: 02-15-2007, 04:59 PM
  4. Which is the best Paysite for World of Warcraft?
    By 3min3m in forum World of Warcraft General
    Replies: 5
    Last Post: 12-06-2006, 07:12 PM
  5. Official New Alliance Race for World of Warcraft
    By Matt in forum World of Warcraft General
    Replies: 18
    Last Post: 11-27-2006, 07:25 PM
All times are GMT -5. The time now is 02:05 AM. 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