PxMeshScale.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_NX_MESHSCALE
32 #define PX_PHYSICS_NX_MESHSCALE
33 
38 #include "foundation/PxMat33.h"
39 #include "foundation/PxAssert.h"
40 
43 #define PX_MESH_SCALE_MIN 1e-6f
44 
47 #define PX_MESH_SCALE_MAX 1e6f
48 
49 #if !PX_DOXYGEN
50 namespace physx
51 {
52 #endif
53 
69 {
70 //= ATTENTION! =====================================================================================
71 // Changing the data layout of this class breaks the binary serialization format. See comments for
72 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
73 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
74 // accordingly.
75 //==================================================================================================
76 public:
81  {
82  }
83 
87  explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(PxReal r): scale(r), rotation(PxIdentity)
88  {
89  }
90 
95  {
96  scale = s;
97  rotation = PxQuat(PxIdentity);
98  }
99 
104  {
105  PX_ASSERT(r.isUnit());
106  scale = s;
107  rotation = r;
108  }
109 
110 
115  {
116  return (scale.x == 1.0f && scale.y == 1.0f && scale.z == 1.0f);
117  }
118 
123  {
124  return PxMeshScale(PxVec3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z), rotation);
125  }
126 
131  {
132  PxMat33 rot(rotation);
133  PxMat33 trans = rot.getTranspose();
134  trans.column0 *= scale[0];
135  trans.column1 *= scale[1];
136  trans.column2 *= scale[2];
137  return trans * rot;
138  }
139 
144  {
145  return (scale.x * scale.y * scale.z < 0.0f);
146  }
147 
148  PxVec3 transform(const PxVec3& v) const
149  {
150  return rotation.rotateInv(scale.multiply(rotation.rotate(v)));
151  }
152 
154  {
155  PxVec3 absXYZ = scale.abs();
156  return (absXYZ.maxElement() <= PX_MESH_SCALE_MAX) && (absXYZ.minElement() >= PX_MESH_SCALE_MIN);
157  }
158 
159  bool isValidForConvexMesh() const
160  {
161  return (scale.maxElement() <= PX_MESH_SCALE_MAX) && (scale.minElement() >= PX_MESH_SCALE_MIN);
162  }
163 
166 
167 
168 };
169 
170 #if !PX_DOXYGEN
171 } // namespace physx
172 #endif
173 
175 #endif
Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_FORCE_INLINE float maxElement() const
returns MAX(x, y, z);
Definition: PxVec3.h:368
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(PxReal r)
Constructor from scalar.
Definition: PxMeshScale.h:87
#define PX_MESH_SCALE_MIN
Minimum allowed absolute magnitude for each of mesh scale&#39;s components (x,y,z).
Definition: PxMeshScale.h:43
Definition: Px.h:84
A class expressing a nonuniform scaling transformation.
Definition: PxMeshScale.h:68
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(const PxVec3 &s)
Constructor to initialize to arbitrary scale and identity scale rotation.
Definition: PxMeshScale.h:94
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition: PxQuat.h:49
float PxReal
Definition: PxSimpleTypes.h:78
#define PX_MESH_SCALE_MAX
Maximum allowed absolute magnitude for each of mesh scale&#39;s components (x,y,z).
Definition: PxMeshScale.h:47
bool isValidForTriangleMesh() const
Definition: PxMeshScale.h:153
PxQuat rotation
The orientation of the scaling axes.
Definition: PxMeshScale.h:165
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale getInverse() const
Returns the inverse of this scaling transformation.
Definition: PxMeshScale.h:122
PxVec3 scale
A nonuniform scaling.
Definition: PxMeshScale.h:164
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isIdentity() const
Returns true if the scaling is an identity transformation.
Definition: PxMeshScale.h:114
PX_CUDA_CALLABLE PX_FORCE_INLINE float minElement() const
returns MIN(x, y, z);
Definition: PxVec3.h:352
bool isValidForConvexMesh() const
Definition: PxMeshScale.h:159
PX_CUDA_CALLABLE bool isUnit() const
returns true if finite and magnitude is close to unit
Definition: PxQuat.h:132
PxVec3 column2
Definition: PxMat33.h:353
3x3 matrix class
Definition: PxMat33.h:90
PxVec3 column0
Definition: PxMat33.h:353
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 abs() const
returns absolute values of components;
Definition: PxVec3.h:376
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(const PxVec3 &s, const PxQuat &r)
Constructor to initialize to arbitrary scaling.
Definition: PxMeshScale.h:103
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale()
Constructor initializes to identity scale.
Definition: PxMeshScale.h:80
#define PX_ASSERT(exp)
Definition: PxAssert.h:61
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNegativeDeterminant() const
Returns true if combination of negative scale components will cause the triangle normal to flip...
Definition: PxMeshScale.h:143
PxVec3 transform(const PxVec3 &v) const
Definition: PxMeshScale.h:148
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 getTranspose() const
Get transposed matrix.
Definition: PxMat33.h:190
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33 toMat33() const
Converts this transformation to a 3x3 matrix representation.
Definition: PxMeshScale.h:130
PxVec3 column1
Definition: PxMat33.h:353
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:473
3 Element vector class.
Definition: PxVec3.h:49