Is my algorithim incorrect?

This is a discussion on Is my algorithim incorrect? within the C Programming forums, part of the General Programming Boards category; Ok. I'm having a wierd error with my program. I'm attempting to detect if the mouse position is within a ...

  1. #1
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147

    Question Is my algorithim incorrect?

    Ok. I'm having a wierd error with my program.

    I'm attempting to detect if the mouse position is within a certain bounding box. I'm using a funtion that returns an int (used to be a bool, but, well, I've been trying different things out) if the mouse is within certain boundaries (described in the arguments).

    Now here's the thing. The detection algorithim I've used works perfectly for me in past program that I've written in QBASIC (yeah, oldy!). Anyways, it's not working now. I've set up a statement to determine the output of the funtion by having it set a variable to whatever its return is. It never changes.

    The function to set the mouse variables works for sure. The coords display perfectly onscreen.

    Is my algorithim written incorrectly? Is my compiler screwy (gcc-c++)?

    If anybody could help I'd really appreciate it. Thanks!

    ==============================================
    mouse_stats ms; // Global Mouse Stats

    int CheckMouse_InBox(int x, int y, int w, int h)
    {
    if ( (ms.x > x) && (ms.y > y) && (ms.x < w) && (ms.y < h) )
    return 1;
    else
    return 0;
    }


    Leeor...

    =================================
    Neptune Computer Entertainment
    "You design 'em, we make 'em!"

    Check out our latest project @:
    http://www.geocities.com/theschoolfromhell
    =================================

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If w and h stand for right and bottom then your function is correct. If they stand for width and height then your function should be:
    Code:
    int CheckMouse_InBox(int x, int y, int w, int h)
    {
        if ( (ms.x > x) && (ms.y > y) && (ms.x < x + w) && (ms.y < y + h) )
            return 1;
        else
            return 0;
    }
    Please read this before continuing. Welcome to the boards!

    EDIT:
    >> Is my compiler screwy (gcc-c++)? <<

    No.

    Your website and game look impressive.
    Last edited by anonytmouse; 04-04-2004 at 02:24 PM.

  3. #3
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    Thank you! Heh... I can't believe I forgot that! It's always a good idea to have someone else look over your own code sometimes, right? :-)

    Anyway, again, thanks. I appreciate it!

    Leeor...

    =================================
    Neptune Computer Entertainment
    "You design 'em, we make 'em!"

    Check out our latest project @:
    http://www.geocities.com/theschoolfromhell
    =================================

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash Table outputting incorrect number
    By Paul Skinner in forum C Programming
    Replies: 4
    Last Post: 11-20-2008, 06:19 AM
  2. error on in algorithim
    By v3dant in forum C Programming
    Replies: 1
    Last Post: 11-08-2004, 11:03 AM
  3. Bresenhams Algorithim
    By curlious in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-10-2003, 03:25 AM
  4. It is not incorrect to use void main
    By momo20016 in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 12-22-2002, 10:17 AM
  5. 'The parameter is incorrect' - LoadImage
    By DarkAvenger in forum Windows Programming
    Replies: 1
    Last Post: 04-12-2002, 03:53 PM

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