gKitGL
PTNTriangle.h
00001 
00002 #ifndef _GK_PTN_TRIANGLE_H
00003 #define _GK_PTN_TRIANGLE_H
00004 
00005 #include "Geometry.h"
00006 #include "Transform.h"
00007 #include "PNTriangle.h"
00008 
00009 namespace gk {
00010     
00011 //! representation d'un triangle position + coordonnees de texture + normale.
00012 struct PTNTriangle : public PNTriangle
00013 {
00014     Point2 ta, tb, tc;
00015     
00016     //! constructeur par defaut.
00017     PTNTriangle( ) 
00018         :
00019         PNTriangle()
00020     {}
00021     
00022     //! construit un triangle connaissant ses 3 sommets, leurs normales et leurs coordonnees de textures.
00023     PTNTriangle( 
00024         const Point& _a, const Normal& _na, const Point2& _ta,
00025         const Point& _b, const Normal& _nb, const Point2& _tb,
00026         const Point& _c, const Normal& _nc, const Point2& _tc )
00027         :
00028         PNTriangle(_a, _na, _b, _nb, _c, _nc),
00029         ta(_ta), tb(_tb), tc(_tc)
00030     {}
00031     
00032     //! construit un triangle connaissant le triangle de base, les normales et les coordonnees de textures des sommets.
00033     PTNTriangle( const Triangle& _abc,
00034         const Normal& _na, const Point2& _ta,
00035         const Normal& _nb, const Point2& _tb,
00036         const Normal& _nc, const Point2& _tc )
00037         :
00038         PNTriangle(_abc, _na, _nb, _nc),
00039         ta(_ta), tb(_tb), tc(_tc)
00040     {}
00041     
00042     //! construit un triangle connaissant un pn triangle et les coordonnees de textures des sommets.
00043     PTNTriangle( const PNTriangle& _abc, const Point2& _ta, const Point2& _tb, const Point2& _tc )
00044         :
00045         PNTriangle(_abc),
00046         ta(_ta), tb(_tb), tc(_tc)
00047     {}
00048     
00049     //! destructeur.
00050     ~PTNTriangle( ) {}
00051     
00052     //! renvoie un pntriangle transforme par 't'.
00053     PTNTriangle transform( const Transform& t )
00054     {
00055         return PTNTriangle( 
00056             t(a), t(na), ta, 
00057             t(b), t(nb), tb, 
00058             t(c), t(nc), tc );
00059     }
00060     
00061     //! renvoie le triangle geometrique.
00062     Triangle getBaseTriangle( )
00063     {
00064         return Triangle(a, b, c);
00065     }
00066     
00067     //! renvoie le pn triangle.
00068     PNTriangle getPNTriangle( )
00069     {
00070         return PNTriangle(a, na, b, nb, c, nc);
00071     }
00072     
00073     //! calcule les coordonnees de texture d'un point a l'interieur du triangle connaissant ses coordonnees barycentriques.
00074     //! convention t(u, v)= (1 - u - v) * ta + u * tb + v * tc.
00075     Point2 getUVTexcoord( const float u, const float v ) const
00076     {
00077         const float w= 1.f - u - v;
00078         return ta * w + tb * u + tc * v;
00079     }
00080 };
00081 
00082 }
00083 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends