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
qtquick3dphysics-queries.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquick3dphysics-queries.html
6
\title Qt Quick 3D Physics Scene Queries
7
\brief Overview of scene query mechanics, types, and best practices in Qt
8
Quick 3D Physics.
9
10
Scene queries allow applications to test spatial relationships and detect
11
collisions programmatically within a \l PhysicsWorld. They enable mechanics
12
such as line-of-sight checks, spatial probing, volume clearance testing, and
13
interactive picking without relying on standard physical contact callbacks.
14
15
\section1 Types of Scene Queries
16
17
Qt Quick 3D Physics provides three main query modes, each optimized for different
18
spatial operations:
19
20
\table
21
\header
22
\li Query Type
23
\li Operation
24
\li Typical Use Cases
25
\row
26
\li \b Raycast
27
\li Casts an infinitely thin line segment along a direction vector.
28
\li Line-of-sight checks, weapon ballistics, laser pointers, user object
29
picking.
30
\row
31
\li \b Sweep
32
\li Sweeps a 3D volume (\l CollisionShape) from its scene position along a linear
33
direction vector.
34
\li Character volume clearance checks, wall-sliding, predictive movement
35
checks.
36
\row
37
\li \b Overlap
38
\li Tests a stationary 3D volume (\l CollisionShape) at its current scene position.
39
\li Spawn-point occupation, area-of-effect (AoE) damage, proximity
40
detection.
41
\endtable
42
43
Each query mode is split into three performance variants depending on the detail
44
level required:
45
46
\list
47
\li \b {Test Queries} (\c testRaycastQuery, \c testSweepQuery,
48
\c testOverlapQuery):
49
Boolean checks that terminate immediately upon finding the first
50
intersection. They return no detailed hit data, making them the fastest
51
option for occlusion or clearance validation.
52
\li \b {Single Queries} (\c singleRaycastQuery, \c singleSweepQuery):
53
Return detailed information (\l locationHit, \l queryHit)
54
for the \b closest intersecting body.
55
\li \b {Multi Queries} (\c multiRaycastQuery, \c multiSweepQuery,
56
\c multiOverlapQuery):
57
Return a list of hit objects for all intersecting bodies along the query
58
path or volume.
59
\endlist
60
61
\section1 Query Mechanics and Key Nuances
62
63
When using scene queries, several system behaviors should be taken
64
into consideration.
65
66
\section2 Bodies Excluded from Queries
67
68
Trigger bodies, such as \l TriggerBody, are not physical colliders and never appear in
69
scene query results. Use an overlap query if you need the equivalent of a trigger volume
70
that you can poll on demand.
71
72
\section2 Filter Groups Do Not Apply
73
74
The \l {PhysicsNode::filterGroup} {filterGroup} and
75
\l {PhysicsNode::filterIgnoreGroups} {filterIgnoreGroups} properties control which bodies
76
collide with each other during simulation. They have no effect on scene queries: a query
77
evaluates every collider matching its \c includeStatic and \c includeDynamic arguments,
78
regardless of the filter groups involved. If a query needs to ignore specific bodies,
79
filter the results after the query returns.
80
81
\section2 Query Shape Transforms
82
83
For \b Sweep and \b Overlap queries, the provided \l CollisionShape defines not only
84
the geometry and scale, but also the starting position and orientation for the query.
85
The shape's scene transform (including parent node transformations) is baked directly
86
into the query execution.
87
88
\section2 Asynchronous Frame Timing and Latency
89
90
The physics simulation steps concurrently alongside QML scene graph rendering.
91
Scene queries executed while a physics step is in flight reflect object
92
positions, poses, and bounding structures from the \e {last completed physics
93
frame}.
94
95
Consequently, queries triggered inside QML event handlers (such as \c onClicked
96
or a \c Timer) operate on the state of the last completed step. That is the same
97
state the scene's visual representation reflects, so a query result agrees with
98
what is currently rendered; it does not account for motion occurring during the
99
step being computed.
100
101
\section2 Triangle Mesh Multi-Hit Behavior
102
103
Multi-hit queries against complex triangle meshes or heightfield shapes yield a
104
single intersection result per mesh object (the closest entry point). Individual
105
triangles of a single mesh are not reported as separate hits.
106
107
Furthermore, rays or volume sweeps that originate from \e inside a mesh or exit
108
through back-facing surface triangles will not report hits for that mesh.
109
110
\section2 Result Ordering in Multi-Queries
111
112
Hit objects returned by multi-queries (\c multiRaycastQuery, \c multiSweepQuery,
113
\c multiOverlapQuery) are populated based on spatial tree traversal order.
114
\b {The results in the returned list are not guaranteed to be ordered by
115
distance.} If a distance-sorted list is required, applications should sort the
116
resulting list explicitly.
117
118
\section2 Minimum Translation Distance (MTD) in Initial Overlaps
119
120
By default, sweep queries handle initial overlaps with existing colliders using
121
Minimum Translation Distance (MTD). If a query shape already overlaps a body at its
122
starting position, the hit result reports a negative \c distance (representing the
123
penetration depth), along with the separation \c position and \c normal.
124
125
\section2 Character Controller Query Hits
126
127
When scene queries hit a \l CharacterController, the returned hit structure
128
(\l queryHit, or \l locationHit) will contain a valid \c body, but
129
its \c shape property will be \c null. This occurs because the underlying
130
character proxy shape does not maintain individual shape metadata. Applications
131
should check if \c shape is \c null before accessing shape-specific properties.
132
133
\section1 Filtering and Optimization Best Practices
134
135
To achieve optimal performance when using scene queries:
136
137
\list
138
\li \b {Use Test Queries First:} Use \c testRaycastQuery or \c testSweepQuery
139
when you only need a \c true / \c false answer (e.g., AI visibility
140
checks). They bypass allocation and computation of hit geometry.
141
\li \b {Filter Body Types:} Constrain query searches using the \c includeStatic
142
and \c includeDynamic parameters. If a raycast only needs to hit dynamic
143
objects, setting \c includeStatic to \c false reduces traversal overhead.
144
\li \b {Limit Distance:} Keep \c maxDistance as short as practical to minimize
145
the number of candidate bounds evaluated by the spatial acceleration
146
structures.
147
\endlist
148
149
\section1 Example
150
The \l {Qt Quick 3D Physics - Queries Example} shows how to get physical bodies from the scene.
151
152
\sa PhysicsWorld, locationHit, queryHit
153
*/
qtquick3dphysics
src
quick3dphysics
doc
src
qtquick3dphysics-queries.qdoc
Generated on
for Qt by
1.16.1