00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _GMTL_TRIOPS_H_
00036 #define _GMTL_TRIOPS_H_
00037
00038 #include <gmtl/Tri.h>
00039
00040 namespace gmtl
00041 {
00054 template< class DATA_TYPE >
00055 Point<DATA_TYPE, 3> center( const Tri<DATA_TYPE>& tri )
00056 {
00057 const float one_third = (1.0f/3.0f);
00058 return (tri[0] + tri[1] + tri[2]) * one_third;
00059 }
00060
00068 template< class DATA_TYPE >
00069 Vec<DATA_TYPE, 3> normal( const Tri<DATA_TYPE>& tri )
00070 {
00071 Vec<DATA_TYPE, 3> normal = cross( tri[1] - tri[0], tri[2] - tri[0] );
00072 normalize( normal );
00073 return normal;
00074 }
00090 template< class DATA_TYPE >
00091 bool operator==( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2 )
00092 {
00093 return ( (tri1[0] == tri2[0]) &&
00094 (tri1[1] == tri2[1]) &&
00095 (tri1[2] == tri2[2]) );
00096 }
00097
00106 template< class DATA_TYPE >
00107 bool operator!=( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2 )
00108 {
00109 return (! (tri1 == tri2));
00110 }
00111
00123 template< class DATA_TYPE >
00124 bool isEqual( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2,
00125 const DATA_TYPE& eps )
00126 {
00127 gmtlASSERT( eps >= 0 );
00128 return ( isEqual(tri1[0], tri2[0], eps) &&
00129 isEqual(tri1[1], tri2[1], eps) &&
00130 isEqual(tri1[2], tri2[2], eps) );
00131 }
00134 }
00135
00136 #endif
00137