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