1 | /* |
2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
3 | * |
4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
5 | * and proprietary rights in and to this software, related documentation |
6 | * and any modifications thereto. Any use, reproduction, disclosure or |
7 | * distribution of this software and related documentation without an express |
8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
9 | */ |
10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
12 | |
13 | |
14 | #ifndef PX_PHYSICS_NX_MESHSCALE |
15 | #define PX_PHYSICS_NX_MESHSCALE |
16 | /** \addtogroup geomutils |
17 | @{ |
18 | */ |
19 | |
20 | #include "common/PxPhysXCommonConfig.h" |
21 | #include "foundation/PxMat33.h" |
22 | |
23 | #ifndef PX_DOXYGEN |
24 | namespace physx |
25 | { |
26 | #endif |
27 | |
28 | /** |
29 | \brief A class expressing a nonuniform scaling transformation. |
30 | |
31 | The scaling is along arbitrary axes that are specified by PxMeshScale::rotation. |
32 | |
33 | \note Currently only positive scale values are supported. |
34 | |
35 | @see PxConvexMeshGeometry PxTriangleMeshGeometry |
36 | */ |
37 | class PxMeshScale |
38 | { |
39 | //= ATTENTION! ===================================================================================== |
40 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
41 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
42 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
43 | // accordingly. |
44 | //================================================================================================== |
45 | public: |
46 | /** |
47 | \brief Constructor initializes to identity scale. |
48 | */ |
49 | PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(): scale(1.0f), rotation(PxIdentity) |
50 | { |
51 | } |
52 | |
53 | /** |
54 | \brief Constructor from scalar. |
55 | */ |
56 | explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(PxReal r): scale(r), rotation(PxIdentity) |
57 | { |
58 | } |
59 | |
60 | /** |
61 | \brief Constructor to initialize to arbitrary scaling. |
62 | */ |
63 | PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale(const PxVec3& s, const PxQuat& r) |
64 | { |
65 | PX_ASSERT(r.isUnit()); |
66 | scale = s; |
67 | rotation = r; |
68 | } |
69 | |
70 | |
71 | /** |
72 | \brief Returns true if the scaling is an identity transformation. |
73 | */ |
74 | PX_CUDA_CALLABLE PX_FORCE_INLINE bool isIdentity() const |
75 | { |
76 | return (scale.x == 1.0f && scale.y == 1.0f && scale.z == 1.0f); |
77 | } |
78 | |
79 | /** |
80 | \brief Returns the inverse of this scaling transformation. |
81 | */ |
82 | PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale getInverse() const |
83 | { |
84 | return PxMeshScale(PxVec3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z), rotation); |
85 | } |
86 | |
87 | /** |
88 | \deprecated |
89 | \brief Returns the identity scaling transformation. |
90 | */ |
91 | PX_DEPRECATED static PX_CUDA_CALLABLE PX_FORCE_INLINE PxMeshScale createIdentity() |
92 | { |
93 | return PxMeshScale(1.0f); |
94 | } |
95 | |
96 | /** |
97 | \brief Converts this transformation to a 3x3 matrix representation. |
98 | */ |
99 | PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33 toMat33() const |
100 | { |
101 | PxMat33 rot(rotation); |
102 | PxMat33 trans = rot.getTranspose(); |
103 | trans.column0 *= scale[0]; |
104 | trans.column1 *= scale[1]; |
105 | trans.column2 *= scale[2]; |
106 | return trans * rot; |
107 | } |
108 | |
109 | |
110 | PxVec3 transform(const PxVec3& v) const |
111 | { |
112 | return rotation.rotateInv(scale.multiply(rotation.rotate(v))); |
113 | } |
114 | |
115 | PxVec3 scale; //!< A nonuniform scaling |
116 | PxQuat rotation; //!< The orientation of the scaling axes |
117 | |
118 | |
119 | }; |
120 | |
121 | #ifndef PX_DOXYGEN |
122 | } // namespace physx |
123 | #endif |
124 | |
125 | /** @} */ |
126 | #endif |
127 | |