negative coordinates?

This is a discussion on negative coordinates? within the Windows Programming forums, part of the Platform Specific Boards category; I'm working on a breakout game and i want the paddle to follow the mouse It works from the left ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    negative coordinates?

    I'm working on a breakout game and i want the paddle to follow the mouse
    It works from the left side of the client area to the far right of the screen but when i go over the left side of the client area, i expected it to return a negative value and the paddle keeps moving left but instead, i get some coordinate like (32070, 32389) and it goes right

    i tried adding m.x < 5000 but for some reason, that doesn't work

    Heres the function that moves the paddle and the function i use to get the mouse inputs
    Code:
    void C_Paddle::Paddle_Movement()
    {
        POINT m = Input.Get_Mouse();
        RECT ClientRect;
        GetClientRect(g_hwnd, &ClientRect);
    
        if ((Paddle_Rect.left + Paddle_Size/2) < m.x && m.x < 5000)
        {
            Paddle_Rect.left++;
            Paddle_Rect.right = Paddle_Rect.left + Paddle_Size;
        }
        if ((Paddle_Rect.left + Paddle_Size/2) > m.x)
        {
            Paddle_Rect.left--;
            Paddle_Rect.right = Paddle_Rect.left + Paddle_Size;
        }
    }
    Code:
    void C_Input::Set_Mouse()
    {
        GetCursorPos(&Mouse);
        ScreenToClient(g_hwnd, &Mouse);
    }
    
    POINT Get_Mouse() { return Mouse; }
    Set_Mouse is constantly called in the main loop, would it be better practice to only call it from the wndproc?

    [edit] What brush does the Ellipse function use?

    [edit2] Why didn't i get any warnings when trying to access a private member?
    Last edited by h_howee; 05-03-2007 at 08:01 PM.

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  2. #2
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Do you have variable overflow (or underflow) occurring (i.e. 0 minus 1 gives 65535)? I'm not familiar with mouse usage so I can't help you there.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Well, the mouse goes out the left side so i suppose so
    it should give me a negative x position but y goes up to 32xxx too
    are the members of POINT unsigned?

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  4. #4
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Point, according to the Platform SDK, is a long variable type. I think the problem is that the mouse cursor position is based on the window's position. What you need is to base it on the position on the screen rather than the window.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    >>What you need is to base it on the position on the screen rather than the window.

    I already have that

    ScreenToClient(g_hwnd, &Mouse);

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    i found my mistake
    Paddle_Size was an UINT
    i changed it to an int and it works fine now =)

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  7. #7
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    You should probably have it as the "long" variable type since that's what "POINT" actually uses.

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. Global coordinates in OpenGL?
    By IcyDeath in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2004, 06:29 PM
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM
  4. how to handle integer overflow in C
    By kate1234 in forum C Programming
    Replies: 8
    Last Post: 04-23-2003, 01:20 PM
  5. Size of 1 pixel
    By ooosawaddee3 in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2002, 09:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21