RavEngine
Loading...
Searching...
No Matches
PxTriangle.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_TRIANGLE_H
30#define PX_TRIANGLE_H
35#include "common/PxPhysXCommonConfig.h"
36#include "foundation/PxVec3.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
42
47{
48 public:
53
61 PX_FORCE_INLINE PxTriangle(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2)
62 {
63 verts[0] = p0;
64 verts[1] = p1;
65 verts[2] = p2;
66 }
67
74 {
75 verts[0] = triangle.verts[0];
76 verts[1] = triangle.verts[1];
77 verts[2] = triangle.verts[2];
78 }
79
84
88 PX_FORCE_INLINE void operator=(const PxTriangle& triangle)
89 {
90 verts[0] = triangle.verts[0];
91 verts[1] = triangle.verts[1];
92 verts[2] = triangle.verts[2];
93 }
94
100 PX_FORCE_INLINE void normal(PxVec3& _normal) const
101 {
102 _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
103 _normal.normalize();
104 }
105
112 {
113 _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]);
114 }
115
121 PX_FORCE_INLINE PxReal area() const
122 {
123 const PxVec3& p0 = verts[0];
124 const PxVec3& p1 = verts[1];
125 const PxVec3& p2 = verts[2];
126 return ((p0 - p1).cross(p0 - p2)).magnitude() * 0.5f;
127 }
128
132 PX_FORCE_INLINE PxVec3 pointFromUV(PxReal u, PxReal v) const
133 {
134 return (1.0f-u-v)*verts[0] + u*verts[1] + v*verts[2];
135 }
136
141};
142
145{
146public:
149 PxU32 padding;
150};
151
152#if !PX_DOXYGEN
153}
154#endif
155
157#endif
A padded version of PxTriangle, to safely load its data using SIMD.
Definition PxTriangle.h:145
Triangle class.
Definition PxTriangle.h:47
PX_FORCE_INLINE PxReal area() const
Compute the area of the triangle.
Definition PxTriangle.h:121
PX_FORCE_INLINE PxTriangle(const PxTriangle &triangle)
Copy constructor.
Definition PxTriangle.h:73
PX_FORCE_INLINE PxTriangle(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2)
Constructor.
Definition PxTriangle.h:61
PX_FORCE_INLINE PxVec3 pointFromUV(PxReal u, PxReal v) const
Definition PxTriangle.h:132
PX_FORCE_INLINE ~PxTriangle()
Destructor.
Definition PxTriangle.h:83
PX_FORCE_INLINE void operator=(const PxTriangle &triangle)
Assignment operator.
Definition PxTriangle.h:88
PxVec3 verts[3]
Array of Vertices.
Definition PxTriangle.h:140
PX_FORCE_INLINE PxTriangle()
Constructor.
Definition PxTriangle.h:52
PX_FORCE_INLINE void denormalizedNormal(PxVec3 &_normal) const
Compute the unnormalized normal of the triangle.
Definition PxTriangle.h:111
PX_FORCE_INLINE void normal(PxVec3 &_normal) const
Compute the normal of the Triangle.
Definition PxTriangle.h:100
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float normalize()
normalizes the vector in place
Definition PxVec3.h:300
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
returns the magnitude
Definition PxVec3.h:183
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39