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 for 2D Items this will always be (0, 0, 1).
146*/
147QVector3D QQuick3DPickResult::normal() const
148{
149 return m_normal;
150}
151
152
153/*!
154 \qmlproperty vector3d pickResult::sceneNormal
155 \readonly
156
157 This property holds the normal of the face that was hit in scene coordinate
158 space.
159*/
160QVector3D QQuick3DPickResult::sceneNormal() const
161{
162 return m_sceneNormal;
163}
164
165
166/*!
167 \qmlproperty int pickResult::instanceIndex
168 \readonly
169 \since 6.5
170
171 This property holds the index in the instance table for the case
172 where the pick hit an instance of an instanced model.
173*/
174int QQuick3DPickResult::instanceIndex() const
175{
176 return m_instanceIndex;
177}
178
179/*!
180 \qmlproperty Item pickResult::itemHit
181 \readonly
182 \since 6.8
183
184 This property holds the Qt Quick Item hit by the pick. This value will be null if
185 \l{pickResult::}{hitType} is not \c pickResult.Item.
186
187 \sa objectHit
188*/
189
190QQuickItem *QQuick3DPickResult::itemHit() const
191{
192 return m_itemHit;
193}
194
195/*!
196 \qmlproperty enumeration pickResult::hitType
197 \readonly
198 \since 6.8
199
200 This property holds the hit type of the pick result.
201
202 \value PickResult.Null The pick did not hit anything.
203 \value PickResult.Model The pick hit a Model.
204 \value PickResult.Item The pick hit a QQuickItem.
205*/
206
207QQuick3DPickResultEnums::HitType QQuick3DPickResult::hitType() const
208{
209 return m_hitType;
210}
211
212QT_END_NAMESPACE