# Is my algorithim incorrect?

Printable View

• 04-04-2004
leeor_net
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
=================================
• 04-04-2004
anonytmouse
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.
• 04-04-2004
leeor_net
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
=================================