/* * Check to see if we are colliding with a cube. * If we are, return true. Otherwise return false. * Bounding sphere collision. * @param c The cube to check. */ bool Cube::checkCollision(Cube c) { float r0sqr = getRadius() * getRadius(); float r1sqr = c.getRadius() * c.getRadius(); float distX = getCenter().x - c.getCenter().x; float distY = getCenter().y - c.getCenter().y; float distZ = getCenter().z - c.getCenter().z; // Since we already need to square these, we won't need to take the absolute value // to accurately compare them to the radii distX *= distX; distY *= distY; distZ *= distZ; float sqrDist = (distX+distY+distZ); if((r0sqr + r1sqr) > sqrDist - 0.5f) { return true; } return false; }
double CubeValidator::getDistance(Cube& c1, Cube& c2) { return sqrt( pow((float)(c1.getCenter().x - c2.getCenter().x), 2) + pow((float)(c1.getCenter().y - c2.getCenter().y), 2)); }