summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2011-03-10 07:55:00 (GMT)
committerGunnar Sletta <gunnar.sletta@nokia.com>2011-03-10 08:00:48 (GMT)
commit07fa5bd76e6ecd87ea8f8422ddaec56eb4db2289 (patch)
tree1fbc7b05a672d9ac438389c4c71871e2174c8057 /examples/opengl
parentfe02247a72467f8bd95c0e68c316c1d71f8e0c1e (diff)
downloadQt-07fa5bd76e6ecd87ea8f8422ddaec56eb4db2289.zip
Qt-07fa5bd76e6ecd87ea8f8422ddaec56eb4db2289.tar.gz
Qt-07fa5bd76e6ecd87ea8f8422ddaec56eb4db2289.tar.bz2
Fix PBuffer example to work again
Done by: Trond
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/pbuffers/cube.cpp49
-rw-r--r--examples/opengl/pbuffers/cube.h3
-rw-r--r--examples/opengl/pbuffers/glwidget.cpp2
3 files changed, 36 insertions, 18 deletions
diff --git a/examples/opengl/pbuffers/cube.cpp b/examples/opengl/pbuffers/cube.cpp
index 5bd35e1..631595a 100644
--- a/examples/opengl/pbuffers/cube.cpp
+++ b/examples/opengl/pbuffers/cube.cpp
@@ -46,7 +46,7 @@
static const qreal FACE_SIZE = 0.4;
-static const qreal speeds[] = { 1.8f, 2.4f, 3.6f };
+static const qreal speeds[] = { 3.8f, 4.4f, 5.6f };
static const qreal amplitudes[] = { 2.0f, 2.5f, 3.0f };
static inline void qSetColor(float colorVec[], QColor c)
@@ -197,7 +197,8 @@ Tile *TileBuilder::newTile(const QVector3D &loc) const
Cube::Cube(const QVector3D &loc)
: Tile(loc)
, rot(0.0f)
- , r(0), a(0)
+ , r(0)
+ , animGroup(0)
{
}
@@ -234,8 +235,8 @@ void Cube::setRotation(qreal r)
void Cube::removeBounce()
{
- delete a;
- a = 0;
+ delete animGroup;
+ animGroup = 0;
delete r;
r = 0;
}
@@ -247,8 +248,8 @@ void Cube::startAnimation()
r->start();
r->setCurrentTime(startx);
}
- if (a)
- a->start();
+ if (animGroup)
+ animGroup->start();
if (rtn)
rtn->start();
}
@@ -259,8 +260,8 @@ void Cube::setAnimationPaused(bool paused)
{
if (r)
r->pause();
- if (a)
- a->pause();
+ if (animGroup)
+ animGroup->pause();
if (rtn)
rtn->pause();
}
@@ -268,8 +269,8 @@ void Cube::setAnimationPaused(bool paused)
{
if (r)
r->resume();
- if (a)
- a->resume();
+ if (animGroup)
+ animGroup->resume();
if (rtn)
rtn->resume();
}
@@ -312,13 +313,29 @@ Cube *CubeBuilder::newCube(const QVector3D &loc) const
c->r->setDuration(d * 4.0f);
c->r->setLoopCount(-1);
c->r->setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
+
+ c->animGroup = new QSequentialAnimationGroup(c);
+
// Animate movement from bottom to top
- c->a = new QPropertyAnimation(c, "altitude");
- c->a->setEndValue(loc.y());
- c->a->setStartValue(loc.y() + amplitudes[ix]);
- c->a->setDuration(d / speeds[ix]);
- c->a->setLoopCount(-1);
- c->a->setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
+ QPropertyAnimation *a_up = new QPropertyAnimation(c, "altitude", c->animGroup);
+ a_up->setEndValue(loc.y());
+ a_up->setStartValue(loc.y() + amplitudes[ix]);
+ a_up->setDuration(d / speeds[ix]);
+ a_up->setLoopCount(1);
+ a_up->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
+
+ // Animate movement from top to bottom
+ QPropertyAnimation *a_down = new QPropertyAnimation(c, "altitude", c->animGroup);
+ a_down->setEndValue(loc.y() + amplitudes[ix]);
+ a_down->setStartValue(loc.y());
+ a_down->setDuration(d / speeds[ix]);
+ a_down->setLoopCount(1);
+ a_down->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad));
+
+ c->animGroup->addAnimation(a_up);
+ c->animGroup->addAnimation(a_down);
+ c->animGroup->setLoopCount(-1);
+
// Animate rotation
c->rtn = new QPropertyAnimation(c, "rotation");
c->rtn->setStartValue(c->rot);
diff --git a/examples/opengl/pbuffers/cube.h b/examples/opengl/pbuffers/cube.h
index 2577e76..5c985a3 100644
--- a/examples/opengl/pbuffers/cube.h
+++ b/examples/opengl/pbuffers/cube.h
@@ -43,6 +43,7 @@
#include <QtOpenGL/qgl.h>
#include <QtCore/qvector.h>
+#include <QtCore/qsequentialanimationgroup.h>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector3d.h>
#include <QtGui/qvector2d.h>
@@ -130,8 +131,8 @@ signals:
private:
qreal rot;
QPropertyAnimation *r;
- QPropertyAnimation *a;
QPropertyAnimation *rtn;
+ QSequentialAnimationGroup *animGroup;
qreal startx;
friend class CubeBuilder;
};
diff --git a/examples/opengl/pbuffers/glwidget.cpp b/examples/opengl/pbuffers/glwidget.cpp
index 930cbc8..f6f89e5 100644
--- a/examples/opengl/pbuffers/glwidget.cpp
+++ b/examples/opengl/pbuffers/glwidget.cpp
@@ -135,7 +135,7 @@ void GLWidget::initializeGeometry()
CubeBuilder cBuilder(geom, 0.5);
cBuilder.setColor(QColor(255, 255, 255, 212));
// build the 3 bouncing, spinning cubes
- for (int i = 0; i < 3; ++i)
+ for (int i = 3; i > 0; --i)
cubes.append(cBuilder.newCube(QVector3D((float)(i-1), -1.5f, 5 - i)));
// build the spinning cube which goes in the dynamic texture