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