8#include <QtQuick3DRuntimeRender/private/qssgrendererutil_p.h>
10#include <QtQuick3DUtils/private/qssgutils_p.h>
12#include <QtGui/QVector2D>
22 return inViewport.
height() != 0 ? inViewport.
width() / inViewport.
height() : 0.0f;
32 , fovHorizontal(
false)
33 , enableFrustumClipping(true)
57 case QSSGRenderGraphObject::Type::OrthographicCamera:
60 case QSSGRenderGraphObject::Type::PerspectiveCamera:
63 case QSSGRenderGraphObject::Type::CustomCamera:
66 case QSSGRenderGraphObject::Type::CustomFrustumCamera:
126 QVector3D targetDirection = sourcePosition - targetPosition;
133 rotationAxis = upDirection;
161 qWarning() <<
"QSSGRenderCamera::calculateViewProjection: far == near";
173 outMatrix = proj * nonScaledGlobal.
inverted();
177 const QRectF &inViewport)
const
184 QVector2D scaledCoords(inverseFrustumScale.
x() * normalizedCoords.
x(), inverseFrustumScale.
y() * normalizedCoords.
y());
186 if (
type == QSSGRenderCamera::Type::OrthographicCamera) {
187 outOrigin.
setX(scaledCoords.
x());
188 outOrigin.
setY(scaledCoords.
y());
189 outOrigin.
setZ(0.0f);
195 outOrigin.
setX(0.0f);
196 outOrigin.
setY(0.0f);
197 outOrigin.
setZ(0.0f);
199 outDir.
setX(scaledCoords.
x());
200 outDir.
setY(scaledCoords.
y());
218 QSSGPlane theCameraPlane(theCameraDir, theDistance);
271 return QVector2D(intersection.
x(), intersection.
y());
276 if (
type == QSSGRenderGraphObject::Type::OrthographicCamera)
281 return 1.0 / (zn /
width);
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane)
Multiplies this matrix by another that applies a perspective frustum projection for a window with low...
QVector4D column(int index) const
Returns the elements of column index as a 4D vector.
void ortho(const QRect &rect)
This is an overloaded member function, provided for convenience. It differs from the above function o...
float * data()
Returns a pointer to the raw data of this matrix.
void setColumn(int index, const QVector4D &value)
Sets the elements of column index to the components of value.
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
Multiplies this matrix by another that applies a perspective projection.
QMatrix4x4 inverted(bool *invertible=nullptr) const
Returns the inverse of this matrix.
void setToIdentity()
Sets this matrix to the identity.
const float * constData() const
Returns a constant pointer to the raw data of this matrix.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
static QQuaternion fromAxisAndAngle(const QVector3D &axis, float angle)
Creates a normalized quaternion that corresponds to rotating through angle degrees about the specifie...
\inmodule QtCore\reentrant
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Representation of a plane.
float d
The distance from the origin.
void normalize()
equivalent plane with unit normal
QVector3D n
The normal to the plane.
The QVector2D class represents a vector or vertex in 2D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
The QVector3D class represents a vector or vertex in 3D space.
constexpr void setX(float x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
constexpr void setY(float y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr void setZ(float z) noexcept
Sets the z coordinate of this point to the given finite z coordinate.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
void normalize() noexcept
Normalizes the current vector in place.
The QVector4D class represents a vector or vertex in 4D space.
QVector4D normalized() const noexcept
Returns the normalized unit vector form of this vector.
Combined button and popup list for selecting options.
float getAspectRatio(const QRectF &inViewport)
constexpr Initialization Uninitialized
QVector3D Q_QUICK3DUTILS_EXPORT transform(const QMatrix3x3 &m, const QVector3D &v)
QVector3D Q_QUICK3DUTILS_EXPORT transform(const QMatrix4x4 &m, const QVector3D &v)
bool qFuzzyIsNull(qfloat16 f) noexcept
constexpr float qRadiansToDegrees(float radians)
constexpr float qDegreesToRadians(float degrees)
constexpr const T & qMax(const T &a, const T &b)
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static qreal dot(const QPointF &a, const QPointF &b)
QVector2D relativeToNormalizedCoordinates(const QRectF &r, QVector2D rectRelativeCoords)
static QVector2D getViewportHalfExtents(const QMatrix4x4 &projection)
static float getZNear(const QMatrix4x4 &projection)
static QQuaternion rotationQuaternionForLookAt(const QVector3D &sourcePosition, const QVector3D &sourceDirection, const QVector3D &targetPosition, const QVector3D &upDirection)
void clearDirty(DirtyFlag dirtyFlag)
std::underlying_type_t< DirtyFlag > FlagT
float getOrthographicScaleFactor(const QRectF &inViewport) const
bool computeFrustumOrtho(const QRectF &inViewport)
float horizontalMagnification
float getLevelOfDetailMultiplier() const
void calculateViewProjectionMatrix(QMatrix4x4 &outMatrix) const
float verticalFov(float aspectRatio) const
bool computeFrustumPerspective(const QRectF &inViewport)
bool computeCustomFrustum(const QRectF &inViewport)
void calculateViewProjectionWithoutTranslation(float near, float far, QMatrix4x4 &outMatrix) const
bool isDirty(DirtyFlag dirtyFlag=DirtyMask) const
void lookAt(const QVector3D &inCameraPos, const QVector3D &inUpDir, const QVector3D &inTargetPos, const QVector3D &pivot)
QSSGRenderRay unproject(const QVector2D &inLayerRelativeMouseCoords, const QRectF &inViewport) const
QVector3D unprojectToPosition(const QVector3D &inGlobalPos, const QSSGRenderRay &inRay) const
float verticalMagnification
void markDirty(DirtyFlag dirtyFlag)
QRectF previousInViewport
bool calculateProjection(const QRectF &inViewport)
QSSGRenderCamera(QSSGRenderGraphObject::Type type)
static Q_REQUIRED_RESULT constexpr bool isCamera(Type type) Q_DECL_NOTHROW
static constexpr QVector3D initScale
bool calculateGlobalVariables()
void clearDirty(DirtyFlag dirtyFlag)
QVector3D getDirection() const
QMatrix4x4 globalTransform
QVector3D getScalingCorrectDirection() const
static QMatrix4x4 calculateTransformMatrix(QVector3D position, QVector3D scale, QVector3D pivot, QQuaternion rotation)
QMatrix4x4 localTransform
QMatrix3x3 calculateNormalMatrix() const
void markDirty(DirtyFlag dirtyFlag)
static std::optional< QVector3D > intersect(const QSSGPlane &inPlane, const QSSGRenderRay &ray)