// Check the collision based on type bool AABB::checkCollision(Collider* other) { int type = calculateCollisionType(other); if(type == AABB_AABB) { return checkAABB(dynamic_cast<AABB*>(other)); } else if(type == AABB_LINE) { return(other->checkCollision(this)); } return false; }
// Returns the new velocity to use based on the collision // (If no collision, return given velocity) glm::vec3 AABB::collisionResponseVector(Collider* other, glm::vec3 velocity) { if(calculateCollisionType(other) == AABB_AABB) { AABB* otherAABB = dynamic_cast<AABB*>(other); // If collision, calculate a new velocity if(checkAABB(otherAABB)) { //Play sound when collision happens //see: http://stackoverflow.com/questions/1565439/how-to-playsound-in-c-using-windows-api //see: http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx //Note: you have to place sound file where .exe file is PlaySound(TEXT("bounce.wav"), NULL, SND_ASYNC); // Get the normal (axis) glm::vec3 normal = getNormal(otherAABB); velocity = glm::reflect(velocity, normal); } } return velocity; }
bool Frustum::intersectsWith(const AABBVolume& aabb) const { Vector3f extentsHalf=aabb.extents()*0.5f; return checkAABB(aabb.center()-extentsHalf,aabb.center()+extentsHalf)!=NotInFrustum; }
bool UINode::checkBounds (int x, int y) const { const float _x = x / static_cast<float>(_frontend->getWidth()); const float _y = y / static_cast<float>(_frontend->getHeight()); return checkAABB(_x, _y, getX(), getY(), getWidth(), getHeight()); }