source: projectionDesigner/trunk/projdesigner/include/gmtl/TriOps.h @ 411

Last change on this file since 411 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.9 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          TriOps.h,v
10 * Date modified: 2004/09/16 21:21:10
11 * Version:       1.9
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_TRIOPS_H_
36#define _GMTL_TRIOPS_H_
37
38#include <gmtl/Tri.h>
39#include <gmtl/Generate.h>
40#include <gmtl/VecOps.h>
41
42namespace gmtl
43{
44/** @ingroup Ops Tri
45 *  @name Triangle Operations
46 * @{
47 */
48
49/**
50 * Computes the point at the center of the given triangle.
51 *
52 * @param tri     the triangle to find the center of
53 *
54 * @return  the point at the center of the triangle
55 */
56template< class DATA_TYPE >
57Point<DATA_TYPE, 3> center( const Tri<DATA_TYPE>& tri )
58{
59   const float one_third = (1.0f/3.0f);
60   return (tri[0] + tri[1] + tri[2]) * DATA_TYPE(one_third);
61}
62
63/**
64 * Computes the normal for this triangle.
65 *
66 * @param tri     the triangle for which to compute the normal
67 *
68 * @return  the normal vector for tri
69 */
70template< class DATA_TYPE >
71Vec<DATA_TYPE, 3> normal( const Tri<DATA_TYPE>& tri )
72{
73   Vec<DATA_TYPE, 3> normal = makeCross( gmtl::Vec<DATA_TYPE,3>(tri[1] - tri[0]), gmtl::Vec<DATA_TYPE,3>(tri[2] - tri[0]) );
74   normalize( normal );
75   return normal;
76}
77/** @} */
78
79/** @ingroup Compare Tri
80 *  @name Triangle Comparitors
81 *  @{
82 */
83
84/**
85 * Compare two triangles to see if they are EXACTLY the same.
86 *
87 * @param tri1    the first triangle to compare
88 * @param tri2    the second triangle to compare
89 *
90 * @return  true if they are equal, false otherwise
91 */
92template< class DATA_TYPE >
93bool operator==( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2 )
94{
95   return ( (tri1[0] == tri2[0]) &&
96            (tri1[1] == tri2[1]) &&
97            (tri1[2] == tri2[2]) );
98}
99
100/**
101 * Compare two triangle to see if they are not EXACTLY the same.
102 *
103 * @param tri1    the first triangle to compare
104 * @param tri2    the second triangle to compare
105 *
106 * @return  true if they are not equal, false otherwise
107 */
108template< class DATA_TYPE >
109bool operator!=( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2 )
110{
111   return (! (tri1 == tri2));
112}
113
114/**
115 * Compare two triangles to see if they are the same within the given tolerance.
116 *
117 * @param tri1    the first triangle to compare
118 * @param tri2    the second triangle to compare
119 * @param eps     the tolerance value to use
120 *
121 * @pre  eps must be >= 0
122 *
123 * @return  true if they are equal within the tolerance, false otherwise
124 */
125template< class DATA_TYPE >
126bool isEqual( const Tri<DATA_TYPE>& tri1, const Tri<DATA_TYPE>& tri2,
127              const DATA_TYPE& eps )
128{
129   gmtlASSERT( eps >= 0 );
130   return ( isEqual(tri1[0], tri2[0], eps) &&
131            isEqual(tri1[1], tri2[1], eps) &&
132            isEqual(tri1[2], tri2[2], eps) );
133}
134/** @} */
135
136} // namespace gmtl
137
138#endif
139
Note: See TracBrowser for help on using the repository browser.