// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #ifndef PX_ALIGNED_QUAT_H #define PX_ALIGNED_QUAT_H #include "vector_types.h" #include "foundation/PxVec3.h" #include "foundation/PxQuat.h" #include "cutil_math.h" #include "foundation/PxQuat.h" #include "foundation/PxAssert.h" #if !PX_DOXYGEN namespace physx { #endif class PxAlignedMat33; /** \brief This is a quaternion class. For more information on quaternion mathematics consult a mathematics source on complex numbers. */ PX_ALIGN_PREFIX(16) class PxAlignedQuat { public: /** \brief Default constructor, does not do any initialization. */ PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat() { } //! identity constructor PX_CUDA_CALLABLE PX_INLINE PxAlignedQuat(PxIDENTITY r) : q(make_float4(0.0f, 0.0f, 0.0f, 1.0f)) { PX_UNUSED(r); } /** \brief Constructor from a scalar: sets the real part w to the scalar value, and the imaginary parts (x,y,z) to zero */ explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat(PxReal r) : q(make_float4(0.0f, 0.0f, 0.0f, r)) { } /** \brief Constructor. Take note of the order of the elements! */ PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat(PxReal nx, PxReal ny, PxReal nz, PxReal nw) : q(make_float4(nx, ny, nz, nw)) {} PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat(const PxQuat& q0) : q(make_float4(q0.x, q0.y, q0.z, q0.w)) {} /** \brief Creates from angle-axis representation. Axis must be normalized! Angle is in radians! Unit: Radians */ PX_CUDA_CALLABLE PX_INLINE PxAlignedQuat(PxReal angleRadians, const PxVec3& unitAxis) { PX_ASSERT(PxAbs(1.0f-unitAxis.magnitude())<1e-3f); const PxReal a = angleRadians * 0.5f; const PxReal s = PxSin(a); q.w = PxCos(a); q.x = unitAxis.x * s; q.y = unitAxis.y * s; q.z = unitAxis.z * s; } PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat(const float4 v) : q(v) {} /** \brief Copy ctor. */ PX_CUDA_CALLABLE PX_FORCE_INLINE PxAlignedQuat(const PxAlignedQuat& v): q(v.q) {} /** \brief Creates from orientation matrix. \param[in] m Rotation matrix to extract quaternion from. */ PX_CUDA_CALLABLE PX_INLINE explicit PxAlignedQuat(const PxAlignedMat33& m); /* defined in PxAlignedMat33.h */ /** \brief returns true if all elements are finite (not NAN or INF, etc.) */ PX_CUDA_CALLABLE bool isFinite() const { return PxIsFinite(q.x) && PxIsFinite(q.y) && PxIsFinite(q.z) && PxIsFinite(q.w); } /** \brief returns true if finite and magnitude is close to unit */ PX_CUDA_CALLABLE bool isUnit() const { const PxReal unitTolerance = 1e-4f; return isFinite() && PxAbs(magnitude()-1)