Jump to content
  • Advertisement
Sign in to follow this  
break_r

My Pick function is 4 pixels off!

This topic is 4545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I cut'n paste this portion from the "Pick" sample in the DirectX SDK: ------------------------------------------------------------ void Pick() { D3DXVECTOR3 vPickRayDir; D3DXVECTOR3 vPickRayOrig; if( GetCapture() ) { POINT ptCursor; GetCursorPos( &ptCursor ); ScreenToClient( g_hWnd, &ptCursor ); // Compute the vector of the Pick ray in screen space D3DXVECTOR3 v; v.x = (( 2.0f * ptCursor.x ) / 640 - 1) / g_matProj._11; v.y = -(( 2.0f * ptCursor.y ) / 480 - 1) / g_matProj._22; v.z = 1.0f; D3DXMATRIX mWorldView = g_matWorld * g_matView; D3DXMATRIX mInv; D3DXMatrixInverse( &mInv, NULL, &mWorldView ); // Transform the screen space Pick ray into 3D space vPickRayDir.x = v.x*mInv._11 + v.y*mInv._21 + v.z*mInv._31; vPickRayDir.y = v.x*mInv._12 + v.y*mInv._22 + v.z*mInv._32; vPickRayDir.z = v.x*mInv._13 + v.y*mInv._23 + v.z*mInv._33; vPickRayOrig.x = mInv._41; vPickRayOrig.y = mInv._42; vPickRayOrig.z = mInv._43; D3DXIntersect(g_pCubeMesh, &vPickRayOrig, &vPickRayDir, &g_bHit, NULL,NULL, NULL, NULL, NULL, NULL); } } ------------------------------------------------------------ I don't have a camera class, just the following setup: ------------------------------------------------------------ D3DXMatrixIdentity( &g_matWorld ); g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld); D3DXMatrixPerspectiveFovLH( &g_matProj, D3DX_PI / 4, 640.0f/480.0f, 1.0f, 10000.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_matProj ); D3DXMatrixLookAtLH( &g_matView, &D3DXVECTOR3( 0.0f, 0.0f, -4.0f ), // eye &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), // look at &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) ); // up g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_matView ); ------------------------------------------------------------ Every frame I render g_pCubeMesh and I don't move the world or view matrices, I just call Pick(). Now, I must be doing something wrong because it registers a hit 4 pixels off to the right and about 12 or so pixels down. It's like the cube is slightly offset from the one that is rendered. Thx, - 3am and blurry-eyed [Edited by - break_r on May 8, 2006 10:21:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
My guess would be that the ScreenToClient function gives windows coordiates, not taking into account the border and menu. (I assume you're running in a window.)

Let me know if this is the case. If you don't mind waiting, I'll likely check this further this weekend, since I'm playing with picking anyway.

Share this post


Link to post
Share on other sites
Hi,

I did what u suggested using GetSystemMetrics() to offset the title bar height and the window border. Appears to work although it's still 1 pixel off *rolls eyes* I guess I can live with that =P

Thanks a lot, I needed a fresh pair of eyes to see what was right in front of me!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!