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
qquick3dpickresult.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 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
8
9QT_BEGIN_NAMESPACE
10
11/*!
12 \qmlvaluetype pickResult
13 \inqmlmodule QtQuick3D
14 \brief Contains the results of a pick.
15
16 Created as a return object to View3D::pick.
17*/
18
19QQuick3DPickResult::QQuick3DPickResult()
20 : m_objectHit(nullptr)
21 , m_distance(0.0f)
22 , m_instanceIndex(-1)
23 , m_itemHit(nullptr)
24 , m_hitType(QQuick3DPickResultEnums::HitType::Null)
25{
26
27}
28
29QQuick3DPickResult::QQuick3DPickResult(QQuick3DModel *hitObject,
30 float distanceFromCamera,
31 const QVector2D &uvPosition,
32 const QVector3D &scenePosition,
33 const QVector3D &position,
34 const QVector3D &normal,
35 const QVector3D &sceneNormal,
36 int instanceIndex,
37 QQuickItem *itemHit)
38 : m_objectHit(hitObject)
39 , m_distance(distanceFromCamera)
40 , m_uvPosition(uvPosition)
41 , m_scenePosition(scenePosition)
42 , m_position(position)
43 , m_normal(normal)
44 , m_sceneNormal(sceneNormal)
45 , m_instanceIndex(instanceIndex)
46 , m_itemHit(itemHit)
47 , m_hitType(QQuick3DPickResultEnums::HitType::Model)
48{
49
50}
51
52QQuick3DPickResult::QQuick3DPickResult(QQuickItem *itemHit,
53 float distanceFromCamera,
54 const QVector2D &uvPosition,
55 const QVector3D &scenePosition,
56 const QVector3D &position,
57 const QVector3D &sceneNormal)
58 : m_objectHit(nullptr)
59 , m_distance(distanceFromCamera)
60 , m_uvPosition(uvPosition)
61 , m_scenePosition(scenePosition)
62 , m_position(position)
63 , m_normal({ 0, 0, 1 })
64 , m_sceneNormal(sceneNormal)
65 , m_instanceIndex(-1)
66 , m_itemHit(itemHit)
67 , m_hitType(QQuick3DPickResultEnums::HitType::Item)
68{
69
70}
71
72/*!
73 \qmlproperty Model pickResult::objectHit
74 \readonly
75
76 This property holds the model object hit by the pick. This value will be null if
77 \l{pickResult::hitType} {hitType} is not \c pickResult.Model.
78
79 \sa itemHit
80*/
81QQuick3DModel *QQuick3DPickResult::objectHit() const
82{
83 return m_objectHit;
84}
85
86/*!
87 \qmlproperty real pickResult::distance
88 \readonly
89
90 This property holds the distance between the pick origin and the hit position
91 i.e. the length of the ray. In the case of using viewport coordinates for
92 picking the pick origin will be the active camera's position.
93*/
94float QQuick3DPickResult::distance() const
95{
96 return m_distance;
97}
98
99/*!
100 \qmlproperty vector2d pickResult::uvPosition
101 \readonly
102
103 This property holds the UV position of the hit. The UV position is calculated as
104 the normalized local x and y coordinates of the hit point relative to the bounding volume.
105 Useful for further picking against an offscreen-rendered object.
106
107 When \l{pickResult::}{hitType} is \c pickResult.Item this value will represent the position
108 of the hit in the coordinate space of \l{pickResult::}{itemHit}.
109*/
110QVector2D QQuick3DPickResult::uvPosition() const
111{
112 return m_uvPosition;
113}
114
115/*!
116 \qmlproperty vector3d pickResult::scenePosition
117 \readonly
118
119 This property holds the scene position of the hit.
120*/
121QVector3D QQuick3DPickResult::scenePosition() const
122{
123 return m_scenePosition;
124}
125
126/*!
127 \qmlproperty vector3d pickResult::position
128 \readonly
129
130 This property holds the scene position of the hit in local coordinate
131 space.
132*/
133QVector3D QQuick3DPickResult::position() const
134{
135 return m_position;
136}
137
138/*!
139 \qmlproperty vector3d pickResult::normal
140 \readonly
141
142 This property holds the normal of the face that was hit in local coordinate
143 space.
144
145 \note This is the geometric normal of the face, which for a face that was
146 hit on its back side points away from the ray. Back sides are only picked
147 when the material's \l {Material::cullMode}{cull mode} does not discard
148 them.
149
150 \note for 2D Items this will always be (0, 0, 1).
151*/
152QVector3D QQuick3DPickResult::normal() const
153{
154 return m_normal;
155}
156
157
158/*!
159 \qmlproperty vector3d pickResult::sceneNormal
160 \readonly
161
162 This property holds the normal of the face that was hit in scene coordinate
163 space.
164*/
165QVector3D QQuick3DPickResult::sceneNormal() const
166{
167 return m_sceneNormal;
168}
169
170
171/*!
172 \qmlproperty int pickResult::instanceIndex
173 \readonly
174 \since 6.5
175
176 This property holds the index in the instance table for the case
177 where the pick hit an instance of an instanced model.
178*/
179int QQuick3DPickResult::instanceIndex() const
180{
181 return m_instanceIndex;
182}
183
184/*!
185 \qmlproperty Item pickResult::itemHit
186 \readonly
187 \since 6.8
188
189 This property holds the Qt Quick Item hit by the pick. This value will be null if
190 \l{pickResult::}{hitType} is not \c pickResult.Item.
191
192 \sa objectHit
193*/
194
195QQuickItem *QQuick3DPickResult::itemHit() const
196{
197 return m_itemHit;
198}
199
200/*!
201 \qmlproperty enumeration pickResult::hitType
202 \readonly
203 \since 6.8
204
205 This property holds the hit type of the pick result.
206
207 \value PickResult.Null The pick did not hit anything.
208 \value PickResult.Model The pick hit a Model.
209 \value PickResult.Item The pick hit a QQuickItem.
210*/
211
212QQuick3DPickResultEnums::HitType QQuick3DPickResult::hitType() const
213{
214 return m_hitType;
215}
216
217QT_END_NAMESPACE