Advertisement
ulfben

dice and AABB test

Sep 12th, 2017
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement