RavEngine
Loading...
Searching...
No Matches
ScTriggerInteraction.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 SC_TRIGGER_INTERACTION_H
30#define SC_TRIGGER_INTERACTION_H
31
32#include "ScElementSimInteraction.h"
33#include "ScShapeSim.h"
34#include "GuOverlapTests.h"
35
36namespace physx
37{
38namespace Sc
39{
41 {
42 public:
43 enum TriggerFlag
44 {
45 PAIR_FLAGS_MASK = ((PxPairFlag::eNOTIFY_TOUCH_LOST << 1) - 1), // Bits where the PxPairFlags eNOTIFY_TOUCH_FOUND and eNOTIFY_TOUCH_LOST get stored
46 NEXT_FREE = ((PAIR_FLAGS_MASK << 1) & ~PAIR_FLAGS_MASK),
47
48 PROCESS_THIS_FRAME = (NEXT_FREE << 0), // the trigger pair is new or the pose of an actor was set -> initial processing required.
49 // This is important to cover cases where a static or kinematic
50 // (non-moving) trigger is created and overlaps with a sleeping
51 // object. Or for the case where a static/kinematic is teleported to a new
52 // location. TOUCH_FOUND should still get sent in that case.
53 LAST = (NEXT_FREE << 1)
54 };
55
56 TriggerInteraction(ShapeSimBase& triggerShape, ShapeSimBase& otherShape);
58
59 PX_FORCE_INLINE Gu::TriggerCache& getTriggerCache() { return mTriggerCache; }
60 PX_FORCE_INLINE ShapeSimBase& getTriggerShape() const { return static_cast<ShapeSimBase&>(getElement0()); }
61 PX_FORCE_INLINE ShapeSimBase& getOtherShape() const { return static_cast<ShapeSimBase&>(getElement1()); }
62
63 PX_FORCE_INLINE bool lastFrameHadContacts() const { return mLastFrameHadContacts; }
64 PX_FORCE_INLINE void updateLastFrameHadContacts(bool hasContact) { mLastFrameHadContacts = hasContact; }
65
66 PX_FORCE_INLINE PxPairFlags getTriggerFlags() const { return PxPairFlags(mFlags & PAIR_FLAGS_MASK); }
67 PX_FORCE_INLINE void setTriggerFlags(PxPairFlags triggerFlags);
68
69 PX_FORCE_INLINE void raiseFlag(TriggerFlag flag) { mFlags |= flag; }
70 PX_FORCE_INLINE void clearFlag(TriggerFlag flag) { mFlags &= ~flag; }
71 PX_FORCE_INLINE PxIntBool readFlag(TriggerFlag flag) const { return PxIntBool(mFlags & flag); }
72
73 PX_FORCE_INLINE void forceProcessingThisFrame(Sc::Scene& scene);
74
75 bool onActivate_(void*);
76 bool onDeactivate_();
77
78 protected:
79 Gu::TriggerCache mTriggerCache;
80 bool mLastFrameHadContacts;
81 };
82
83} // namespace Sc
84
85
86PX_FORCE_INLINE void Sc::TriggerInteraction::setTriggerFlags(PxPairFlags triggerFlags)
87{
88 PX_ASSERT(PxU32(triggerFlags) < (PxPairFlag::eDETECT_CCD_CONTACT << 1)); // to find out if a new PxPairFlag has been added in which case PAIR_FLAGS_MASK needs to get adjusted
89
90#if PX_CHECKED
91 if (triggerFlags & PxPairFlag::eNOTIFY_TOUCH_PERSISTS)
92 {
93 PX_WARN_ONCE("Trigger pairs do not support PxPairFlag::eNOTIFY_TOUCH_PERSISTS events any longer.");
94 }
95#endif
96
97 PxU32 newFlags = mFlags;
98 PxU32 fl = PxU32(triggerFlags) & PxU32(PxPairFlag::eNOTIFY_TOUCH_FOUND|PxPairFlag::eNOTIFY_TOUCH_LOST);
99 newFlags &= (~PAIR_FLAGS_MASK); // clear old flags
100 newFlags |= fl;
101
102 mFlags = newFlags;
103}
104
105PX_FORCE_INLINE void Sc::TriggerInteraction::forceProcessingThisFrame(Sc::Scene& scene)
106{
107 raiseFlag(PROCESS_THIS_FRAME);
108
109 if (!readInteractionFlag(InteractionFlag::eIS_ACTIVE))
110 {
111 raiseInteractionFlag(InteractionFlag::eIS_ACTIVE);
112 scene.notifyInteractionActivated(this);
113 }
114}
115
116}
117
118#endif
Definition ScElementSimInteraction.h:40
Definition ScScene.h:240
Definition ScShapeSimBase.h:54
Definition ScTriggerInteraction.h:41
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxPairFlag::Enum, PxU16 > PxPairFlags
Bitfield that contains a set of raised flags defined in PxPairFlag.
Definition PxFiltering.h:277
Definition GuOverlapTests.h:59
@ eDETECT_CCD_CONTACT
This flag is used to indicate whether this pair generates CCD contacts.
Definition PxFiltering.h:216
@ eNOTIFY_TOUCH_LOST
Call contact report callback or trigger callback when this collision pair stops to be in contact.
Definition PxFiltering.h:125
@ eNOTIFY_TOUCH_FOUND
Call contact report callback or trigger callback when this collision pair starts to be in contact.
Definition PxFiltering.h:87
@ eNOTIFY_TOUCH_PERSISTS
Call contact report callback while this collision pair is in contact.
Definition PxFiltering.h:107