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
qraycaster_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 QRAYCASTER_P_H
6#define QRAYCASTER_P_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>
20
21#include <QtCore/QPointer>
22#include <QtCore/QVarLengthArray>
23#include <QtGui/qvectornd.h>
24#include <qqmlintegration.h>
25#include <QtQml/QQmlListProperty>
26#include <QtQuick3D/private/qquick3dnode_p.h>
27
28#include <QtQuick3DPhysics/private/qquick3dphysicslocationhit_p.h>
29
31
32class QAbstractPhysicsNode;
33class QPhysicsWorld;
34
35class Q_QUICK3DPHYSICS_EXPORT QRaycaster : public QQuick3DNode
36{
38 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged
39 FINAL REVISION(6, 13))
40 Q_PROPERTY(QVector3D direction READ direction WRITE setDirection NOTIFY directionChanged
41 FINAL REVISION(6, 13))
42 Q_PROPERTY(float maxDistance READ maxDistance WRITE setMaxDistance NOTIFY maxDistanceChanged
43 FINAL REVISION(6, 13))
44 Q_PROPERTY(bool excludeParentBody READ excludeParentBody WRITE setExcludeParentBody NOTIFY
45 excludeParentBodyChanged FINAL REVISION(6, 13))
46 Q_PROPERTY(QQmlListProperty<QAbstractPhysicsNode> excludedBodies READ excludedBodies CONSTANT
47 FINAL REVISION(6, 13))
48 Q_PROPERTY(bool includeStatic READ includeStatic WRITE setIncludeStatic NOTIFY
49 includeStaticChanged FINAL REVISION(6, 13))
50 Q_PROPERTY(bool includeDynamic READ includeDynamic WRITE setIncludeDynamic NOTIFY
51 includeDynamicChanged FINAL REVISION(6, 13))
52 Q_PROPERTY(bool isColliding READ isColliding NOTIFY isCollidingChanged FINAL REVISION(6, 13))
53 Q_PROPERTY(QQuick3DPhysicsLocationHit hit READ hit NOTIFY hitChanged FINAL REVISION(6, 13))
54 QML_NAMED_ELEMENT(Raycaster)
56
57public:
58 explicit QRaycaster(QQuick3DNode *parent = nullptr);
59 ~QRaycaster() override;
60
61 bool enabled() const;
62 void setEnabled(bool enabled);
63
64 QVector3D direction() const;
65 void setDirection(const QVector3D &direction);
67 float maxDistance() const;
68 void setMaxDistance(float maxDistance);
69
70 bool excludeParentBody() const;
71 void setExcludeParentBody(bool excludeParentBody);
72
73 QQmlListProperty<QAbstractPhysicsNode> excludedBodies();
74
75 bool includeStatic() const;
76 void setIncludeStatic(bool includeStatic);
77
78 bool includeDynamic() const;
79 void setIncludeDynamic(bool includeDynamic);
81 bool isColliding() const;
82 QQuick3DPhysicsLocationHit hit() const;
85 void enabledChanged();
86 void directionChanged();
87 void maxDistanceChanged();
88 void excludeParentBodyChanged();
89 void includeStaticChanged();
90 void includeDynamicChanged();
91 void isCollidingChanged();
92 void hitChanged();
93 void bodyEntered(QAbstractPhysicsNode *body);
94 void bodyExited(QAbstractPhysicsNode *body);
95
96private:
97 void updateRaycast(QPhysicsWorld *world);
98 void updateHit(const QQuick3DPhysicsLocationHit &hit);
99 void clearHit();
100 void gatherExcludedBodies(QVarLengthArray<const QAbstractPhysicsNode *, 4> &excluded) const;
101
102 static void qmlAppendExcludedBody(QQmlListProperty<QAbstractPhysicsNode> *list,
103 QAbstractPhysicsNode *body);
104 static QAbstractPhysicsNode *qmlExcludedBodyAt(QQmlListProperty<QAbstractPhysicsNode> *list,
105 qsizetype index);
106 static qsizetype qmlExcludedBodyCount(QQmlListProperty<QAbstractPhysicsNode> *list);
107 static void qmlClearExcludedBodies(QQmlListProperty<QAbstractPhysicsNode> *list);
108
109 bool m_enabled = true;
110 QVector3D m_direction = QVector3D(0.0f, 0.0f, -1.0f);
111 float m_maxDistance = 100.0f;
112 bool m_excludeParentBody = true;
113 bool m_includeStatic = true;
114 bool m_includeDynamic = true;
115 // Weak, so a body deleted after it was listed cannot go on matching a later body that
116 // happens to land on the same address.
117 QList<QPointer<QAbstractPhysicsNode>> m_excludedBodies;
118
119 bool m_isColliding = false;
120 QQuick3DPhysicsLocationHit m_hit;
121
122 friend class QPhysicsWorld;
123};
124
126
127#endif // QRAYCASTER_P_H
Definition qlist.h:82
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:178
PxTransformT< float > PxTransform
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static QWorldManager worldManager
static bool raycastImpl(const physx::PxScene *scene, const QVector3D &origin, const QVector3D &direction, float maxDistance, bool includeStatic, bool includeDynamic, physx::PxRaycastCallback &hitCallback, physx::PxHitFlags hitFlags, physx::PxQueryFlags extraQueryFlags={}, physx::PxQueryFilterCallback *filterCall=nullptr)
static bool validateQuery(const physx::PxScene *scene, bool includeStatic, bool includeDynamic)
static const physx::PxGeometry * validateQueryShape(const physx::PxScene *scene, QAbstractCollisionShape *shape, bool includeStatic, bool includeDynamic)
static void collectPhysicsNodes(QQuick3DObject *node, QList< QAbstractPhysicsNode * > &nodes)
static const QString qtPhysicsTimingsFile
static bool sweepImpl(const physx::PxScene *scene, QAbstractCollisionShape *shape, const QVector3D &direction, float maxDistance, bool includeStatic, bool includeDynamic, physx::PxSweepCallback &hitCallback, physx::PxHitFlags hitFlags, physx::PxQueryFlags extraQueryFlags={})
static bool overlapImpl(const physx::PxScene *scene, QAbstractCollisionShape *shape, bool includeStatic, bool includeDynamic, physx::PxOverlapCallback &hitCallback, physx::PxQueryFlags extraQueryFlags={})
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
#define emit
QVector< QAbstractPhysicsNode * > orphanNodes
QVector< QPhysicsWorld * > worlds
QVector< QRaycaster * > orphanRaycasters
QVector< QPhysicsJoint * > orphanJoints