diff options
Diffstat (limited to 'examples/widgets/graphicsview/boxes')
-rw-r--r-- | examples/widgets/graphicsview/boxes/glbuffers.cpp | 4 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/scene.cpp | 5 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/scene.h | 2 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/trackball.cpp | 8 |
4 files changed, 10 insertions, 9 deletions
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp index 1481292e76..851cd17796 100644 --- a/examples/widgets/graphicsview/boxes/glbuffers.cpp +++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp @@ -50,11 +50,11 @@ #include "glbuffers.h" #include <QtGui/qmatrix4x4.h> - +#include <QtCore/qmath.h> void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) { - const GLdouble ymax = zNear * tan(fovy * M_PI / 360.0); + const GLdouble ymax = zNear * tan(qDegreesToRadians(fovy) / 2.0); const GLdouble ymin = -ymax; const GLdouble xmin = ymin * aspect; const GLdouble xmax = ymax * aspect; diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 9ac429c667..31b9553c75 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -52,7 +52,7 @@ #include "scene.h" #include <QtGui/qmatrix4x4.h> #include <QtGui/qvector3d.h> -#include <cmath> +#include <qmath.h> #include "3rdparty/fbm.h" @@ -868,11 +868,12 @@ void Scene::renderCubemaps() QVector3D center; + const float eachAngle = 2 * M_PI / m_cubemaps.size(); for (int i = m_frame % N; i < m_cubemaps.size(); i += N) { if (0 == m_cubemaps[i]) continue; - float angle = 2.0f * PI * i / m_cubemaps.size(); + float angle = i * eachAngle; center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f)); diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h index a2ba1d0b5a..ccb6f368cd 100644 --- a/examples/widgets/graphicsview/boxes/scene.h +++ b/examples/widgets/graphicsview/boxes/scene.h @@ -63,8 +63,6 @@ #include "glbuffers.h" #include "qtbox.h" -#define PI 3.14159265358979 - QT_BEGIN_NAMESPACE class QMatrix4x4; QT_END_NAMESPACE diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp index 15f3af77d1..794ce7ac37 100644 --- a/examples/widgets/graphicsview/boxes/trackball.cpp +++ b/examples/widgets/graphicsview/boxes/trackball.cpp @@ -50,6 +50,7 @@ #include "trackball.h" #include "scene.h" +#include <qmath.h> #include <cmath> //============================================================================// @@ -101,10 +102,11 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation) case Plane: { QLineF delta(m_lastPos, p); - m_angularVelocity = 180*delta.length() / (PI*msecs); + const float angleDelta = qRadiansToDegrees(float(delta.length())); + m_angularVelocity = angleDelta / msecs; m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized(); m_axis = transformation.rotatedVector(m_axis); - m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation; + m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angleDelta) * m_rotation; } break; case Sphere: @@ -124,7 +126,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation) currentPos3D.normalize(); m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D); - float angle = 180 / PI * std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis))); + float angle = qRadiansToDegrees(std::asin(m_axis.length())); m_angularVelocity = angle / msecs; m_axis.normalize(); |