SHARE
TWEET

dice and AABB test

ulfben Sep 12th, 2017 (edited) 277 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top