X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fsphere.hh;fp=src%2FMoof%2FSphere.hh;h=dd4decec8d4224c16945467b820118a9ecdd4d4f;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=f5285545b17a3faa66ba3f4fdd0a250b1bf50a99;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/Moof/Sphere.hh b/src/moof/sphere.hh similarity index 52% rename from src/Moof/Sphere.hh rename to src/moof/sphere.hh index f528554..dd4dece 100644 --- a/src/Moof/Sphere.hh +++ b/src/moof/sphere.hh @@ -12,75 +12,78 @@ #ifndef _MOOF_SPHERE_HH_ #define _MOOF_SPHERE_HH_ -#include -#include -#include -#include -#include -#include -#include +/** + * \file sphere.hh + * A round shape like a circle or sphere. + * TODO: This class needs some work. + */ + +#include +#include +#include +#include +#include +#include +#include -// TODO this needs work -namespace Mf { +namespace moof { /** * A round object. */ - - template -struct Sphere : public Cullable, public Drawable, public Shape +struct sphere : public cullable, public drawable, public shape { - typedef cml::vector< Scalar, cml::fixed > Vector; + typedef moof::vector< scalar, fixed > 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& sphere, Contact& hit) const + bool intersect(const sphere& sphere, contact& 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; @@ -91,10 +94,10 @@ struct Sphere : public Cullable, public Drawable, public Shape return true; } - bool intersect(const Vector& point2, Contact& hit) const + bool intersect(const vector& point2, contact& hit) const { - Vector n = point2 - point; - Scalar distance = n.length(); + vector n = point2 - point; + scalar distance = n.length(); if (distance > radius) return false; @@ -106,16 +109,16 @@ struct Sphere : public Cullable, public Drawable, public Shape } // a ray inside the sphere will not intersect on its way out - bool intersect(const Ray& ray, typename Ray::Contact& hit) const + bool intersect(const ray& ray, typename ray::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; @@ -123,7 +126,7 @@ struct Sphere : public Cullable, public Drawable, public Shape 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; @@ -132,13 +135,13 @@ struct Sphere : public Cullable, public Drawable, public Shape 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); @@ -154,7 +157,7 @@ inline void Sphere<2>::draw(Scalar alpha) const } template <> -inline void Sphere<3>::draw(Scalar alpha) const +inline void sphere<3>::draw(scalar alpha) const { GLUquadricObj* sphereObj = gluNewQuadric(); gluQuadricDrawStyle(sphereObj, GLU_LINE); @@ -170,19 +173,19 @@ inline void Sphere<3>::draw(Scalar alpha) const } template -inline bool checkCollision(const Sphere& a, const Sphere& b) +inline bool checkCollision(const sphere& a, const sphere& 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_