RavEngine
Loading...
Searching...
No Matches
GuBoxConversion.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 GU_BOX_CONVERSION_H
30#define GU_BOX_CONVERSION_H
31
32#include "GuBox.h"
33#include "foundation/PxMathUtils.h"
34#include "foundation/PxMat34.h"
35#include "foundation/PxVecMath.h"
36
37namespace physx
38{
39 // PT: builds rot from quat. WARNING: writes 4 bytes after 'dst.rot'.
40 PX_FORCE_INLINE void buildFrom(Gu::Box& dst, const PxQuat& q)
41 {
42 using namespace aos;
43 const QuatV qV = V4LoadU(&q.x);
44 Vec3V column0, column1, column2;
45 QuatGetMat33V(qV, column0, column1, column2);
46 // PT: TODO: investigate if these overlapping stores are a problem
47 V4StoreU(Vec4V_From_Vec3V(column0), &dst.rot.column0.x);
48 V4StoreU(Vec4V_From_Vec3V(column1), &dst.rot.column1.x);
49 V4StoreU(Vec4V_From_Vec3V(column2), &dst.rot.column2.x);
50 }
51
52 PX_FORCE_INLINE void buildFrom(Gu::Box& dst, const PxVec3& center, const PxVec3& extents, const PxQuat& q)
53 {
54 using namespace aos;
55 // PT: writes 4 bytes after 'rot' but it's safe since we then write 'center' just afterwards
56 buildFrom(dst, q);
57 dst.center = center;
58 dst.extents = extents;
59 }
60
61 PX_FORCE_INLINE void buildMatrixFromBox(PxMat34& mat34, const Gu::Box& box)
62 {
63 mat34.m = box.rot;
64 mat34.p = box.center;
65 }
66
67 // SD: function is now the same as FastVertex2ShapeScaling::transformQueryBounds
68 // PT: lots of LHS in that one. TODO: revisit...
69 PX_INLINE Gu::Box transform(const PxMat34& transfo, const Gu::Box& box)
70 {
71 Gu::Box ret;
72 PxMat33& obbBasis = ret.rot;
73
74 obbBasis.column0 = transfo.rotate(box.rot.column0 * box.extents.x);
75 obbBasis.column1 = transfo.rotate(box.rot.column1 * box.extents.y);
76 obbBasis.column2 = transfo.rotate(box.rot.column2 * box.extents.z);
77
78 ret.center = transfo.transform(box.center);
79 ret.extents = PxOptimizeBoundingBox(obbBasis);
80 return ret;
81 }
82
83 PX_INLINE Gu::Box transformBoxOrthonormal(const Gu::Box& box, const PxTransform& t)
84 {
85 Gu::Box ret;
86 PxMat33& obbBasis = ret.rot;
87 obbBasis.column0 = t.rotate(box.rot.column0);
88 obbBasis.column1 = t.rotate(box.rot.column1);
89 obbBasis.column2 = t.rotate(box.rot.column2);
90 ret.center = t.transform(box.center);
91 ret.extents = box.extents;
92 return ret;
93 }
94
100 PX_INLINE void rotate(const Gu::Box& src, const PxMat34& mtx, Gu::Box& obb)
101 {
102 // The extents remain constant
103 obb.extents = src.extents;
104 // The center gets x-formed
105 obb.center = mtx.transform(src.center);
106 // Combine rotations
107 obb.rot = mtx.m * src.rot;
108 }
109
110// PT: TODO: move this to a better place
111 PX_FORCE_INLINE void getInverse(PxMat33& dstRot, PxVec3& dstTrans, const PxMat33& srcRot, const PxVec3& srcTrans)
112 {
113 const PxMat33 invRot = srcRot.getInverse();
114 dstTrans = invRot.transform(-srcTrans);
115 dstRot = invRot;
116 }
117
118}
119
120#endif
Represents an oriented bounding box.
Definition GuBox.h:72
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3T< Type > transform(const PxVec3T< Type > &other) const
Transform vector by matrix, equal to v' = M*v.
Definition PxMat33.h:347
PX_CUDA_CALLABLE PX_INLINE const PxMat33T getInverse() const
Get the real inverse.
Definition PxMat33.h:218
Definition PxMat34.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > transform(const PxVec3T< Type > &other) const
Transform point by matrix.
Definition PxMat34.h:216
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
transform(pattern)
Definition docopt.py:72
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_INLINE void rotate(const Gu::Box &src, const PxMat34 &mtx, Gu::Box &obb)
recomputes the OBB after an arbitrary transform by a 4x4 matrix.
Definition GuBoxConversion.h:100
PX_FOUNDATION_API PxVec3 PxOptimizeBoundingBox(PxMat33 &basis)
computes a oriented bounding box around the scaled basis.
Definition FdMathUtils.cpp:140