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
61
62
63
64
65
66
69
70
71
72
73
74
75
76
77
80
81
82
83
84
85
86
87
88
91
92
93
94
95
96
97
98
99
100
101
102
103
106
107
108
109
110
111
112
115
116
117
118
119
120
121
123QAbstractPhysicsNode::QAbstractPhysicsNode()
125 QPhysicsWorld::registerNode(
this);
128QAbstractPhysicsNode::~QAbstractPhysicsNode()
130 for (
auto shape : std::as_const(m_collisionShapes))
131 shape->disconnect(
this);
132 QPhysicsWorld::deregisterNode(
this);
135QQmlListProperty<QAbstractCollisionShape> QAbstractPhysicsNode::collisionShapes()
137 return QQmlListProperty<QAbstractCollisionShape>(
138 this,
nullptr, QAbstractPhysicsNode::qmlAppendShape,
139 QAbstractPhysicsNode::qmlShapeCount, QAbstractPhysicsNode::qmlShapeAt,
140 QAbstractPhysicsNode::qmlClearShapes);
143const QVector<QAbstractCollisionShape *> &QAbstractPhysicsNode::getCollisionShapesList()
const
145 return m_collisionShapes;
148void QAbstractPhysicsNode::updateFromPhysicsTransform(
const physx::PxTransform &transform)
150 const auto pos = transform.p;
151 const auto rotation = transform.q;
152 const auto qtPosition = QVector3D(pos.x, pos.y, pos.z);
153 const auto qtRotation = QQuaternion(rotation.w, rotation.x, rotation.y, rotation.z);
156 const QQuick3DNode *parentNode =
static_cast<QQuick3DNode *>(parentItem());
160 setRotation(qtRotation);
161 setPosition(qtPosition);
163 setPosition(parentNode->mapPositionFromScene(qtPosition));
164 const auto relativeRotation = parentNode->sceneRotation().inverted() * qtRotation;
165 setRotation(relativeRotation);
169bool QAbstractPhysicsNode::sendContactReports()
const
171 return m_sendContactReports;
174void QAbstractPhysicsNode::setSendContactReports(
bool sendContactReports)
176 if (m_sendContactReports == sendContactReports)
179 m_sendContactReports = sendContactReports;
180 emit sendContactReportsChanged(m_sendContactReports);
183bool QAbstractPhysicsNode::receiveContactReports()
const
185 return m_receiveContactReports;
188void QAbstractPhysicsNode::setReceiveContactReports(
bool receiveContactReports)
190 if (m_receiveContactReports == receiveContactReports)
193 m_receiveContactReports = receiveContactReports;
194 emit receiveContactReportsChanged(m_receiveContactReports);
197bool QAbstractPhysicsNode::sendTriggerReports()
const
199 return m_sendTriggerReports;
202void QAbstractPhysicsNode::setSendTriggerReports(
bool sendTriggerReports)
204 if (m_sendTriggerReports == sendTriggerReports)
207 m_sendTriggerReports = sendTriggerReports;
208 emit sendTriggerReportsChanged(m_sendTriggerReports);
211bool QAbstractPhysicsNode::receiveTriggerReports()
const
213 return m_receiveTriggerReports;
216void QAbstractPhysicsNode::setReceiveTriggerReports(
bool receiveTriggerReports)
218 if (m_receiveTriggerReports == receiveTriggerReports)
221 m_receiveTriggerReports = receiveTriggerReports;
222 emit receiveTriggerReportsChanged(m_receiveTriggerReports);
225void QAbstractPhysicsNode::registerContact(QAbstractPhysicsNode *body,
226 const QVector<QVector3D> &positions,
227 const QVector<QVector3D> &impulses,
228 const QVector<QVector3D> &normals)
230 emit bodyContact(body, positions, impulses, normals);
233void QAbstractPhysicsNode::onShapeDestroyed(QObject *object)
235 m_collisionShapes.removeAll(
static_cast<QAbstractCollisionShape *>(object));
238void QAbstractPhysicsNode::onShapeNeedsRebuild(QObject * )
240 m_shapesDirty =
true;
243void QAbstractPhysicsNode::qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list,
244 QAbstractCollisionShape *shape)
246 if (shape ==
nullptr)
248 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
249 self->m_collisionShapes.push_back(shape);
250 self->m_hasStaticShapes = self->m_hasStaticShapes || shape->isStaticShape();
252 if (shape->parentItem() ==
nullptr) {
255 QQuick3DObject *parentItem = qobject_cast<QQuick3DObject *>(shape->parent());
257 shape->setParentItem(parentItem);
259 const auto &scenManager = QQuick3DObjectPrivate::get(self)->sceneManager;
261 QQuick3DObjectPrivate::refSceneManager(shape, *scenManager);
267 connect(shape, &QAbstractCollisionShape::destroyed, self,
268 &QAbstractPhysicsNode::onShapeDestroyed);
271 connect(shape, &QAbstractCollisionShape::needsRebuild, self,
272 &QAbstractPhysicsNode::onShapeNeedsRebuild);
275QAbstractCollisionShape *
276QAbstractPhysicsNode::qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list, qsizetype index)
278 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
279 return self->m_collisionShapes.at(index);
282qsizetype QAbstractPhysicsNode::qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list)
284 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
285 return self->m_collisionShapes.count();
288void QAbstractPhysicsNode::qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list)
290 QAbstractPhysicsNode *self =
static_cast<QAbstractPhysicsNode *>(list->object);
291 for (
const auto &shape : std::as_const(self->m_collisionShapes)) {
292 if (shape->parentItem() ==
nullptr)
293 QQuick3DObjectPrivate::get(shape)->derefSceneManager();
295 self->m_hasStaticShapes =
false;
296 for (
auto shape : std::as_const(self->m_collisionShapes))
297 shape->disconnect(self);
298 self->m_collisionShapes.clear();
301int QAbstractPhysicsNode::filterGroup()
const
303 return m_filterGroup;
306void QAbstractPhysicsNode::setfilterGroup(
int newfilterGroup)
308 if (m_filterGroup == newfilterGroup)
310 m_filterGroup = newfilterGroup;
311 m_filtersDirty =
true;
312 emit filterGroupChanged();
315int QAbstractPhysicsNode::filterIgnoreGroups()
const
317 return m_filterIgnoreGroups;
320void QAbstractPhysicsNode::setFilterIgnoreGroups(
int newFilterIgnoreGroups)
322 if (m_filterIgnoreGroups == newFilterIgnoreGroups)
324 m_filterIgnoreGroups = newFilterIgnoreGroups;
325 m_filtersDirty =
true;
326 emit filterIgnoreGroupsChanged();
Combined button and popup list for selecting options.