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
qssgrenderray_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#ifndef QSSG_RENDER_RAY_H
8#define QSSG_RENDER_RAY_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DUtils/private/qssgbounds3_p.h>
22#include <QtQuick3DUtils/private/qssgplane_p.h>
23
24#include <QtGui/QVector2D>
25#include <QtGui/QVector3D>
26#include <QtGui/QMatrix4x4>
27
28#include <optional>
29
30QT_BEGIN_NAMESPACE
31class QSSGMeshBVHNode;
32struct QSSGRenderMesh;
33struct QSSGMeshBVHTriangle;
35{
39};
40
41struct Q_AUTOTEST_EXPORT QSSGRenderRay
42{
43 QVector3D origin;
44 QVector3D direction;
45 QSSGRenderRay() = default;
46 QSSGRenderRay(const QVector3D &inOrigin, const QVector3D &inDirection)
47 : origin(inOrigin), direction(inDirection)
48 {
49 }
50 // If we are parallel, then no intersection of course.
51 static std::optional<QVector3D> intersect(const QSSGPlane &inPlane, const QSSGRenderRay &ray);
52
53 // Perform an intersection aslo returning Barycentric Coordinates
54 static bool triangleIntersect(const QSSGRenderRay &ray,
55 const QVector3D &v0,
56 const QVector3D &v1,
57 const QVector3D &v2,
58 float &u,
59 float &v,
60 QVector3D &normal);
61
62 struct IntersectionResult
63 {
64 bool intersects = false;
65 float rayLengthSquared = 0.; // Length of the ray in world coordinates for the hit.
66 QVector2D relXY; // UV coords for further mouse picking against a offscreen-rendered object.
67 QVector3D scenePosition;
68 QVector3D localPosition;
69 QVector3D faceNormal;
70 QVector3D sceneFaceNormal;
71 IntersectionResult() = default;
72 inline constexpr IntersectionResult(float rl,
73 const QVector2D &relxy,
74 const QVector3D &scenePosition,
75 const QVector3D &localPosition,
76 const QVector3D &normal,
77 const QVector3D &sceneNormal)
78 : intersects(true)
79 , rayLengthSquared(rl)
80 , relXY(relxy)
81 , scenePosition(scenePosition)
82 , localPosition(localPosition)
83 , faceNormal(normal)
84 , sceneFaceNormal(sceneNormal)
85 {}
86 };
87
88 struct HitResult
89 {
90 float min;
91 float max;
92 const QSSGBounds3 *bounds;
93 inline bool intersects() const { return bounds && max >= std::max(min, 0.0f); }
94 };
95
96 struct RayData
97 {
98 enum class DirectionOp : quint8
99 {
100 Normal,
101 Swap,
102 Zero = 0x10
103 };
104
105 const QMatrix4x4 &globalTransform;
106 const QSSGRenderRay &ray;
107 // Cached data calculated from the global transform and the ray
108 const QVector3D origin;
109 const QVector3D directionInvers;
110 const QVector3D direction;
111 const DirectionOp dirOp[3];
112 };
113
114 static RayData createRayData(const QMatrix4x4 &globalTransform,
115 const QSSGRenderRay &ray);
116 static IntersectionResult createIntersectionResult(const RayData &data,
117 const HitResult &hit);
118
119 static HitResult intersectWithAABBv2(const RayData &data,
120 const QSSGBounds3 &bounds);
121
122 static void intersectWithBVH(const RayData &data,
123 const QSSGMeshBVHNode *bvh,
124 const QSSGRenderMesh *mesh,
125 QVector<IntersectionResult> &intersections,
126 int depth = 0);
127
128 static QVector<IntersectionResult> intersectWithBVHTriangles(const RayData &data,
129 const std::vector<QSSGMeshBVHTriangle> &bvhTriangles,
130 int triangleOffset,
131 int triangleCount);
132
133 std::optional<QVector2D> relative(const QMatrix4x4 &inGlobalTransform,
134 const QSSGBounds3 &inBounds,
135 QSSGRenderBasisPlanes inPlane) const;
136
137 std::optional<QVector2D> relativeXY(const QMatrix4x4 &inGlobalTransform, const QSSGBounds3 &inBounds) const
138 {
139 return relative(inGlobalTransform, inBounds, QSSGRenderBasisPlanes::XY);
140 }
141};
142QT_END_NAMESPACE
143#endif
Combined button and popup list for selecting options.
QSSGRenderBasisPlanes