Jump to content
  • Advertisement
Sign in to follow this  

Lazyfoo Tutorial Question

This topic is 3276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!