Jump to content
  • Advertisement
Sign in to follow this  
Stowelly

Transforming mouse co-ordinates into screen space in windowed mode

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

sorry i wasnt sure if this was directx(9) specific but thought was more of a beginner thing. ok my picking method works fine in full screen but in windowed mode i dont think it takes into account the position of the screen when calculating the width and the height in windowed mode and incorectly picks my objects (slightly off centre until i move the window to the top left corner of the screen then is fine). im using the following method to calculate my mouse position
v.x =  ( ( ( 2.0f * mouseX ) / mainViewport.Width  ) - 1 ) / matProj._11;
v.y = -( ( ( 2.0f * mouseY ) / mainViewport.Height ) - 1 ) / matProj._22; 
v.z =  1.0f;
mousePos = v;
thanks

Share this post


Link to post
Share on other sites
Advertisement
Make sure you use ScreenToClient() before plugging in the mouse coordinates - otherwise you can end up being a few (or more) pixels out due to the windows location and border/titles.

That fragment of code looks like the one from the "Pick" sample - if you look a bit further up ISTR they use a GetCursorPos() followed by ScreenToClient() to format the mouse coordinates before any 3D-related calculations.

hth
Jack

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!