--- /dev/null
+#include "Sphere.hxx"
+
+Sphere::Sphere(const Vec3f& center, float radius, Shader* shader)
+ : Primitive(shader),
+ m_center(center),
+ m_radius(radius)
+{
+}
+
+Sphere::~Sphere()
+{
+}
+
+bool
+Sphere::Intersect(Ray& ray)
+{
+ float A = ray.direction().dot(ray.direction());
+ float C = (ray.origin()-m_center).dot(ray.origin()-m_center) - m_radius*m_radius;
+ float B = 2 * ray.direction().dot(ray.origin()-m_center);
+
+ if( B*B-4*A*C < 0 )
+ return false;
+
+ float root = sqrtf(B*B-4*A*C);
+ float t = (-B-root)/(2.0f*A);
+ if(t > ray.t())
+ return false;
+
+ if( t < 1e-6 )
+ {
+ t = (-B+root)/(2.0f*A);
+ if( t < 1e-6 || t > ray.t())
+ return false;
+ }
+ ray.setT(t);
+ return true;
+}
+
+Vec3f
+Sphere::GetNormal(Ray& ray)
+{
+ return Vec3f();
+}