Thread: Mouse Coordinates are Off

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109

    Mouse Coordinates are Off

    I'm working on capturing the mouse coordinates in a little game I'm making during some time off. I go to work on the ability to select different units, and I notice that my selection appears off. Upon further investigation, I can't find anything wrong with my code. So, I decide to output mouse coordinates to the screen so I can run some tests. The mouse starts at 0,0 in the top right perfectly fine. I have a small test map up, and I go to the corner of it which the game tells me is at 512,512. The mouse is telling its 508,484. So, I think maybe something is stretching my map. To test to see if maybe it's my map drawing algorithm that's off, I have a box drawn using 0,0 512,0 512,512 and 0,512 as the corners. It lines up with corners of what I have drawn, but not with the mouse.

    I'm using Direct3D 9, on Windows XP. Is there any reason anyone can think of that the coordinates might be off? In the far right corner of my window it tells me the coordinates are 795,567 and I figure that's about right for an 800x600 window taking the caption/system menu bar into account and the border.

    Here's how I query for my mouse coordinates:

    PHP Code:
    case WM_LBUTTONDOWN:
         
    ptCurrentMousePosit.LOWORD(lParam);
         
    ptCurrentMousePosit.HIWORD(lParam);

         
    // ... handle coordinates and test for selection ... 

    I checked MSDN and they gave me no reason to believe that the coordinates which this give me should be wrong. I use the exact same method for WM_MOUSEMOVE so I can record the mouse coordinates on the screen for testing (Source). On that source, it mentions using GET_X_LPARAM and GET_Y_LPARAM, however I've seen it done correctly the way I am doing it, and MSVC++ 2005 Express Edition complains that they don't exist even though they are supposed to be in windows.h.

    My screen resolution is 1280x1024, but I doubt that has anything to do with it.

    Is there any reason the drawing could be stretched or something? I don't have any reason to believe that its a projection problem, however I'm open to any and all suggestions you might have. The back buffer is the same size as the window by the way, so it isn't becuase there is a size difference between the two.

    Thanks for any help in advance.
    Last edited by Morgul; 08-18-2006 at 11:56 AM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get relative mouse coordinates when GLUT return absolute
    By joeprogrammer in forum Game Programming
    Replies: 14
    Last Post: 02-10-2009, 06:35 PM
  2. Finding mouse coordinates without disturbing its position
    By abachler in forum Networking/Device Communication
    Replies: 4
    Last Post: 10-21-2008, 11:19 AM
  3. Replies: 2
    Last Post: 02-18-2008, 04:53 AM
  4. Retrieving mouse coordinates behind a window.
    By Kurisu33 in forum Windows Programming
    Replies: 3
    Last Post: 10-04-2006, 02:11 PM
  5. Screen coordinates and mouse pointer manipulation
    By Zewu in forum Windows Programming
    Replies: 1
    Last Post: 03-25-2005, 05:30 PM