Jump to content
  • Advertisement
Sign in to follow this  
Miikka_J

Problem with directX picking, hits seem to be offset?

This topic is 4517 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

Have been attempting to put together a mouse picking program and have been running into a couple of problems. My function is derived from the pick sample in the SDK but it seems to register hits slightly below and to the right of the object, as if the object has been drawn slightly off of where it should be. Problem persists in fullscreen and windowed, and also when using other peoples algorithms for the picking. Seems to be a consistent problem amoungst them. Thing is the picking demo itself works fine, could it be some sort of windows / d3d init problem (I don't use CD3D application but demo does). I wouldn't know where to look for that sort of thing. Any suggestions would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Are you using ScreenToClient() to translate the GetCursorPos()?

The window border and caption/title need to be compensated for. D3D's (0,0) is not the same as your window's (0,0).

If you look at the Pick sample, there is a pair of calls (run a "find" on 'screentoclient') that handle this - you need to correct for it before you start doing the normal maths stuff.

hth
Jack

Share this post


Link to post
Share on other sites
ScreenToClient() and GetCursor() are already being used, did try compensating for the title with GetSystemMetrics() but the numbers I was getting back for that wern't correct.

Plus none of that explains the persistance of the problem in fullscreen.

Sorry, you can tell I've been working on this for a while.

Share this post


Link to post
Share on other sites
You gotta make sure that your backbuffer width and height are exact for the actual client window, adjusted for the window frame's dimensions (title bar, menu, scrollbars, etc.). Fullscreen should be easier. In MFC, I get the WM_SIZE message and use it for the backbuffer dimensions. For Win32, I think you can do the same thing.

Oh yea, you also have to use the same width/height in your projection matrix.

Share this post


Link to post
Share on other sites
POINT ptCursor;
GetCursorPos( &ptCursor );

D3DVIEWPORT9 mainViewport;
m_pd3dDevice->GetViewport( &mainViewport );

ScreenToClient( m_hWnd, &ptCursor );
mouseX = ptCursor.x - mainViewport.X;
mouseY = ptCursor.y - mainViewport.Y;
m_pd3dDevice->SetCursorPosition( ptCursor.x, ptCursor.y, 0 );

mouseX and mouseY are what i use for the co-ords for the mouse co-ords, compensates for the screen position

[Edited by - Stowelly on July 9, 2006 3:07:43 PM]

Share this post


Link to post
Share on other sites
When you created the window, you did use AdjustWindowRect() to specify the client area size to be the same as the backbuffer size, right?

Share this post


Link to post
Share on other sites
Thanks for all the replies. What I ended up doing was adding the following code after the D3D initialization and in WM_SIZE in winproc to set the correct info in D3DPRESENT_PARAMETERS d3dpp:

HRESULT SetWindowSize()
{
RECT m_rcWindowClient; // Saved client area size for mode switches

// Update window properties
GetClientRect( hwnd, &m_rcWindowClient );

d3dpp.BackBufferWidth = m_rcWindowClient.right - m_rcWindowClient.left;
d3dpp.BackBufferHeight = m_rcWindowClient.bottom - m_rcWindowClient.top;

return S_OK;
}

Although I suspect I will change to AdjustWindowRect() to keep the ratio's right

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!