src/rcrt/primitives/Triangle.h

Go to the documentation of this file.
00001 #ifndef TRIANGLE_H_
00002 #define TRIANGLE_H_
00003 
00004 #include "Primitive.h"
00005 #include "Vertex.h"
00006 #include "AABB.h"
00007 #include "../Ray.h"
00008 #include "../Intersection.h"
00009 #include <limits>
00010 #include <algorithm>
00011 
00012 namespace rcrt
00013 {
00014 
00018 class Triangle : public Primitive
00019 {
00020 protected:
00021         Vertex* a;
00022         Vertex* b;
00023         Vertex* c;
00024         AABB box;
00025         
00026         Point3D center; //precomputed
00027         Vec3D faceNormal; //precomputed and checked against given or vertex normals
00028         Vec3D tangent; //precomputed
00029         bool ownVertices; //whether or not the triangle should delete its vertices
00030         bool smooth; //do smooth shading?
00031         
00032         
00033         //helper methods for signed volume intersection test
00034         float volume(const Point3D& o, const Point3D& e,
00035                         const Point3D& a, const Point3D& b) const;
00036         bool sameSign(const float& a, const float& b) const;
00037         
00038 public:
00046         Triangle(const Point3D& a,const Point3D& b,const Point3D& c,
00047                         const Vec3D& fNo, SolidObject* parent=0);
00048 
00056         Triangle(Vertex* av,Vertex* bv,Vertex* cv, SolidObject* parent=0, bool smooth = false);
00057         virtual ~Triangle();
00058         
00063         Vertex* operator[] (int i) const;
00064         Vertex*& operator[] (int i);
00065         
00066         virtual Intersection intersect(Ray& ray) const;
00067         virtual const AABB& getBoundingBox() const;
00068         virtual const Point3D& getCentroid() const;
00069         
00070         virtual Vec3D getSNormal(float beta, float gamma) const;
00071         virtual Vec3D getGNormal(float beta, float gamma) const;
00072         virtual Point2D getUV(float beta, float gamma) const;
00073         virtual Point3D getPoint(float beta, float gamma) const;
00074         virtual Point2D getUV(const Point2D& p) const;
00075         virtual Point3D getPoint(const Point2D& p) const;
00076         virtual Vec3D getTangent(float beta, float gamma) const;
00077         virtual bool isSmooth() const;
00078         
00079         void updateBox();
00080         
00081         void clipPlane(Axis axis, float plane, AABB& lBox, AABB& rBox) const;
00082 };
00083 
00084 }
00085 
00086 #endif /*TRIANGLE_H_*/

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3