summaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/graphicsview')
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp4
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp5
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h2
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp8
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.cpp15
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.cpp17
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.cpp28
7 files changed, 32 insertions, 47 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();
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp
index b94c650c18..298e4aae64 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.cpp
+++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp
@@ -53,11 +53,10 @@
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
+#include <qmath.h>
-#include <math.h>
-
-static const double Pi = 3.14159265358979323846264338327950288419717;
-static double TwoPi = 2.0 * Pi;
+const qreal Pi = M_PI;
+const qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@@ -140,9 +139,7 @@ void Mouse::advance(int step)
//! [5]
QLineF lineToCenter(QPointF(0, 0), mapFromScene(0, 0));
if (lineToCenter.length() > 150) {
- qreal angleToCenter = ::acos(lineToCenter.dx() / lineToCenter.length());
- if (lineToCenter.dy() < 0)
- angleToCenter = TwoPi - angleToCenter;
+ qreal angleToCenter = std::atan2(lineToCenter.dy(), lineToCenter.dx());
angleToCenter = normalizeAngle((Pi - angleToCenter) + Pi / 2);
if (angleToCenter < Pi && angleToCenter > Pi / 4) {
@@ -171,9 +168,7 @@ void Mouse::advance(int step)
continue;
QLineF lineToMouse(QPointF(0, 0), mapFromItem(item, 0, 0));
- qreal angleToMouse = ::acos(lineToMouse.dx() / lineToMouse.length());
- if (lineToMouse.dy() < 0)
- angleToMouse = TwoPi - angleToMouse;
+ qreal angleToMouse = std::atan2(lineToMouse.dy(), lineToMouse.dx());
angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp
index 012b9ea2ed..88160d9399 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp
@@ -51,13 +51,10 @@
#include "arrow.h"
-#include <math.h>
-
+#include <qmath.h>
#include <QPen>
#include <QPainter>
-const qreal Pi = 3.14;
-
//! [0]
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
: QGraphicsLineItem(parent)
@@ -132,14 +129,12 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
setLine(QLineF(intersectPoint, myStartItem->pos()));
//! [5] //! [6]
- double angle = ::acos(line().dx() / line().length());
- if (line().dy() >= 0)
- angle = (Pi * 2) - angle;
+ double angle = std::atan2(-line().dy(), line().dx());
- QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
- cos(angle + Pi / 3) * arrowSize);
- QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
- cos(angle + Pi - Pi / 3) * arrowSize);
+ QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize,
+ cos(angle + M_PI / 3) * arrowSize);
+ QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
+ cos(angle + M_PI - M_PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp
index e794e803cf..aec12b4225 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp
@@ -51,13 +51,9 @@
#include "edge.h"
#include "node.h"
-#include <math.h>
-
+#include <qmath.h>
#include <QPainter>
-static const double Pi = 3.14159265358979323846264338327950288419717;
-static double TwoPi = 2.0 * Pi;
-
//! [0]
Edge::Edge(Node *sourceNode, Node *destNode)
: arrowSize(10)
@@ -139,18 +135,16 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
//! [6]
// Draw the arrows
- double angle = ::acos(line.dx() / line.length());
- if (line.dy() >= 0)
- angle = TwoPi - angle;
-
- QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize,
- cos(angle + Pi / 3) * arrowSize);
- QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
- cos(angle + Pi - Pi / 3) * arrowSize);
- QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize,
- cos(angle - Pi / 3) * arrowSize);
- QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize,
- cos(angle - Pi + Pi / 3) * arrowSize);
+ double angle = std::atan2(-line.dy(), line.dx());
+
+ QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + M_PI / 3) * arrowSize,
+ cos(angle + M_PI / 3) * arrowSize);
+ QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
+ cos(angle + M_PI - M_PI / 3) * arrowSize);
+ QPointF destArrowP1 = destPoint + QPointF(sin(angle - M_PI / 3) * arrowSize,
+ cos(angle - M_PI / 3) * arrowSize);
+ QPointF destArrowP2 = destPoint + QPointF(sin(angle - M_PI + M_PI / 3) * arrowSize,
+ cos(angle - M_PI + M_PI / 3) * arrowSize);
painter->setBrush(Qt::black);
painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);