//---------------------------------------------------------------------------- // William Baxter III's Ray Tracer // // Project for Comp 238, Raster Graphics // University of North Carolina at Chapel Hill // // $Id:$ //---------------------------------------------------------------------------- #ifndef WB3SPHERE_H #define WB3SPHERE_H #include "wb3Primitive.hpp" class wb3Sphere : public wb3Primitive { public: wb3Sphere(const Vec3f& center = Vec3f::ZERO, float radius = 0); ~wb3Sphere(); virtual const wb3Artifact* Intersect(const Ray3f& r, float *idist, const wb3Artifact* ignore =0) const; virtual void GetNormal(const Ray3f& r, const Vec3f &isect, Vec3f& normal) const; void SetCenter(const Vec3f& c); const Vec3f& GetCenter(); void SetRadius(float R); void SetRadiusSqr(float R2); float GetRadius() const; float GetRadiusSqr() const; protected: Vec3f m_C; // sphere's center float m_fR2; // sphere's radius squared }; //---------------------------------------------------------------------------- inline void wb3Sphere::SetCenter(const Vec3f& c) { m_C = c; } //---------------------------------------------------------------------------- inline void wb3Sphere::SetRadius(float R) { m_fR2 = R * R; } //---------------------------------------------------------------------------- inline void wb3Sphere::SetRadiusSqr(float R2) { m_fR2 = R2; } //---------------------------------------------------------------------------- inline float wb3Sphere::GetRadius() const { return float(sqrt(m_fR2)); } //---------------------------------------------------------------------------- inline float wb3Sphere::GetRadiusSqr() const { return m_fR2; } //---------------------------------------------------------------------------- inline void wb3Sphere::GetNormal(const Ray3f& r, const Vec3f &isect, Vec3f& normal) const { normal = (isect - m_C); normal.Normalize(); } //---------------------------------------------------------------------------- #endif