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:
138 QVector3D targetDirection = sourcePosition - targetPosition;
145 rotationAxis = upDirection;
150 return QQuaternion::fromAxisAndAngle(rotationAxis, rotationAngle);
173 qWarning() <<
"QSSGRenderCamera::calculateViewProjection: far == near";
184 nonScaledGlobal.setColumn(3,
QVector4D(0, 0, 0, 1));
185 outMatrix = proj * nonScaledGlobal.inverted();
189 const QRectF &inViewport)
const
196 QVector2D scaledCoords(inverseFrustumScale.x() * normalizedCoords.x(), inverseFrustumScale.y() * normalizedCoords.y());
198 if (
type == QSSGRenderCamera::Type::OrthographicCamera) {
199 outOrigin.setX(scaledCoords.x());
200 outOrigin.setY(scaledCoords.y());
201 outOrigin.setZ(0.0f);
207 outOrigin.setX(0.0f);
208 outOrigin.setY(0.0f);
209 outOrigin.setZ(0.0f);
211 outDir.setX(scaledCoords.x());
212 outDir.setY(scaledCoords.y());
230 QSSGPlane theCameraPlane(theCameraDir, theDistance);
268 nearPlane.normalize();
270 rightPlane.normalize();
272 topPlane.normalize();
283 return QVector2D(intersection.
x(), intersection.
y());
288 if (
type == QSSGRenderGraphObject::Type::OrthographicCamera)
293 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 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.
\inmodule QtCore\reentrant
Representation of a plane.
float d
The distance from the origin.
void normalize()
equivalent plane with unit normal
static constexpr bool isCamera(Type type) noexcept
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.
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
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.
QVector3D Q_QUICK3DUTILS_EXPORT transform(const QMatrix3x3 &m, const QVector3D &v)
QVector3D Q_QUICK3DUTILS_EXPORT transform(const QMatrix4x4 &m, const QVector3D &v)
QVector2D relativeToNormalizedCoordinates(const QRectF &r, QVector2D rectRelativeCoords)
Combined button and popup list for selecting options.
float getAspectRatio(const QRectF &inViewport)
constexpr Initialization Uninitialized
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)
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
float verticalFov(float aspectRatio) const
bool computeFrustumPerspective(const QRectF &inViewport)
bool computeCustomFrustum(const QRectF &inViewport)
static void calculateViewProjectionMatrix(const QMatrix4x4 &globalTransform, const QMatrix4x4 &projection, QMatrix4x4 &outMatrix)
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 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)