RavEngine
Loading...
Searching...
No Matches
GuGJKType.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_GJKTYPE_H
30#define GU_GJKTYPE_H
31
32#include "GuVecConvex.h"
33#include "foundation/PxVecTransform.h"
34
35namespace physx
36{
37namespace Gu
38{
39 class ConvexHullV;
40 class ConvexHullNoScaleV;
41 class BoxV;
42
43 template <typename Convex> struct ConvexGeom { typedef Convex Type; };
44 template <> struct ConvexGeom<ConvexHullV> { typedef ConvexHullV Type; };
45 template <> struct ConvexGeom<ConvexHullNoScaleV> { typedef ConvexHullNoScaleV Type; };
46 template <> struct ConvexGeom<BoxV> { typedef BoxV Type; };
47
48 struct GjkConvex
49 {
50 GjkConvex(const ConvexV& convex) : mConvex(convex) {}
51 virtual ~GjkConvex() {}
52
53 PX_FORCE_INLINE aos::FloatV getMinMargin() const { return mConvex.getMinMargin(); }
54 PX_FORCE_INLINE aos::BoolV isMarginEqRadius() const { return mConvex.isMarginEqRadius(); }
55 PX_FORCE_INLINE bool getMarginIsRadius() const { return mConvex.getMarginIsRadius(); }
56 PX_FORCE_INLINE aos::FloatV getMargin() const { return mConvex.getMargin(); }
57
58 template <typename Convex>
59 PX_FORCE_INLINE const Convex& getConvex() const { return static_cast<const Convex&>(mConvex); }
60
61 virtual aos::Vec3V supportPoint(const PxI32 index) const { return doVirtualSupportPoint(index); }
62 virtual aos::Vec3V support(const aos::Vec3VArg v) const { return doVirtualSupport(v); }
63 virtual aos::Vec3V support(const aos::Vec3VArg dir, PxI32& index) const { return doVirtualSupport(dir, index); }
64 virtual aos::FloatV getSweepMargin() const { return doVirtualGetSweepMargin(); }
65 virtual aos::Vec3V getCenter() const = 0;
66
67 protected:
68 const ConvexV& mConvex;
69
70 private:
71 // PT: following functions call the v-table. I think this curious pattern is needed for the de-virtualization
72 // approach used in the GJK code, combined with the GuGJKTest file that is only used externally.
73 aos::Vec3V doVirtualSupportPoint(const PxI32 index) const { return supportPoint(index); }
74 aos::Vec3V doVirtualSupport(const aos::Vec3VArg v) const { return support(v); }
75 aos::Vec3V doVirtualSupport(const aos::Vec3VArg dir, PxI32& index) const { return support(dir, index); }
76 aos::FloatV doVirtualGetSweepMargin() const { return getSweepMargin(); }
77
78 //PX_NOCOPY(GjkConvex)
79 GjkConvex& operator = (const GjkConvex&);
80 };
81
82 template <typename Convex>
83 struct LocalConvex : public GjkConvex
84 {
85 LocalConvex(const Convex& convex) : GjkConvex(convex){}
86
87 // PT: I think we omit the virtual on purpose here, for the de-virtualization approach, i.e. the code calls these
88 // functions directly (bypassing the v-table). In fact I think we don't need virtuals at all here, it's probably
89 // only for external cases and/or cases where we want to reduce code size.
90 // The mix of virtual/force-inline/inline below is confusing/unclear.
91
92 // GjkConvex
93 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index) const { return getConvex<Convex>().supportPoint(index); }
94 aos::Vec3V support(const aos::Vec3VArg v) const { return getConvex<Convex>().supportLocal(v); }
95 aos::Vec3V support(const aos::Vec3VArg dir, PxI32& index) const { return getConvex<Convex>().supportLocal(dir, index); }
96 PX_INLINE aos::FloatV getSweepMargin() const { return getConvex<Convex>().getSweepMargin(); }
97 virtual aos::Vec3V getCenter() const { return getConvex<Convex>().getCenter(); }
98 //~GjkConvex
99
100 //ML: we can't force inline function, otherwise win modern will throw compiler error
102 {
103 return LocalConvex<typename ConvexGeom<Convex>::Type >(static_cast<const typename ConvexGeom<Convex>::Type&>(GjkConvex::mConvex));
104 }
105
107
108 typedef Convex Type;
109
110 private:
111 //PX_NOCOPY(LocalConvex<Convex>)
112 LocalConvex<Convex>& operator = (const LocalConvex<Convex>&);
113 };
114
115 template <typename Convex>
116 struct RelativeConvex : public GjkConvex
117 {
118 RelativeConvex(const Convex& convex, const aos::PxMatTransformV& aToB) : GjkConvex(convex), mAToB(aToB), mAToBTransposed(aToB)
119 {
120 aos::V3Transpose(mAToBTransposed.rot.col0, mAToBTransposed.rot.col1, mAToBTransposed.rot.col2);
121 }
122
123 // GjkConvex
124 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index) const { return mAToB.transform(getConvex<Convex>().supportPoint(index)); }
125 aos::Vec3V support(const aos::Vec3VArg v) const { return getConvex<Convex>().supportRelative(v, mAToB, mAToBTransposed); }
126 aos::Vec3V support(const aos::Vec3VArg dir, PxI32& index) const { return getConvex<Convex>().supportRelative(dir, mAToB, mAToBTransposed, index); }
127 PX_INLINE aos::FloatV getSweepMargin() const { return getConvex<Convex>().getSweepMargin(); }
128 virtual aos::Vec3V getCenter() const { return mAToB.transform(getConvex<Convex>().getCenter()); }
129 //~GjkConvex
130
131 PX_FORCE_INLINE const aos::PxMatTransformV& getRelativeTransform() const { return mAToB; }
132
133 //ML: we can't force inline function, otherwise win modern will throw compiler error
135 {
136 return RelativeConvex<typename ConvexGeom<Convex>::Type >(static_cast<const typename ConvexGeom<Convex>::Type&>(GjkConvex::mConvex), mAToB);
137 }
138
140
141 typedef Convex Type;
142
143 private:
144 //PX_NOCOPY(RelativeConvex<Convex>)
146
147 const aos::PxMatTransformV& mAToB;
148 aos::PxMatTransformV mAToBTransposed; // PT: precomputed mAToB transpose (because 'rotate' is faster than 'rotateInv')
149 };
150
151}
152}
153
154#endif
Definition GuVecBox.h:102
Definition GuVecConvexHullNoScale.h:41
Definition GuVecConvexHull.h:184
Definition GuVecConvex.h:58
Definition PxVecTransform.h:200
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuGJKType.h:43
Definition GuGJKType.h:49
Definition GuGJKType.h:84
Definition GuGJKType.h:117
Definition PxVecMathAoSScalar.h:90
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77