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;
00027 Vec3D faceNormal;
00028 Vec3D tangent;
00029 bool ownVertices;
00030 bool smooth;
00031
00032
00033
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