src/TexturedSmoothTriangle.h

Go to the documentation of this file.
00001 #ifndef TEXTURED_SMOOTH_TRIANGLE_H
00002 #define TEXTURED_SMOOTH_TRIANGLE_H
00003 
00004 
00005 #include "Triangle.h"
00006 #include "Object.h"
00007 #include "TexCoordinate.h"
00008 
00009 
00015 class TexturedSmoothTriangle : public Triangle
00016 {
00017 public:
00018     TexturedSmoothTriangle(const Triangle & v)
00019         : Triangle(v)
00020     {
00021     }
00022 
00023     TexturedSmoothTriangle( const Triangle &    v,
00024                             const Vec3f &       na,
00025                             const Vec3f &       nb,
00026                             const Vec3f &       nc )
00027         : Triangle(v),
00028             mNa(na),
00029             mNb(nb),
00030             mNc(nc)
00031     {
00032         mNa.normalize();
00033         mNb.normalize();
00034         mNc.normalize();
00035     }
00036 
00037     TexturedSmoothTriangle( const Triangle &        v,
00038                             const Vec3f &           na,
00039                             const Vec3f &           nb,
00040                             const Vec3f &           nc,
00041                             const TexCoordinate &   ta,
00042                             const TexCoordinate &   tb,
00043                             const TexCoordinate &   tc )
00044         : Triangle(v),
00045             mNa(na),
00046             mNb(nb),
00047             mNc(nc),
00048             mTa(ta),
00049             mTb(tb),
00050             mTc(tc)
00051     {
00052         mNa.normalize();
00053         mNb.normalize();
00054         mNc.normalize();
00055     }
00056 
00059     void setNormals(const Vec3f & na, const Vec3f & nb, const Vec3f & nc)
00060     {
00061         mNa = na;
00062         mNb = nb;
00063         mNc = nc;
00064 
00065         mNa.normalize();
00066         mNb.normalize();
00067         mNc.normalize();
00068     }
00069 
00074     Vec3f normal(const Ray & ray) const
00075     {
00076         assert(ray.hit() == this);
00077         assert(ray.obj());
00078 
00079         // assume u/v coordinates in ray correspond to beta(u) and gamma
00080         // (v) barycentric coordinates of hit point on triangle (have to be
00081         // stored like this in the intersection code !)
00082 
00083         Vec3f normal = ray.u() * mNb + ray.v() * mNc + (1 - ray.u() - ray.v() ) * mNa;
00084         ray.obj()->toGlobalCoordinates(normal);
00085 
00086         return normal.normal();
00087     }
00088 
00091     void setTexCoord(const TexCoordinate & ta, const TexCoordinate & tb, const TexCoordinate & tc)
00092     {
00093         mTa = ta;
00094         mTb = tb;
00095         mTc = tc;
00096     }
00097 
00100     TexCoordinate texCoord(const Ray & ray) const
00101     {
00102         assert(ray.hit() == this);
00103 
00104         // assume u/v coordinates in ray correspond to beta(u) and gamma
00105         // (v) barycentric coordinates of hitpoint on triangle (have to be
00106         // stored like this in the intersection code !)
00107         float u = ray.u() * mTb.x() + ray.v() * mTc.x() + (1 - ray.u() - ray.v() ) * mTa.x();
00108         float v = ray.u() * mTb.y() + ray.v() * mTc.y() + (1 - ray.u() - ray.v() ) * mTa.y();
00109 
00110         return TexCoordinate(u, v);
00111     }
00112 
00113 private:
00115     Vec3f           mNa;
00116     Vec3f           mNb;
00117     Vec3f           mNc;
00118 
00120     TexCoordinate   mTa;
00121     TexCoordinate   mTb;
00122     TexCoordinate   mTc;
00123 };
00124 
00125 #endif
00126 

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1