1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qtriggerbody_p.h"
5#include "physxnode/qphysxtriggerbody_p.h"
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \qmltype TriggerBody
11 \inherits PhysicsNode
12 \inqmlmodule QtQuick3D.Physics
13 \since 6.4
14 \brief Reports when objects enter a given volume.
15
16 This type defines a trigger body. A trigger body is a body that does not interact
17 physically but is used to detect when objects intersect with its volume.
18*/
19
20/*!
21 \qmlproperty int TriggerBody::collisionCount
22 This property returns the number of bodies currently colliding with the trigger body.
23*/
24
25/*!
26 \qmlsignal TriggerBody::bodyEntered(PhysicsNode *body)
27 This signal is emitted when the trigger body is penetrated by the specified \a body.
28*/
29
30/*!
31 \qmlsignal TriggerBody::bodyExited(PhysicsNode *body)
32 This signal is emitted when the trigger body is no longer penetrated by the specified \a body.
33*/
34
35QTriggerBody::QTriggerBody() = default;
36
37void QTriggerBody::registerCollision(QAbstractPhysicsNode *collision)
38{
39 int size = m_collisions.size();
40 m_collisions.insert(value: collision);
41
42 if (size != m_collisions.size()) {
43 emit bodyEntered(body: collision);
44 emit collisionCountChanged();
45 }
46}
47
48void QTriggerBody::deregisterCollision(QAbstractPhysicsNode *collision)
49{
50 int size = m_collisions.size();
51 m_collisions.remove(value: collision);
52
53 if (size != m_collisions.size()) {
54 emit bodyExited(body: collision);
55 emit collisionCountChanged();
56 }
57}
58
59int QTriggerBody::collisionCount() const
60{
61 return m_collisions.count();
62}
63
64QAbstractPhysXNode *QTriggerBody::createPhysXBackend()
65{
66 return new QPhysXTriggerBody(this);
67}
68
69QT_END_NAMESPACE
70

source code of qtquick3dphysics/src/quick3dphysics/qtriggerbody.cpp