Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceIndexedTriangle.h
1 /*
2  *      ICE / OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose, 
10 including commercial applications, and to alter it and redistribute it freely, 
11 subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
16 */
17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 /**
19  *      Contains a handy indexed triangle class.
20  *      \file           IceIndexedTriangle.h
21  *      \author         Pierre Terdiman
22  *      \date           January, 17, 2000
23  */
24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 // Include Guard
28 #ifndef __ICEINDEXEDTRIANGLE_H__
29 #define __ICEINDEXEDTRIANGLE_H__
30
31         // Forward declarations
32         enum CubeIndex;
33
34         // An indexed triangle class.
35         class ICEMATHS_API IndexedTriangle
36         {
37                 public:
38                 //! Constructor
39                 inline_                                 IndexedTriangle()                                                                       {}
40                 //! Constructor
41                 inline_                                 IndexedTriangle(udword r0, udword r1, udword r2)        { mVRef[0]=r0; mVRef[1]=r1; mVRef[2]=r2; }
42                 //! Copy constructor
43                 inline_                                 IndexedTriangle(const IndexedTriangle& triangle)
44                                                                 {
45                                                                         mVRef[0] = triangle.mVRef[0];
46                                                                         mVRef[1] = triangle.mVRef[1];
47                                                                         mVRef[2] = triangle.mVRef[2];
48                                                                 }
49                 //! Destructor
50                 inline_                                 ~IndexedTriangle()                                                                      {}
51                 //! Vertex-references
52                                 udword                  mVRef[3];
53
54                 // Methods
55                                 void                    Flip();
56                                 float                   Area(const Point* verts)                                                                                        const;
57                                 float                   Perimeter(const Point* verts)                                                                           const;
58                                 float                   Compacity(const Point* verts)                                                                           const;
59                                 void                    Normal(const Point* verts, Point& normal)                                                       const;
60                                 void                    DenormalizedNormal(const Point* verts, Point& normal)                           const;
61                                 void                    Center(const Point* verts, Point& center)                                                       const;
62                                 void                    CenteredNormal(const Point* verts, Point& normal)                                       const;
63                                 void                    RandomPoint(const Point* verts, Point& random)                                          const;
64                                 bool                    IsVisible(const Point* verts, const Point& source)                                      const;
65                                 bool                    BackfaceCulling(const Point* verts, const Point& source)                        const;
66                                 float                   ComputeOcclusionPotential(const Point* verts, const Point& view)        const;
67                                 bool                    ReplaceVertex(udword oldref, udword newref);
68                                 bool                    IsDegenerate()                                                                                                          const;
69                                 bool                    HasVertex(udword ref)                                                                                           const;
70                                 bool                    HasVertex(udword ref, udword* index)                                                            const;
71                                 ubyte                   FindEdge(udword vref0, udword vref1)                                                            const;
72                                 udword                  OppositeVertex(udword vref0, udword vref1)                                                      const;
73                 inline_ udword                  OppositeVertex(ubyte edgenb)                                                                            const   { return mVRef[2-edgenb];       }
74                                 void                    GetVRefs(ubyte edgenb, udword& vref0, udword& vref1, udword& vref2)     const;
75                                 float                   MinEdgeLength(const Point* verts)                                                                       const;
76                                 float                   MaxEdgeLength(const Point* verts)                                                                       const;
77                                 void                    ComputePoint(const Point* verts, float u, float v, Point& pt, udword* nearvtx=null)     const;
78                                 float                   Angle(const IndexedTriangle& tri, const Point* verts)                           const;
79                 inline_ Plane                   PlaneEquation(const Point* verts)                                                                       const   { return Plane(verts[mVRef[0]], verts[mVRef[1]], verts[mVRef[2]]);      }
80                                 bool                    Equal(const IndexedTriangle& tri)                                                                       const;
81                                 CubeIndex               ComputeCubeIndex(const Point* verts)                                                            const;
82         };
83
84 #endif // __ICEINDEXEDTRIANGLE_H__