#ifndef _MOOF_SPHERE_HH_
#define _MOOF_SPHERE_HH_
-#include <Moof/Contact.hh>
-#include <Moof/Cullable.hh>
-#include <Moof/Drawable.hh>
-#include <Moof/Frustum.hh>
-#include <Moof/Math.hh>
-#include <Moof/OpenGL.hh>
-#include <Moof/Shape.hh>
+/**
+ * \file sphere.hh
+ * A round shape like a circle or sphere.
+ * TODO: This class needs some work.
+ */
+
+#include <moof/contact.hh>
+#include <moof/cullable.hh>
+#include <moof/drawable.hh>
+#include <moof/frustum.hh>
+#include <moof/math.hh>
+#include <moof/opengl.hh>
+#include <moof/shape.hh>
-// TODO this needs work
-namespace Mf {
+namespace moof {
/**
* A round object.
*/
-
-
template <int D = 3>
-struct Sphere : public Cullable, public Drawable, public Shape<D>
+struct sphere : public cullable, public drawable, public shape<D>
{
- typedef cml::vector< Scalar, cml::fixed<D> > Vector;
+ typedef moof::vector< scalar, fixed<D> > vector;
- Vector point;
- Scalar radius;
+ vector point;
+ scalar radius;
- Sphere() {}
+ sphere() {}
- Sphere(const Vector& p, Scalar r) :
+ sphere(const vector& p, scalar r) :
point(p),
radius(r) {}
- void init(const Vector& p, Scalar r)
+ void init(const vector& p, scalar r)
{
point = p;
radius = r;
}
- void init(const Vector& p, const Vector& o)
+ void init(const vector& p, const vector& o)
{
point = p;
radius = (o - p).length();
}
- //void encloseVertices(const Vector vertices[], unsigned count);
+ //void enclose_vertices(const vector vertices[], unsigned count);
- //void draw(Scalar alpha = 0.0) const;
- //bool isVisible(const Frustum& frustum) const;
+ //void draw(scalar alpha = 0.0) const;
+ //bool is_visible(const frustum& frustum) const;
- void encloseVertices(const Vector vertices[], unsigned count)
+ void enclose_vertices(const vector vertices[], unsigned count)
{
// TODO
}
- void draw(Scalar alpha = 0.0) const;
+ void draw(scalar alpha = 0.0) const;
- bool isVisible(const Frustum& frustum) const
+ bool is_visible(const frustum& frustum) const
{
return true;
}
- bool intersect(const Sphere<D>& sphere, Contact<D>& hit) const
+ bool intersect(const sphere<D>& sphere, contact<D>& hit) const
{
- Vector n = sphere.point - point;
- Scalar distance = n.length();
- Scalar limit = radius + sphere.radius;
+ vector n = sphere.point - point;
+ scalar distance = n.length();
+ scalar limit = radius + sphere.radius;
if (distance > limit) return false;
return true;
}
- bool intersect(const Vector& point2, Contact<D>& hit) const
+ bool intersect(const vector& point2, contact<D>& hit) const
{
- Vector n = point2 - point;
- Scalar distance = n.length();
+ vector n = point2 - point;
+ scalar distance = n.length();
if (distance > radius) return false;
}
// a ray inside the sphere will not intersect on its way out
- bool intersect(const Ray<D>& ray, typename Ray<D>::Contact& hit) const
+ bool intersect(const ray<D>& ray, typename ray<D>::contact& hit) const
{
- Vector b = point - ray.point;
- Scalar z = cml::dot(b, ray.direction);
+ vector b = point - ray.point;
+ scalar z = dot(b, ray.direction);
// check if the ball is behind the ray
if (z < SCALAR(0.0)) return false;
- Scalar d2 = cml::dot(b, b) - z*z;
- Scalar r2 = radius * radius;
+ scalar d2 = dot(b, b) - z*z;
+ scalar r2 = radius * radius;
// check for an intersection
if (d2 > r2) return false;
hit.distance = z - std::sqrt(r2 - d2);
if (hit.distance < SCALAR(0.0)) return false;
- Vector surfacePoint;
+ vector surfacePoint;
ray.solve(surfacePoint, hit.distance);
hit.normal = surfacePoint - point;
return true;
template <>
-inline bool Sphere<3>::isVisible(const Frustum& frustum) const
+inline bool sphere<3>::is_visible(const frustum& frustum) const
{
return frustum.contains(*this);
}
template <>
-inline void Sphere<2>::draw(Scalar alpha) const
+inline void sphere<2>::draw(scalar alpha) const
{
GLUquadricObj* sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
}
template <>
-inline void Sphere<3>::draw(Scalar alpha) const
+inline void sphere<3>::draw(scalar alpha) const
{
GLUquadricObj* sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
}
template <int D>
-inline bool checkCollision(const Sphere<D>& a, const Sphere<D>& b)
+inline bool checkCollision(const sphere<D>& a, const sphere<D>& b)
{
- Scalar d = (a.point - b.point).length();
+ scalar d = (a.point - b.point).length();
return d < (a.radius + b.radius);
}
-typedef Sphere<2> Sphere2;
-typedef Sphere2 Circle;
-typedef Sphere<3> Sphere3;
+typedef sphere<2> sphere2;
+typedef sphere2 circle;
+typedef sphere<3> sphere3;
-} // namespace Mf
+} // namespace moof
#endif // _MOOF_SPHERE_HH_