Lazyfoo Tutorial Question

Started by
1 comment, last by hurstshifter 14 years, 10 months ago
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]
Advertisement
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.
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.

This topic is closed to new replies.

Advertisement