| 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-2021 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 PXS_CONTACTMANAGER_H |
| 32 | #define PXS_CONTACTMANAGER_H |
| 33 | |
| 34 | #include "PxvConfig.h" |
| 35 | #include "PxcNpWorkUnit.h" |
| 36 | |
| 37 | namespace physx |
| 38 | { |
| 39 | |
| 40 | class PxsContext; |
| 41 | class PxsRigidBody; |
| 42 | struct PxsCCDBody; |
| 43 | class PxsMaterialManager; |
| 44 | struct PxsCCDShape; |
| 45 | |
| 46 | namespace Dy |
| 47 | { |
| 48 | class DynamicsContext; |
| 49 | } |
| 50 | |
| 51 | namespace Sc |
| 52 | { |
| 53 | class ShapeInteraction; |
| 54 | } |
| 55 | |
| 56 | enum PxsPairVisColor |
| 57 | { |
| 58 | |
| 59 | eVIS_COLOR_SWEPTINTEGRATE_OFF = 0x000000, |
| 60 | eVIS_COLOR_SWEPTINTEGRATE_SLOW = 0x404040, |
| 61 | eVIS_COLOR_SWEPTINTEGRATE_CLEAR = 0x007f00, |
| 62 | eVIS_COLOR_SWEPTINTEGRATE_IMPACT = 0x1680ff, |
| 63 | eVIS_COLOR_SWEPTINTEGRATE_FAIL = 0x0000ff |
| 64 | |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | \brief Additional header structure for CCD contact data stream. |
| 70 | */ |
| 71 | struct |
| 72 | { |
| 73 | /** |
| 74 | \brief Stream for next collision. The same pair can collide multiple times during multiple CCD passes. |
| 75 | */ |
| 76 | PxsCCDContactHeader* ; //4 //8 |
| 77 | /** |
| 78 | \brief Size (in bytes) of the CCD contact stream (not including force buffer) |
| 79 | */ |
| 80 | PxU16 ; //6 //10 |
| 81 | /** |
| 82 | \brief Defines whether the stream is from a previous pass. |
| 83 | |
| 84 | It could happen that the stream can not get allocated because we run out of memory. In that case the current event should not use the stream |
| 85 | from an event of the previous pass. |
| 86 | */ |
| 87 | PxU16 ; //8 //12 |
| 88 | |
| 89 | PxU8 [12 - sizeof(PxsCCDContactHeader*)]; //16 |
| 90 | }; |
| 91 | |
| 92 | PX_COMPILE_TIME_ASSERT((sizeof(PxsCCDContactHeader) & 0xF) == 0); |
| 93 | |
| 94 | |
| 95 | class PxsContactManager |
| 96 | { |
| 97 | public: |
| 98 | PxsContactManager(PxsContext* context, PxU32 index); |
| 99 | ~PxsContactManager(); |
| 100 | |
| 101 | |
| 102 | PX_FORCE_INLINE void setDisableStrongFriction(PxU32 d) { (!d) ? mNpUnit.flags &= ~PxcNpWorkUnitFlag::eDISABLE_STRONG_FRICTION |
| 103 | : mNpUnit.flags |= PxcNpWorkUnitFlag::eDISABLE_STRONG_FRICTION; } |
| 104 | |
| 105 | PX_FORCE_INLINE PxReal getRestDistance() const { return mNpUnit.restDistance; } |
| 106 | PX_FORCE_INLINE void setRestDistance(PxReal v) { mNpUnit.restDistance = v; } |
| 107 | |
| 108 | void destroy(); |
| 109 | |
| 110 | PX_FORCE_INLINE PxU8 getDominance0() const { return mNpUnit.dominance0; } |
| 111 | PX_FORCE_INLINE void setDominance0(PxU8 v) { mNpUnit.dominance0 = v; } |
| 112 | |
| 113 | PX_FORCE_INLINE PxU8 getDominance1() const { return mNpUnit.dominance1; } |
| 114 | PX_FORCE_INLINE void setDominance1(PxU8 v) { mNpUnit.dominance1 = v; } |
| 115 | |
| 116 | PX_FORCE_INLINE PxU16 getTouchStatus() const { return PxU16(mNpUnit.statusFlags & PxcNpWorkUnitStatusFlag::eHAS_TOUCH); } |
| 117 | PX_FORCE_INLINE PxU16 touchStatusKnown() const { return PxU16(mNpUnit.statusFlags & PxcNpWorkUnitStatusFlag::eTOUCH_KNOWN); } |
| 118 | PX_FORCE_INLINE PxI32 getTouchIdx() const { return (mNpUnit.statusFlags& PxcNpWorkUnitStatusFlag::eHAS_TOUCH) ? 1 : (mNpUnit.statusFlags& PxcNpWorkUnitStatusFlag::eHAS_NO_TOUCH ? -1 : 0); } |
| 119 | |
| 120 | PX_FORCE_INLINE PxU32 getIndex() const { return mNpUnit.index; } |
| 121 | |
| 122 | PX_FORCE_INLINE PxU16 getHasCCDRetouch() const { return PxU16(mNpUnit.statusFlags & PxcNpWorkUnitStatusFlag::eHAS_CCD_RETOUCH); } |
| 123 | PX_FORCE_INLINE void clearCCDRetouch() { mNpUnit.statusFlags &= ~PxcNpWorkUnitStatusFlag::eHAS_CCD_RETOUCH; } |
| 124 | PX_FORCE_INLINE void raiseCCDRetouch() { mNpUnit.statusFlags |= PxcNpWorkUnitStatusFlag::eHAS_CCD_RETOUCH; } |
| 125 | |
| 126 | |
| 127 | |
| 128 | // flags stuff - needs to be refactored |
| 129 | |
| 130 | PX_FORCE_INLINE Ps::IntBool isChangeable() const { return Ps::IntBool(mFlags & PXS_CM_CHANGEABLE); } |
| 131 | PX_FORCE_INLINE Ps::IntBool getCCD() const { return Ps::IntBool((mFlags & PXS_CM_CCD_LINEAR) && (mNpUnit.flags & PxcNpWorkUnitFlag::eDETECT_CCD_CONTACTS)); } |
| 132 | PX_FORCE_INLINE Ps::IntBool getHadCCDContact() const { return Ps::IntBool(mFlags & PXS_CM_CCD_CONTACT); } |
| 133 | PX_FORCE_INLINE void setHadCCDContact() { mFlags |= PXS_CM_CCD_CONTACT; } |
| 134 | void setCCD(bool enable); |
| 135 | PX_FORCE_INLINE void clearCCDContactInfo() { mFlags &= ~PXS_CM_CCD_CONTACT; mNpUnit.ccdContacts = NULL; } |
| 136 | |
| 137 | PX_FORCE_INLINE PxcNpWorkUnit& getWorkUnit() { return mNpUnit; } |
| 138 | PX_FORCE_INLINE const PxcNpWorkUnit& getWorkUnit() const { return mNpUnit; } |
| 139 | |
| 140 | PX_FORCE_INLINE void* getUserData() const { return mShapeInteraction; } |
| 141 | |
| 142 | // Setup solver-constraints |
| 143 | void resetCachedState(); |
| 144 | void resetFrictionCachedState(); |
| 145 | |
| 146 | Sc::ShapeInteraction* getShapeInteraction() const { return mShapeInteraction; } |
| 147 | |
| 148 | private: |
| 149 | //KS - moving this up - we want to get at flags |
| 150 | |
| 151 | PxsRigidBody* mRigidBody0; //4 //8 |
| 152 | PxsRigidBody* mRigidBody1; //8 //16 |
| 153 | PxU32 mFlags; //20 //36 |
| 154 | Sc::ShapeInteraction* mShapeInteraction; //16 //32 |
| 155 | |
| 156 | |
| 157 | |
| 158 | friend class PxsContext; |
| 159 | // everything required for narrow phase to run |
| 160 | PxcNpWorkUnit mNpUnit; |
| 161 | |
| 162 | enum |
| 163 | { |
| 164 | PXS_CM_CHANGEABLE = (1<<0), |
| 165 | PXS_CM_CCD_LINEAR = (1<<1), |
| 166 | PXS_CM_CCD_CONTACT = (1 << 2) |
| 167 | }; |
| 168 | |
| 169 | friend class Dy::DynamicsContext; |
| 170 | friend struct PxsCCDPair; |
| 171 | friend class PxsIslandManager; |
| 172 | friend class PxsCCDContext; |
| 173 | friend class Sc::ShapeInteraction; |
| 174 | }; |
| 175 | |
| 176 | } |
| 177 | |
| 178 | #endif |
| 179 | |