diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-09-30 15:35:12 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-10-14 16:01:12 +0000 |
commit | 797f5b02691551ce276b335f1409c3378b973e3e (patch) | |
tree | c068219c70ee20ff9461523927de1930a596d5a2 /src/core/core-components/qcamera.cpp | |
parent | 2ee30c9a87f15404adce7267d364398e09906576 (diff) |
QCamera: clean up and make useful method Q_INVOKABLE
- remove const float &
- correct coding style
- register the CameraTranslateOptions enum
- make all translate/rotate methods Q_INVOKABLE
Change-Id: I4f145a32aff9571c54c5eb63e76b237a0ff0ce35
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/core/core-components/qcamera.cpp')
-rw-r--r-- | src/core/core-components/qcamera.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/core/core-components/qcamera.cpp b/src/core/core-components/qcamera.cpp index 5f7b2ef9a..0746b408b 100644 --- a/src/core/core-components/qcamera.cpp +++ b/src/core/core-components/qcamera.cpp @@ -135,24 +135,24 @@ void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option // Calculate the amount to move by in world coordinates QVector3D vWorld; - if ( !qFuzzyIsNull( vLocal.x() ) ) + if (!qFuzzyIsNull(vLocal.x())) { // Calculate the vector for the local x axis - QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized(); + const QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized(); vWorld += vLocal.x() * x; } - if ( !qFuzzyIsNull( vLocal.y() ) ) + if (!qFuzzyIsNull(vLocal.y())) vWorld += vLocal.y() * upVector(); - if ( !qFuzzyIsNull( vLocal.z() ) ) + if (!qFuzzyIsNull(vLocal.z())) vWorld += vLocal.z() * viewVector.normalized(); // Update the camera position using the calculated world vector setPosition(position() + vWorld); // May be also update the view center coordinates - if ( option == TranslateViewCenter ) + if (option == TranslateViewCenter) setViewCenter(viewCenter() + vWorld); // Refresh the camera -> view center vector @@ -164,7 +164,7 @@ void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option // 2) The local x vector is the normal to the plane in which the new up vector // must lay. So we can take the cross product of this normal and the new // x vector. The new normal vector forms the last part of the orthonormal basis - QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized(); + const QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized(); setUpVector(QVector3D::crossProduct(x, viewVector).normalized()); } @@ -180,9 +180,9 @@ void QCamera::translateWorld(const QVector3D& vWorld , CameraTranslationOption o QQuaternion QCamera::tiltRotation(float angle) const { - QVector3D viewVector = viewCenter() - position(); - QVector3D xBasis = QVector3D::crossProduct(upVector(), viewVector.normalized()).normalized(); - return QQuaternion::fromAxisAndAngle( xBasis, -angle ); + const QVector3D viewVector = viewCenter() - position(); + const QVector3D xBasis = QVector3D::crossProduct(upVector(), viewVector.normalized()).normalized(); + return QQuaternion::fromAxisAndAngle(xBasis, -angle); } QQuaternion QCamera::panRotation(float angle) const @@ -196,43 +196,43 @@ QQuaternion QCamera::rollRotation(float angle) const return QQuaternion::fromAxisAndAngle(viewVector, -angle); } -void QCamera::tilt( const float& angle ) +void QCamera::tilt(float angle) { - QQuaternion q = tiltRotation( angle ); - rotate( q ); + QQuaternion q = tiltRotation(angle); + rotate(q); } -void QCamera::pan( const float& angle ) +void QCamera::pan(float angle) { - QQuaternion q = panRotation( -angle ); - rotate( q ); + QQuaternion q = panRotation(-angle); + rotate(q); } -void QCamera::roll( const float& angle ) +void QCamera::roll(float angle) { - QQuaternion q = rollRotation( -angle ); - rotate( q ); + QQuaternion q = rollRotation(-angle); + rotate(q); } -void QCamera::tiltAboutViewCenter( const float& angle ) +void QCamera::tiltAboutViewCenter(float angle) { - QQuaternion q = tiltRotation( -angle ); - rotateAboutViewCenter( q ); + QQuaternion q = tiltRotation(-angle); + rotateAboutViewCenter(q); } -void QCamera::panAboutViewCenter( const float& angle ) +void QCamera::panAboutViewCenter(float angle) { - QQuaternion q = panRotation( angle ); - rotateAboutViewCenter( q ); + QQuaternion q = panRotation(angle); + rotateAboutViewCenter(q); } -void QCamera::rollAboutViewCenter( const float& angle ) +void QCamera::rollAboutViewCenter(float angle) { - QQuaternion q = rollRotation( angle ); - rotateAboutViewCenter( q ); + QQuaternion q = rollRotation(angle); + rotateAboutViewCenter(q); } -void QCamera::rotate( const QQuaternion& q ) +void QCamera::rotate(const QQuaternion& q) { setUpVector(q * upVector()); QVector3D viewVector = viewCenter() - position(); @@ -240,7 +240,7 @@ void QCamera::rotate( const QQuaternion& q ) setViewCenter(position() + cameraToCenter); } -void QCamera::rotateAboutViewCenter( const QQuaternion& q ) +void QCamera::rotateAboutViewCenter(const QQuaternion& q) { setUpVector(q * upVector()); QVector3D viewVector = viewCenter() - position(); |