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