Example #1
0
Box Box::FromSphere(const Sphere &sphere)
{
    Box b;
    b.SetMin(sphere.GetCenter() - Vector3(sphere.GetRadius()));
    b.SetMax(sphere.GetCenter() + Vector3(sphere.GetRadius()));
    return b;
}
Example #2
0
float Plane::DistanceFromSphere( const Sphere & sphere ) const
{
	float distance = Normal() * sphere.GetCenter() + d;

	if ( distance > sphere.GetRadius() ) {
		return distance - sphere.GetRadius();
	}
	if ( distance < -sphere.GetRadius() ) {
		return distance + sphere.GetRadius();
	} else {
		return 0.0f;
	}
}
Example #3
0
bool Renderer::RaySphereIntersection(Ray ray, Sphere sphere)
{
	Vector d = ray.GetDirection();
	Vector e = ray.GetOrigin();
	Vector c = sphere.GetCenter();
	int R = sphere.GetRadius();

	float discriminant = (d ^ (e - c)) * (d ^ (e - c)) - ((d ^ d) * (((e - c) ^ (e - c)) - R * R));

	if(discriminant >= 0.0)
		return true;

	return false;
}