PxTriangle.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 
31 #ifndef PX_PHYSICS_GEOMUTILS_PX_TRIANGLE
32 #define PX_PHYSICS_GEOMUTILS_PX_TRIANGLE
33 
38 #include "foundation/PxVec3.h"
39 
40 #if !PX_DOXYGEN
41 namespace physx
42 {
43 #endif
44 
49 {
50  public:
55 
63  PX_FORCE_INLINE PxTriangle(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2)
64  {
65  verts[0] = p0;
66  verts[1] = p1;
67  verts[2] = p2;
68  }
69 
76  {
77  verts[0] = triangle.verts[0];
78  verts[1] = triangle.verts[1];
79  verts[2] = triangle.verts[2];
80  }
81 
86 
90  PX_FORCE_INLINE void operator=(const PxTriangle& triangle)
91  {
92  verts[0] = triangle.verts[0];
93  verts[1] = triangle.verts[1];
94  verts[2] = triangle.verts[2];
95  }
96 
102  PX_FORCE_INLINE void normal(PxVec3& _normal) const
103  {
104  _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
105  _normal.normalize();
106  }
107 
114  {
115  _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
116  }
117 
124  {
125  const PxVec3& p0 = verts[0];
126  const PxVec3& p1 = verts[1];
127  const PxVec3& p2 = verts[2];
128  return ((p0 - p1).cross(p0 - p2)).magnitude() * 0.5f;
129  }
130 
134  PxVec3 pointFromUV(PxReal u, PxReal v) const { return (1.0f-u-v)*verts[0] + u*verts[1] + v*verts[2]; }
135 
139  PxVec3 verts[3];
140 
141 };
142 
143 
144 #if !PX_DOXYGEN
145 }
146 #endif
147 
149 #endif
Definition: GuContactBuffer.h:37
PX_FORCE_INLINE void operator=(const PxTriangle &triangle)
Assignment operator.
Definition: PxTriangle.h:90
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
float PxReal
Definition: PxSimpleTypes.h:78
PX_FORCE_INLINE PxTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2)
Constructor.
Definition: PxTriangle.h:63
PX_FORCE_INLINE PxTriangle()
Constructor.
Definition: PxTriangle.h:54
PX_FORCE_INLINE PxTriangle(const PxTriangle &triangle)
Copy constructor.
Definition: PxTriangle.h:75
PxVec3 verts[3]
Array of Vertices.
Definition: PxTriangle.h:139
PX_FORCE_INLINE PxReal area() const
Compute the area of the triangle.
Definition: PxTriangle.h:123
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
returns the magnitude
Definition: PxVec3.h:183
PX_FORCE_INLINE ~PxTriangle()
Destructor.
Definition: PxTriangle.h:85
PX_CUDA_CALLABLE PX_FORCE_INLINE float normalize()
normalizes the vector in place
Definition: PxVec3.h:300
PX_FORCE_INLINE void denormalizedNormal(PxVec3 &_normal) const
Compute the unnormalized normal of the triangle.
Definition: PxTriangle.h:113
PxVec3 pointFromUV(PxReal u, PxReal v) const
Definition: PxTriangle.h:134
Triangle class.
Definition: PxTriangle.h:48
PX_FORCE_INLINE void normal(PxVec3 &_normal) const
Compute the normal of the Triangle.
Definition: PxTriangle.h:102
3 Element vector class.
Definition: PxVec3.h:49