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#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
24
25#include <QtGui/QVector2D>
26#include <QtGui/QVector3D>
27#include <QtGui/QMatrix4x4>
28
29#include <optional>
30
31QT_BEGIN_NAMESPACE
32class QSSGMeshBVHNode;
33struct QSSGRenderMesh;
34struct QSSGMeshBVHTriangle;
36{
40};
41
42struct Q_AUTOTEST_EXPORT QSSGRenderRay
43{
44 QVector3D origin;
45 QVector3D direction;
46 QSSGRenderRay() = default;
47 QSSGRenderRay(const QVector3D &inOrigin, const QVector3D &inDirection)
48 : origin(inOrigin), direction(inDirection)
49 {
50 }
51 // If we are parallel, then no intersection of course.
52 static std::optional<QVector3D> intersect(const QSSGPlane &inPlane, const QSSGRenderRay &ray);
53
54 // Perform an intersection aslo returning Barycentric Coordinates
55 static bool triangleIntersect(const QSSGRenderRay &ray,
56 const QVector3D &v0,
57 const QVector3D &v1,
58 const QVector3D &v2,
59 float &u,
60 float &v,
61 QVector3D &normal,
62 QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back);
63
64 struct IntersectionResult
65 {
66 bool intersects = false;
67 float rayLengthSquared = 0.; // Length of the ray in world coordinates for the hit.
68 QVector2D relXY; // UV coords for further mouse picking against a offscreen-rendered object.
69 QVector3D scenePosition;
70 QVector3D localPosition;
71 QVector3D faceNormal;
72 QVector3D sceneFaceNormal;
73 IntersectionResult() = default;
74 inline constexpr IntersectionResult(float rl,
75 const QVector2D &relxy,
76 const QVector3D &scenePosition,
77 const QVector3D &localPosition,
78 const QVector3D &normal,
79 const QVector3D &sceneNormal)
80 : intersects(true)
81 , rayLengthSquared(rl)
82 , relXY(relxy)
83 , scenePosition(scenePosition)
84 , localPosition(localPosition)
85 , faceNormal(normal)
86 , sceneFaceNormal(sceneNormal)
87 {}
88 };
89
90 struct HitResult
91 {
92 float min;
93 float max;
94 const QSSGBounds3 *bounds;
95 inline bool intersects() const { return bounds && max >= std::max(min, 0.0f); }
96 };
97
98 struct RayData
99 {
100 enum class DirectionOp : quint8
101 {
102 Normal,
103 Swap,
104 Zero = 0x10
105 };
106
107 const QMatrix4x4 &globalTransform;
108 const QSSGRenderRay &ray;
109 // Cached data calculated from the global transform and the ray
110 const QVector3D origin;
111 const QVector3D directionInvers;
112 const QVector3D direction;
113 const DirectionOp dirOp[3];
114 };
115
116 static RayData createRayData(const QMatrix4x4 &globalTransform,
117 const QSSGRenderRay &ray);
118 static IntersectionResult createIntersectionResult(const RayData &data,
119 const HitResult &hit);
120
121 static HitResult intersectWithAABBv2(const RayData &data,
122 const QSSGBounds3 &bounds);
123
124 static void intersectWithBVH(const RayData &data,
125 const QSSGMeshBVHNode *bvh,
126 const QSSGRenderMesh *mesh,
127 QVector<IntersectionResult> &intersections,
128 QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back,
129 int depth = 0);
130
131 static QVector<IntersectionResult> intersectWithBVHTriangles(const RayData &data,
132 const std::vector<QSSGMeshBVHTriangle> &bvhTriangles,
133 int triangleOffset,
134 int triangleCount,
135 QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back);
136
137 std::optional<QVector2D> relative(const QMatrix4x4 &inGlobalTransform,
138 const QSSGBounds3 &inBounds,
139 QSSGRenderBasisPlanes inPlane) const;
140
141 std::optional<QVector2D> relativeXY(const QMatrix4x4 &inGlobalTransform, const QSSGBounds3 &inBounds) const
142 {
143 return relative(inGlobalTransform, inBounds, QSSGRenderBasisPlanes::XY);
144 }
145};
146QT_END_NAMESPACE
147#endif
Combined button and popup list for selecting options.
QSSGRenderBasisPlanes