ulfben

dice and AABB test

Sep 12th, 2017
334
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //random() and isColliding() courtesy of ulfben, used with permission.
  2. //  https://pastebin.com/TLEZK0M8
  3. //  RNG in C++11: https://isocpp.org/files/papers/n3551.pdf
  4. //returns random number between min-max (inclusive)
  5. int random(int min, int max) {
  6.     static std::random_device rd; //obtain a random seed from hardware
  7.     static std::mt19937 eng(rd()); //seed the generator
  8.     std::uniform_int_distribution<> distr(min, max); //define the range
  9.     /*std::uniform_real_distribution<>*/ //use if you want floats!
  10.     return distr(eng);
  11. }
  12. //AABB intersection test
  13. bool isColliding(const SDL_Rect& lhs, const SDL_Rect& rhs) {
  14.     SDL_assert(&lhs != &rhs);
  15.     return !(lhs.x + lhs.w < rhs.x  //!(lhs.right < rhs.left
  16.         || rhs.x + rhs.w < lhs.x    //|| rhs.right < lhs.left
  17.         || lhs.y + lhs.h < rhs.y    //|| lhs.bottom < rhs.top
  18.         || rhs.y + rhs.h < lhs.y);  //|| rhs.bottom < lhs.top)
  19. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×