diff options
author | Rainer Keller <rainer.keller@nokia.com> | 2011-05-16 14:12:41 +0200 |
---|---|---|
committer | Rainer Keller <rainer.keller@nokia.com> | 2011-05-16 14:15:06 +0200 |
commit | 7ba61af09678127861e33931e741ebbf9b002385 (patch) | |
tree | 9e957db97d1a676fb504e63dafa6646e71215d9d | |
parent | 2d3b42d376c2d2137a5fb1b163d7ce30aa8a4584 (diff) |
Remove dependency to glu
Done-with: ckamm
-rw-r--r-- | src/ui/accelerometercontrol.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/ui/accelerometercontrol.cpp b/src/ui/accelerometercontrol.cpp index b9ebb97..4f43a86 100644 --- a/src/ui/accelerometercontrol.cpp +++ b/src/ui/accelerometercontrol.cpp @@ -39,6 +39,7 @@ #include <QtCore/QDir> #include <QtGui/QMatrix4x4> #include <QtGui/QMouseEvent> +#include <QtGui/QVector3D> static QVector3D accelerometerX(-1, 0, 0); static QVector3D accelerometerY(0, 1, 0); @@ -114,20 +115,70 @@ void AccelerometerControl::initializeGL() mNorthTexture = bindTexture(northImg); } +/* since glu is not available everywhere we need to implement needed functions ourself */ + +static void lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) +{ + QVector3D F(centerX - eyeX, centerY - eyeY, centerZ - eyeZ); + F.normalize(); + + QVector3D UP(upX, upY, upZ); + UP.normalize(); + + QVector3D s = QVector3D::crossProduct(F, UP); + QVector3D u = QVector3D::crossProduct(s, F); + + GLfloat M[16]; + M[0] = s.x(); + M[4] = s.y(); + M[8] = s.z(); + M[12] = 0; + + M[1] = u.x(); + M[5] = u.y(); + M[9] = u.z(); + M[13] = 0; + + M[2] = -F.x(); + M[6] = -F.y(); + M[10] = -F.z(); + M[14] = 0; + + M[3] = 0; + M[7] = 0; + M[11] = 0; + M[15] = 1; + + glMultMatrixf(M); + glTranslatef(-eyeX, -eyeY, -eyeZ); +} + +static void perspective(float fovY, float aspectRatio, float front, float back) +{ + const double DEG2RAD = 3.14159265 / 180; + + double tangent = tan(fovY/2 * DEG2RAD); // tangent of half fovY + double height = front * tangent; // half height of near plane + double width = height * aspectRatio; // half width of near plane + + // params: left, right, bottom, top, near, far + glFrustum(-width, width, -height, height, front, back); +} + void AccelerometerControl::resizeGL(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); qreal aspect = (qreal)w / h; - gluPerspective(45, aspect, 0.1, 10); + perspective(45, aspect, 0.1, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScalef (-1., 1., 1.); // left-handed system, x right, y up, z into - gluLookAt(0.7, 1, -2, - 0, 0, 0, - 0, 1, 0); + lookAt(0.7, 1, -2, + 0, 0, 0, + 0, 1, 0); } void AccelerometerControl::drawMobile() |