//---------------------------------------------------------------------------- // William Baxter III's Ray Tracer // // Project for Comp 238, Raster Graphics // University of North Carolina at Chapel Hill // // $Id:$ //---------------------------------------------------------------------------- #ifndef WB3PLANE_H #define WB3PLANE_H #include "wb3Artifact.hpp" class wb3Plane : public wb3Artifact { public: wb3Plane(const Vec3f& normal, const Vec3f& point); wb3Plane(float A, float B, float C, float D); wb3Plane(); ~wb3Plane() {}; 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; float Dist(const Vec3f& point) const; void Normalize(); void Set(const Vec3f& normal, const Vec3f& point); void SetPoint(const Vec3f& point); void SetTwoSided(bool bTwoSides); bool GetTwoSided() const; protected: Vec3f m_N; // plane eq.: float m_fD; // p . m_N + m_fD = 0; bool m_bTwoSided; }; //---------------------------------------------------------------------------- inline wb3Plane::wb3Plane(const Vec3f& normal, const Vec3f& point) : m_N(normal) { m_fD = -(point * normal); m_bTwoSided = true; } //---------------------------------------------------------------------------- inline wb3Plane::wb3Plane(float A, float B, float C, float D) : m_N(A, B, C) { m_fD = D; m_bTwoSided = true; } //---------------------------------------------------------------------------- inline wb3Plane::wb3Plane() { m_bTwoSided = true; } //---------------------------------------------------------------------------- inline void wb3Plane::GetNormal(const Ray3f& r, const Vec3f &isect, Vec3f& Normal) const { if (m_bTwoSided && r.V()*m_N > 0) Normal = -m_N; // flip normal so lighting will work else Normal = m_N; } //---------------------------------------------------------------------------- inline void wb3Plane::Normalize() { float len = m_N.Length(); if (len>0) { float leninv = 1.0f/len; m_N *= leninv; m_fD *= leninv; } } //---------------------------------------------------------------------------- inline float wb3Plane::Dist(const Vec3f &point) const { // i don't think this is correct return (point * m_N) + m_fD; } //---------------------------------------------------------------------------- inline void wb3Plane::Set(const Vec3f& normal, const Vec3f& point) { m_N = normal; m_fD = -(point * m_N); } //---------------------------------------------------------------------------- inline void wb3Plane::SetPoint(const Vec3f& point) { m_fD = -(point * m_N); } //---------------------------------------------------------------------------- inline void wb3Plane::SetTwoSided(bool bTwoSides) { m_bTwoSided = bTwoSides; } //---------------------------------------------------------------------------- inline bool wb3Plane::GetTwoSided() const { return m_bTwoSided; } //---------------------------------------------------------------------------- #endif