Esempio n. 1
0
sphere::sphere(sphere const& other) :
shape(other.name(), other.Color()),
center_(other.center()),
radius_(other.radius())
{
	// cout << "sphere copy c'tor" << endl;
}
Esempio n. 2
0
	bool bbox::intersects(const sphere& s) const
	{
		const vec3& center(s.center());
		float radius(s.radius());

		return ((center.x >= mn.x && (mn.x - center.x) <= radius) &&
			(center.x <= mx.x && (center.x - mx.x) <= radius) &&
			(center.y >= mn.y && (mn.y - center.y) <= radius) &&
			(center.y <= mx.y && (center.y - mx.y) <= radius) &&
			(center.z >= mn.z && (mn.z - center.z) <= radius) &&
			(center.z <= mx.z && (center.z - mx.z) <= radius));
	}
Esempio n. 3
0
	bool ray::intersects(const sphere& s, float* f) const
	{
		const vec3& rayorig(pos - s.center());
		float radius(s.radius());

		if(f) *f = 0.0f;
		if(rayorig.lengthSq() <= (radius * radius))
			return true;
		float a(dir.dot(dir));
		float b(2.0f * rayorig.dot(dir));
		float c(rayorig.dot(rayorig) - radius * radius);
		float d((b * b) - (4.0f * a * c));
		if(d < SSH_EPSILON) return false;
		if(f)
		{
			*f = (-b - sqrtf(d)) / (2.0f * a);
			if(*f < 0.0f) *f = (-b + sqrtf(d)) / (2.0f * a);
		}

		return true;
	}