1 | #ifndef NX_COLLISION_NXTRIANGLE
|
---|
2 | #define NX_COLLISION_NXTRIANGLE
|
---|
3 | /*----------------------------------------------------------------------------*\
|
---|
4 | |
|
---|
5 | | Public Interface to NovodeX Technology
|
---|
6 | |
|
---|
7 | | www.novodex.com
|
---|
8 | |
|
---|
9 | \*----------------------------------------------------------------------------*/
|
---|
10 | /** \addtogroup physics
|
---|
11 | @{
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "Nxp.h"
|
---|
15 |
|
---|
16 | #define NX_INV3 0.33333333333333333333f //!< 1/3
|
---|
17 |
|
---|
18 | /**
|
---|
19 | \brief Triangle class.
|
---|
20 |
|
---|
21 | @see NxTriangleMesh NxTriangleMeshDesc
|
---|
22 | */
|
---|
23 | class NxTriangle
|
---|
24 | {
|
---|
25 | public:
|
---|
26 | /**
|
---|
27 | \brief Constructor
|
---|
28 | */
|
---|
29 | NX_INLINE NxTriangle()
|
---|
30 | {
|
---|
31 | }
|
---|
32 | /**
|
---|
33 | \brief Constructor
|
---|
34 |
|
---|
35 | \param[in] p0 Point 0
|
---|
36 | \param[in] p1 Point 1
|
---|
37 | \param[in] p2 Point 2
|
---|
38 | */
|
---|
39 | NX_INLINE NxTriangle(const NxVec3& p0, const NxVec3& p1, const NxVec3& p2)
|
---|
40 | {
|
---|
41 | verts[0] = p0;
|
---|
42 | verts[1] = p1;
|
---|
43 | verts[2] = p2;
|
---|
44 | }
|
---|
45 | /**
|
---|
46 | \brief Copy constructor
|
---|
47 |
|
---|
48 | \param[in] triangle Tri to copy
|
---|
49 | */
|
---|
50 | NX_INLINE NxTriangle(const NxTriangle& triangle)
|
---|
51 | {
|
---|
52 | verts[0] = triangle.verts[0];
|
---|
53 | verts[1] = triangle.verts[1];
|
---|
54 | verts[2] = triangle.verts[2];
|
---|
55 | }
|
---|
56 | /**
|
---|
57 | \brief Destructor
|
---|
58 | */
|
---|
59 | NX_INLINE ~NxTriangle()
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | \brief Array of Vertices.
|
---|
65 | */
|
---|
66 | NxVec3 verts[3];
|
---|
67 |
|
---|
68 | /**
|
---|
69 | \brief Compute the centre of the NxTriangle.
|
---|
70 |
|
---|
71 | \param[out] center Retrieve centre(average) point of triangle.
|
---|
72 | */
|
---|
73 | NX_INLINE void center(NxVec3& center) const
|
---|
74 | {
|
---|
75 | center = (verts[0] + verts[1] + verts[2])*NX_INV3;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | \brief Compute the normal of the NxTriangle.
|
---|
80 |
|
---|
81 | \param[out] _normal Triangle normal.
|
---|
82 | */
|
---|
83 | NX_INLINE void normal(NxVec3& _normal) const
|
---|
84 | {
|
---|
85 | _normal = (verts[1]-verts[0])^(verts[2]-verts[0]);
|
---|
86 | _normal.normalize();
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | \brief Makes a fat triangle
|
---|
91 |
|
---|
92 | \param[in] fatCoeff Amount to inflate triangle by.
|
---|
93 | \param[in] constantBorder True - Add same width independant of tri size. False - Add bigger borders to biggers triangles.
|
---|
94 | */
|
---|
95 | NX_INLINE void inflate(float fatCoeff, bool constantBorder)
|
---|
96 | {
|
---|
97 | // Compute triangle center
|
---|
98 | NxVec3 triangleCenter;
|
---|
99 | center(triangleCenter);
|
---|
100 |
|
---|
101 | // Don't normalize?
|
---|
102 | // Normalize => add a constant border, regardless of triangle size
|
---|
103 | // Don't => add more to big triangles
|
---|
104 | for(unsigned i=0;i<3;i++)
|
---|
105 | {
|
---|
106 | NxVec3 v = verts[i] - triangleCenter;
|
---|
107 |
|
---|
108 | if(constantBorder) v.normalize();
|
---|
109 |
|
---|
110 | verts[i] += v * fatCoeff;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | };
|
---|
114 |
|
---|
115 | /** @} */
|
---|
116 | #endif
|
---|
117 |
|
---|
118 |
|
---|
119 | //AGCOPYRIGHTBEGIN
|
---|
120 | ///////////////////////////////////////////////////////////////////////////
|
---|
121 | // Copyright © 2005 AGEIA Technologies.
|
---|
122 | // All rights reserved. www.ageia.com
|
---|
123 | ///////////////////////////////////////////////////////////////////////////
|
---|
124 | //AGCOPYRIGHTEND
|
---|
125 |
|
---|