//---------------------------------------------------------------------------- // 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 "wb3Artifact.hpp" class wb3Sphere : public wb3Artifact { public: wb3Sphere(Vec3f center, float radius); ~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(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::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