Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstracttriggerregion_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef ABSTRACTTRIGGERREGION_H
6#define ABSTRACTTRIGGERREGION_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DPhysics/qtquick3dphysicsglobal.h>
21#include <QtCore/QHash>
22#include <QtCore/QSet>
23#include <QtQml/QQmlEngine>
24
26
27// What a node whose shapes are PhysX triggers keeps track of: the bodies
28// overlapping it. TriggerBody reports them, and GravityField acts on them.
29class Q_QUICK3DPHYSICS_EXPORT QAbstractTriggerRegion : public QAbstractPhysicsNode
30{
31 Q_OBJECT
32 QML_ANONYMOUS
33public:
34 QAbstractTriggerRegion();
35
36 // One shape of the region together with one shape of a body, which is what
37 // the simulation reports an overlap for. The same shape listed twice on one
38 // node builds two PhysX shapes that name the same pair, which is the same
39 // answer: they are built from the same geometry at the same pose, so they
40 // start and stop overlapping in the same step.
41 using ShapePair = QPair<QAbstractCollisionShape *, QAbstractCollisionShape *>;
42
43 void registerCollision(QAbstractPhysicsNode *collision, ShapePair shapes);
44 void deregisterCollision(QAbstractPhysicsNode *collision, ShapePair shapes);
45 void invalidateOverlaps(QAbstractPhysicsNode *node);
46 void dropUnreportedOverlaps();
47
48 // Whether `body` is counted by collisionCount and passed to bodyDidEnter()
49 // and bodyDidExit(). By default, whether it asked for that with
50 // PhysicsNode::sendTriggerReports.
51 virtual bool countsBody(const QAbstractPhysicsNode *body) const;
52
53 // Whether bodies that set PhysicsNode::receiveTriggerReports are told about
54 // this region through PhysicsNode::enteredTriggerBody and exitedTriggerBody.
55 // Those signals name a TriggerBody, so by default they are not.
56 virtual bool reportsToBodies() const;
57
58 // The number of bodies inside the region that countsBody() accepted.
59 int collisionCount() const;
60
61Q_SIGNALS:
62 void collisionCountChanged();
63
64protected:
65 // Called when a node actually enters or leaves, i.e. not for repeated
66 // reports about a node that is already tracked.
67 virtual void bodyDidEnter(QAbstractPhysicsNode *body);
68 virtual void bodyDidExit(QAbstractPhysicsNode *body);
69
70 // What is currently reported as overlapping for one body: the shape pairs it
71 // is reported for, and those of them that are waiting to be reported again
72 // because the shapes on one side of them have been replaced.
73 struct Overlaps
74 {
75 QSet<ShapePair> pairs;
76 QSet<ShapePair> unreported;
77 // countsBody() and what the body asked for, as of when it entered, so
78 // that the reports on the way out are the ones made on the way in.
79 bool reports = false;
80 bool receives = false;
81 };
82
83 // Every body overlapping the region, counted or not. The shapes in the
84 // pairs are only ever compared, never dereferenced, since a shape can be
85 // gone before its pairs are.
86 const QHash<QAbstractPhysicsNode *, Overlaps> &collisions() const { return m_collisions; }
87
88private:
89 void dropDestroyedBody(QObject *body);
90 void reportEntered(QAbstractPhysicsNode *body, bool reports, bool receives);
91 void reportExited(QAbstractPhysicsNode *body, bool reports, bool receives);
92
93 QHash<QAbstractPhysicsNode *, Overlaps> m_collisions;
94 // How many of those are counted, kept as they come and go rather than
95 // counted on every read.
96 int m_reportedCount = 0;
97};
98
100
101#endif // ABSTRACTTRIGGERREGION_H
static QAbstractPhysXNode * backendOf(const QAbstractPhysicsNode *node)
void init(QPhysicsWorld *world, QPhysXWorld *physX) override
QList< QPointer< QAbstractPhysicsNode > > wakesOnRemoval
std::optional< SceneGravity > applyGravity(QList< QFilterData > &staleFilters)
QPhysXGravityField(QGravityField *frontEnd)
DebugDrawBodyType getDebugDrawBodyType() override
void init(QPhysicsWorld *world, QPhysXWorld *physX) override
bool useTriggerFlag() override
std::optional< QFilterData > staleFilterOnRemoval
void sync(float deltaTime, QHash< QQuick3DNode *, QMatrix4x4 > &transformCache) override
static void fieldDestroyed(QGravityField *field)
void apply(const QPhysicsGravity &gravity, QPhysicsGravity::Target target, QAbstractPhysicsNode *node, QAbstractPhysXNode *backend, bool wake)
Q_ALWAYS_INLINE bool fuzzyEquals(const physx::PxTransform &a, const physx::PxTransform &b)
PxTransformT< float > PxTransform
DebugDrawBodyType
static bool operator!=(const QFilterData &a, const QFilterData &b)
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE