gKitGL
PNTriangle.h
00001 
00002 #ifndef _GK_PN_TRIANGLE_H
00003 #define _GK_PN_TRIANGLE_H
00004 
00005 #include "Geometry.h"
00006 #include "Transform.h"
00007 #include "Triangle.h"
00008 
00009 namespace gk {
00010     
00011 //! representation d'un triangle position + normale.
00012 struct PNTriangle : public Triangle
00013 {
00014     Normal na, nb, nc;
00015     
00016     //! constructeur par defaut.
00017     PNTriangle( ) 
00018         :
00019         Triangle()
00020     {}
00021     
00022     //! construit un triangle connaissant ses 3 sommets et leur normales.
00023     PNTriangle( 
00024         const Point& _a, const Normal& _na, 
00025         const Point& _b, const Normal& _nb,
00026         const Point& _c, const Normal& _nc )
00027         :
00028         Triangle(_a, _b, _c),
00029         na(_na), nb(_nb), nc(_nc)
00030     {}
00031     
00032     //! construit un triangle connaissant le triangle de base et les normales des sommets.
00033     PNTriangle( const Triangle& abc,
00034         const Normal& _na, const Normal& _nb, const Normal& _nc )
00035         :
00036         Triangle(abc),
00037         na(_na), nb(_nb), nc(_nc)
00038     {}
00039     
00040     //! destructeur.
00041     ~PNTriangle( ) {}
00042     
00043     //! calcule la normale a l'interieur du triangle connaissant ses coordonnees barycentriques.
00044     //! convention n(u, v)= (1 - u - v) * na + u * nb + v * nc.
00045     Normal getUVNormal( const float u, const float v ) const
00046     {
00047         const float w= 1.f - u - v;
00048         return Normalize(na * w + nb * u + nc * v);
00049     }
00050     
00051     //! renvoie un pntriangle transforme par 't'.
00052     PNTriangle transform( const Transform& t )
00053     {
00054         return PNTriangle( t(a), t(na), t(b), t(nb), t(c), t(nc) );
00055     }
00056     
00057     //! renvoie le triangle geometrique support du PN triangle.
00058     Triangle getBaseTriangle( )
00059     {
00060         return Triangle(a, b, c);
00061     }
00062 };
00063 
00064 }
00065 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends