//---------------------------------------------------------------------------- // William Baxter III's Ray Tracer // // Project for Comp 238, Raster Graphics // University of North Carolina at Chapel Hill // // $Id:$ //---------------------------------------------------------------------------- #ifndef WB3TRIANGLE_H #define WB3TRIANGLE_H #include #include #include "wb3Plane.hpp" class wb3Triangle : public wb3Plane { public: wb3Triangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3); wb3Triangle(); wb3Triangle(const Vec3f verts[3]); ~wb3Triangle(); virtual const wb3Artifact* Intersect(const Ray3f& r, float *dist, const wb3Artifact* ignore =0) const; float Dist(const Vec3f& point) const; void Set(const Vec3f& normal, const Vec3f& point); void SetPoint(const Vec3f& point); void SetVerts(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3); void SetNormals(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3); void SetTexCoords(const Vec2f& uv1, const Vec2f& uv2, const Vec2f& uv3); void Normalize(); protected: virtual Vec3f& GetColorComponent( Vec3f& color, wb3Component::ComponentType type, const Vec3f& Pw) const; virtual float GetScalarComponent( wb3Component::ComponentType type, const Vec3f& Pw) const; int ptInTri3D(const Vec3f& P) const; bool m_bBFCull; // backface culling or not Vec3f m_vert[3]; // verticies of triangle Vec3f *m_norm; // per-vertex normals Vec2f *m_uv; // UV coordinates for texture mapping }; //---------------------------------------------------------------------------- inline void wb3Triangle::SetPoint(const Vec3f& point) { m_fD = -(point * m_N); } //---------------------------------------------------------------------------- inline void wb3Triangle::Normalize() { float len = m_N.Length(); if (len>0) { float leninv = 1.0f/len; m_N *= leninv; m_fD *= leninv; } } //---------------------------------------------------------------------------- inline float wb3Triangle::Dist(const Vec3f &point) const { // i don't think this is correct return (point * m_N) + m_fD; } //---------------------------------------------------------------------------- inline void wb3Triangle::Set(const Vec3f& normal, const Vec3f& point) { m_N = normal; m_fD = -(point * m_N); } //---------------------------------------------------------------------------- #endif