summaryrefslogtreecommitdiffstats
path: root/src/datavis3d/utils
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-08-12 10:01:53 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-08-12 10:05:26 +0300
commitfd01da8d39f74b5a624ffebab0927f8a259aeac7 (patch)
tree12344eb81ab998fbc4a56f4c3f79e65147f7c0f8 /src/datavis3d/utils
parent2b8e387e4f7be174f96ca6cfe7d7a99aabb7ec4a (diff)
Replaced sins and cos's with q -versions
+ replaced qFabs with qAbs where applicable Change-Id: Icea0953a29ffb8f779479d4c26cd385c2535ce8d Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavis3d/utils')
-rw-r--r--src/datavis3d/utils/camerahelper.cpp28
-rw-r--r--src/datavis3d/utils/utils.cpp20
-rw-r--r--src/datavis3d/utils/vertexindexer.cpp2
3 files changed, 22 insertions, 28 deletions
diff --git a/src/datavis3d/utils/camerahelper.cpp b/src/datavis3d/utils/camerahelper.cpp
index 4523ee9a..39753317 100644
--- a/src/datavis3d/utils/camerahelper.cpp
+++ b/src/datavis3d/utils/camerahelper.cpp
@@ -94,10 +94,10 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom,
int screenWidth, int screenHeight, bool showUnder)
{
QMatrix4x4 viewMatrix;
- GLint lowerLimit = 0;
+ GLfloat lowerLimit = 0.0f;
if (showUnder)
- lowerLimit = -90;
+ lowerLimit = -90.0f;
// Calculate mouse movement since last frame
GLfloat mouseMoveX = GLfloat(m_previousMousePos.x() - mousePos.x())
@@ -108,10 +108,10 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom,
m_xRotation -= mouseMoveX;
m_yRotation -= mouseMoveY;
// Reset at 360 in x and limit to 0...90 in y
- if (qFabs(m_xRotation) >= 360)
- m_xRotation = 0;
- if (m_yRotation >= 90)
- m_yRotation = 90;
+ if (qAbs(m_xRotation) >= 360.0f)
+ m_xRotation = 0.0f;
+ if (m_yRotation >= 90.0f)
+ m_yRotation = 90.0f;
else if (m_yRotation <= lowerLimit)
m_yRotation = lowerLimit;
@@ -121,8 +121,8 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom,
viewMatrix.translate(m_target.x(), m_target.y(), m_target.z());
// Apply rotations
// Handle x and z rotation when y -angle is other than 0
- viewMatrix.rotate(m_xRotation, 0, cos(qDegreesToRadians(m_yRotation)),
- sin(qDegreesToRadians(m_yRotation)));
+ viewMatrix.rotate(m_xRotation, 0, qCos(qDegreesToRadians(m_yRotation)),
+ qSin(qDegreesToRadians(m_yRotation)));
// y rotation is always "clean"
viewMatrix.rotate(m_yRotation, 1.0f, 0.0f, 0.0f);
// handle zoom by scaling
@@ -131,11 +131,6 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(const QPoint &mousePos, int zoom,
viewMatrix.translate(-m_target.x(), -m_target.y(), -m_target.z());
//qDebug() << m_xRotation << m_yRotation;
- //qDebug() << "sin(m_yRotation)" << sin(qDegreesToRadians(m_yRotation));
- //qDebug() << "asin(m_yRotation)" << asin(qDegreesToRadians(m_yRotation));
- //qDebug() << "cos(m_yRotation)" << cos(qDegreesToRadians(m_yRotation));
- //qDebug() << "tan(m_yRotation)" << tan(qDegreesToRadians(m_yRotation));
-
m_previousMousePos = mousePos;
return viewMatrix;
}
@@ -156,11 +151,10 @@ QVector3D CameraHelper::calculateLightPosition(const QVector3D &lightPosition,
yAngle = 0;
}
GLfloat radius = (radiusFactor + lightPosition.y()); // set radius to match the highest height of the light
- GLfloat zPos = radius * cos(xAngle) * cos(yAngle);
- GLfloat xPos = radius * sin(xAngle) * cos(yAngle);
- GLfloat yPos = (radiusFactor + lightPosition.y()) * sin(yAngle);
+ GLfloat zPos = radius * qCos(xAngle) * qCos(yAngle);
+ GLfloat xPos = radius * qSin(xAngle) * qCos(yAngle);
+ GLfloat yPos = (radiusFactor + lightPosition.y()) * qSin(yAngle);
// Keep light in the set position in relation to camera
- // TODO: Does not work perfectly yet; Light seems wrong when viewing scene from sides (or isometrically)
newLightPosition = QVector3D(-xPos + lightPosition.x(),
yPos + lightPosition.y(),
zPos + lightPosition.z());
diff --git a/src/datavis3d/utils/utils.cpp b/src/datavis3d/utils/utils.cpp
index 3ab5b4f8..25314e31 100644
--- a/src/datavis3d/utils/utils.cpp
+++ b/src/datavis3d/utils/utils.cpp
@@ -110,23 +110,23 @@ void Utils::printText(QPainter *painter, const QString &text, const QSize &posit
if (absoluteCoords) {
// This assumes absolute screen coordinates
painter->translate(position.width() - (((float)bgrStrLen / 2.0f)
- * cos(qDegreesToRadians(rotation)))
- + (((float)bgrHeight / 2.0f) * sin(qDegreesToRadians(rotation))),
+ * qCos(qDegreesToRadians(rotation)))
+ + (((float)bgrHeight / 2.0f) * qSin(qDegreesToRadians(rotation))),
position.height()
- - ((((float)bgrHeight / 2.0f) * cos(qDegreesToRadians(rotation)))
- + (((float)bgrStrLen / 2.0f) * sin(qDegreesToRadians(rotation)))));
+ - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation)))
+ + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation)))));
} else {
// This calculates y as a distance from screen bottom
painter->translate(position.width() - (((float)bgrStrLen / 2.0f)
- * cos(qDegreesToRadians(rotation)))
- + (((float)bgrHeight / 2.0f) * sin(qDegreesToRadians(rotation))),
+ * qCos(qDegreesToRadians(rotation)))
+ + (((float)bgrHeight / 2.0f) * qSin(qDegreesToRadians(rotation))),
painter->window().height() - position.height()
- - ((((float)bgrHeight / 2.0f) * cos(qDegreesToRadians(rotation)))
- + (((float)bgrStrLen / 2.0f) * sin(qDegreesToRadians(rotation)))));
+ - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation)))
+ + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation)))));
}
//qDebug() << painter->window().height() - position.height()
- // - ((((float)bgrHeight / 2.0f) * cos(qDegreesToRadians(rotation)))
- // + (((float)bgrStrLen / 2.0f) * sin(qDegreesToRadians(rotation))));
+ // - ((((float)bgrHeight / 2.0f) * qCos(qDegreesToRadians(rotation)))
+ // + (((float)bgrStrLen / 2.0f) * qSin(qDegreesToRadians(rotation))));
painter->rotate(rotation);
painter->drawText(0, 0,
bgrStrLen, bgrHeight,
diff --git a/src/datavis3d/utils/vertexindexer.cpp b/src/datavis3d/utils/vertexindexer.cpp
index 1d03d4c8..99c0a139 100644
--- a/src/datavis3d/utils/vertexindexer.cpp
+++ b/src/datavis3d/utils/vertexindexer.cpp
@@ -53,7 +53,7 @@ int unique_vertices = 0;
// Returns true if v1 can be considered equal to v2
bool VertexIndexer::is_near(float v1, float v2)
{
- return qFabs(v1 - v2) < 0.01f;
+ return qAbs(v1 - v2) < 0.01f;
}
// Searches through all already-exported vertices