Sign in to follow this  
hurstshifter

Lazyfoo Tutorial Question

Recommended Posts

Hey Guys, I have a quick question regarding LazyFoo's SDL tutorial #19 if anyone has gone through this before. http://lazyfoo.net/SDL_tutorials/lesson19/index.php Basically, in the following line...
//If no sides from vertical A are outside of B
        if( ( ( bottomAv <= topB ) || ( topAv >= bottomB ) || ( rightAv <= leftB ) || ( leftAv >= rightB ) ) == false )
        {
            //A collision is detected
            return true;
        }

...lazyFoo describes how to calculate whether a circular object has collided with a rectangular object. Works great and makes sense to me, but, is there a reason why he used the "== false" line in his if statement? Couldn't he have just flipped the greater thans to less thans and vice versa? Maybe I'm missing something huge here. [/source]

Share this post


Link to post
Share on other sites
Quote:
is there a reason why he used the "== false" line in his if statement?


Not really; I wouldn't have written it that way.

Another way to negate the whole thing is to just put a '!' in front:


if( !( ( bottomAv <= topB ) || ( topAv >= bottomB ) || ( rightAv <= leftB ) || ( leftAv >= rightB ) ) )
// ^ there, so that it refers to the entire condition


Quote:
Couldn't he have just flipped the greater thans to less thans and vice versa?


You would also have to change the ||'s to &&'s.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Quote:
is there a reason why he used the "== false" line in his if statement?


Not really; I wouldn't have written it that way.

Another way to negate the whole thing is to just put a '!' in front:


if( !( ( bottomAv <= topB ) || ( topAv >= bottomB ) || ( rightAv <= leftB ) || ( leftAv >= rightB ) ) )
// ^ there, so that it refers to the entire condition


Quote:
Couldn't he have just flipped the greater thans to less thans and vice versa?


You would also have to change the ||'s to &&'s.



I see. The logical not operator definitely makes it look cleaner. I'm going to use your method instead. Thanks for the tip.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this