ulfben icon

dice and AABB test

ulfben | PRO | 09/12/17 12:14:06 PM UTC | 0 ⭐ | 1050 👁️ | Never ⏰ | []
C++ |

860 B

|

None

|

0 👍

/

0 👎

//random() and isColliding() courtesy of ulfben, used with permission.
//  https://pastebin.com/TLEZK0M8 
//  RNG in C++11: https://isocpp.org/files/papers/n3551.pdf
//returns random number between min-max (inclusive)
int random(int min, int max) {
    static std::random_device rd; //obtain a random seed from hardware
    static std::mt19937 eng(rd()); //seed the generator
    std::uniform_int_distribution<> distr(min, max); //define the range
    /*std::uniform_real_distribution<>*/ //use if you want floats!
    return distr(eng);
}
//AABB intersection test
bool isColliding(const SDL_Rect& lhs, const SDL_Rect& rhs) {
    SDL_assert(&lhs != &rhs);
    return !(lhs.x + lhs.w < rhs.x  //!(lhs.right < rhs.left 
        || rhs.x + rhs.w < lhs.x    //|| rhs.right < lhs.left
        || lhs.y + lhs.h < rhs.y    //|| lhs.bottom < rhs.top
        || rhs.y + rhs.h < lhs.y);  //|| rhs.bottom < lhs.top)
}

Comments

  • Gyqizv icon
    04/02/26 06:14:09 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎