6#include <QtQuick3D/private/qquick3dobject_p.h>
7#include <foundation/PxTransform.h>
11#include <QtGui/qquaternion.h>
16
17
18
19
20
21
22
23
24
27
28
29
30
31
32
33
36
37
38
39
40
41
44
45
46
47
48
49
50
53
54
55
56
57
58
59
60
61
64
65
66
67
68
69
70
71
72
75
76
77
78
79
80
81
82
83
86
87
88
89
90
91
92
93
94
97
98
99
100
101
102
103
104
105
106
107
108
109
112
113
114
115
116
117
118
119
120
121
124
125
126
127
128
129
130
131
132
133
134
136QAbstractPhysicsNode::QAbstractPhysicsNode()
138 QPhysicsWorld::registerNode(
this);
141QAbstractPhysicsNode::~QAbstractPhysicsNode()
143 for (
auto shape : std::as_const(m_collisionShapes))
144 shape->disconnect(
this);
145 QPhysicsWorld::deregisterNode(
this);
148QQmlListProperty<QAbstractCollisionShape> QAbstractPhysicsNode::collisionShapes()
150 return QQmlListProperty<QAbstractCollisionShape>(
151 this,
nullptr, QAbstractPhysicsNode::qmlAppendShape,
152 QAbstractPhysicsNode::qmlShapeCount, QAbstractPhysicsNode::qmlShapeAt,
153 QAbstractPhysicsNode::qmlClearShapes);
156const QVector<QAbstractCollisionShape *> &QAbstractPhysicsNode::getCollisionShapesList()
const
158 return m_collisionShapes;
161void QAbstractPhysicsNode::updateFromPhysicsTransform(
const physx::PxTransform &transform)
163 const auto pos = transform.p;
164 const auto rotation = transform.q;
165 const auto qtPosition = QVector3D(pos.x, pos.y, pos.z);
166 const auto qtRotation = QQuaternion(rotation.w, rotation.x, rotation.y, rotation.z);
169 const QQuick3DNode *parentNode =
static_cast<QQuick3DNode *>(parentItem());
178 const QVector3D localPosition =
179 parentNode ? parentNode->mapPositionFromScene(qtPosition) : qtPosition;
180 const QQuaternion localRotation =
181 parentNode ? parentNode->sceneRotation().inverted() * qtRotation : qtRotation;
183 setPosition(localPosition);
184 setRotation(localRotation);
187bool QAbstractPhysicsNode::sendContactReports()
const
189 return m_sendContactReports;
192void QAbstractPhysicsNode::setSendContactReports(
bool sendContactReports)
194 if (m_sendContactReports == sendContactReports)
197 m_sendContactReports = sendContactReports;
198 emit sendContactReportsChanged(m_sendContactReports);
201bool QAbstractPhysicsNode::receiveContactReports()
const
203 return m_receiveContactReports;
206void QAbstractPhysicsNode::setReceiveContactReports(
bool receiveContactReports)
208 if (m_receiveContactReports == receiveContactReports)
211 m_receiveContactReports = receiveContactReports;
212 emit receiveContactReportsChanged(m_receiveContactReports);
215bool QAbstractPhysicsNode::sendTriggerReports()
const
217 return m_sendTriggerReports;
220void QAbstractPhysicsNode::setSendTriggerReports(
bool sendTriggerReports)
222 if (m_sendTriggerReports == sendTriggerReports)
225 m_sendTriggerReports = sendTriggerReports;
226 emit sendTriggerReportsChanged(m_sendTriggerReports);
229bool QAbstractPhysicsNode::receiveTriggerReports()
const
231 return m_receiveTriggerReports;
234void QAbstractPhysicsNode::setReceiveTriggerReports(
bool receiveTriggerReports)
236 if (m_receiveTriggerReports == receiveTriggerReports)
239 m_receiveTriggerReports = receiveTriggerReports;
240 emit receiveTriggerReportsChanged(m_receiveTriggerReports);
243void QAbstractPhysicsNode::registerContact(QAbstractPhysicsNode *body,
244 const QVector<QVector3D> &positions,
245 const QVector<QVector3D> &impulses,
246 const QVector<QVector3D> &normals)
248 emit bodyContact(body, positions, impulses, normals);
251void QAbstractPhysicsNode::onShapeDestroyed(QObject *object)
253 m_collisionShapes.removeAll(
static_cast<QAbstractCollisionShape *>(object));
256void QAbstractPhysicsNode::onShapeNeedsRebuild(QObject * )
258 m_shapesDirty =
true;
261void QAbstractPhysicsNode::qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list,
262 QAbstractCollisionShape *shape)
264 if (shape ==
nullptr)
266 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
267 self->m_collisionShapes.push_back(shape);
268 self->m_hasStaticShapes = self->m_hasStaticShapes || shape->isStaticShape();
270 if (shape->parentItem() ==
nullptr) {
273 QQuick3DObject *parentItem = qobject_cast<QQuick3DObject *>(shape->parent());
275 shape->setParentItem(parentItem);
277 const auto &scenManager = QQuick3DObjectPrivate::get(self)->sceneManager;
279 QQuick3DObjectPrivate::refSceneManager(shape, *scenManager);
285 connect(shape, &QAbstractCollisionShape::destroyed, self,
286 &QAbstractPhysicsNode::onShapeDestroyed);
289 connect(shape, &QAbstractCollisionShape::needsRebuild, self,
290 &QAbstractPhysicsNode::onShapeNeedsRebuild);
293QAbstractCollisionShape *
294QAbstractPhysicsNode::qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list, qsizetype index)
296 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
297 return self->m_collisionShapes.at(index);
300qsizetype QAbstractPhysicsNode::qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list)
302 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
303 return self->m_collisionShapes.count();
306void QAbstractPhysicsNode::qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list)
308 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
309 for (
const auto &shape : std::as_const(self->m_collisionShapes)) {
310 if (shape->parentItem() ==
nullptr)
311 QQuick3DObjectPrivate::get(shape)->derefSceneManager();
313 self->m_hasStaticShapes =
false;
314 for (
auto shape : std::as_const(self->m_collisionShapes))
315 shape->disconnect(self);
316 self->m_collisionShapes.clear();
319int QAbstractPhysicsNode::filterGroup()
const
321 return m_filterGroup;
324void QAbstractPhysicsNode::setfilterGroup(
int newfilterGroup)
326 if (m_filterGroup == newfilterGroup)
329 if (newfilterGroup < 0 || newfilterGroup >= 32) {
330 qWarning() <<
"PhysicsNode: filterGroup" << newfilterGroup
331 <<
"is out of range [0, 31], ignoring. Values outside this range are"
332 " silently excluded from collision filtering by the underlying engine.";
336 m_filterGroup = newfilterGroup;
337 m_filtersDirty =
true;
338 emit filterGroupChanged();
341int QAbstractPhysicsNode::filterIgnoreGroups()
const
343 return m_filterIgnoreGroups;
346void QAbstractPhysicsNode::setFilterIgnoreGroups(
int newFilterIgnoreGroups)
348 if (m_filterIgnoreGroups == newFilterIgnoreGroups)
350 m_filterIgnoreGroups = newFilterIgnoreGroups;
351 m_filtersDirty =
true;
352 emit filterIgnoreGroupsChanged();
Combined button and popup list for selecting options.