Qt-interest Archive, August 2007
OpenGL Perspective QTransform Issue
Message 1 in thread
I am rendering a QGraphicsPixmapItem in a QGraphicsScene in a QGraphicsView.
The QGraphicsView uses a QGLWidget viewport.
I am trying to rotate an image around its Y-axis but from 72
degrees until 102 degrees the image disappears.
So the image's perspective rotation around the Y-axis is as follows:
* 0 -> 71 degrees: visible
* 72 -> 102 degrees: INVISIBLE
* 103 -> 180 degrees: visible
Also noteworthy: At certain degrees I see just one pixel (at 79
degrees and at 101 degrees)
Screenshot of the application to give you an idea of the kind of
perspective transformation I am trying to do:
http://wesley.debianbox.be/images/SlideFlowDevelopment.png
(left part of the screen)
The following code is an example project that illustrates my problem.
It is also available as a tar.gz package here:
http://wesley.debianbox.be/files/RotationProblem.tar.gz
Pastebin version is here: http://qtnode.net/index.php/pastebin/4453
//////// main.cpp ////////
#include <QApplication>
#include "test.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
test *t = new test();
t->show();
return app.exec();
}
//////// test.h ////////
#include <QWidget>
class QGraphicsScene;
class QGraphicsPixmapItem;
class QGraphicsView;
class test : public QWidget
{
Q_OBJECT
public:
test(QWidget *parent = 0);
private:
qreal xx, yy;
QGraphicsView *view;
QGraphicsScene *sscene;
QGraphicsPixmapItem *one;
private slots:
void tl2(int frame);
};
//////// test.cpp ////////
#include <QtGui>
#include <QtOpenGL>
#include "test.h"
const char *IMAGE = "test.png"; // image to use
test::test(QWidget *parent) : QWidget(parent)
{
xx = yy = 0.0;
setWindowModality(Qt::NonModal);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
resize(500, 500);
sscene = new QGraphicsScene(this);
view = new QGraphicsView(this);
QGLWidget *glw = new QGLWidget();
view->resize(450, 450);
view->setViewport(glw);
view->setScene(sscene);
view->setBackgroundBrush(Qt::black);
QVBoxLayout *vbox = new QVBoxLayout();
QPalette palette;
QBrush brush(QColor(0, 0, 0, 255));
brush.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Window, brush);
palette.setBrush(QPalette::Inactive, QPalette::Window, brush);
palette.setBrush(QPalette::Disabled, QPalette::Window, brush);
setPalette(palette);
vbox->addWidget(view);
setLayout(vbox);
one = sscene->addPixmap(QPixmap(IMAGE).scaled(view->width()-10,
view->height(), Qt::KeepAspectRatio));
one->setPos((view->width()-one->sceneBoundingRect().width())/2,
(view->height()-one->sceneBoundingRect().height())/2);
view->setSceneRect(sscene->itemsBoundingRect());
QTimeLine *time = new QTimeLine(7000);
time->setFrameRange(0, 180);
time->setUpdateInterval(20);
connect(time, SIGNAL(frameChanged(int)), this, SLOT(tl2(int)));
time->start();
}
void test::tl2(int frame)
{
QTransform t, t1, t2;
if (xx == 0.0) xx = one->sceneBoundingRect().width()/2;
if (yy == 0.0) yy = one->sceneBoundingRect().height()/2;
t1.translate(-xx, -yy);
t1.rotate(frame, Qt::YAxis);
t2.translate(xx, yy);
t = t1 * t2;
one->setTransform(t);
}
//////// test.pro ////////
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += test.h
SOURCES += main.cpp test.cpp
QT += opengl
--
[ signature omitted ]
Message 2 in thread
I haven't used QGraphicsView with OpenGL yet, so i might be totally off,
but this comes to my mind: did you check your near clip plane? if an
edge of the rotating quad gets too close to the camera it might get
clipped.
Cheers,
Peter
gogogowesley wrote:
> I am rendering a QGraphicsPixmapItem in a QGraphicsScene in a
> QGraphicsView.
> The QGraphicsView uses a QGLWidget viewport.
>
> I am trying to rotate an image around its Y-axis but from 72
> degrees until 102 degrees the image disappears.
> So the image's perspective rotation around the Y-axis is as
follows:
> * 0 -> 71 degrees: visible
> * 72 -> 102 degrees: INVISIBLE
> * 103 -> 180 degrees: visible
>
--
[ signature omitted ]
Message 3 in thread
gogogowesley wrote:
>
> 2007/8/9, Peter Prade <prade@xxxxxxxxxxx>:
> > I haven't used QGraphicsView with OpenGL yet, so i might be totally
off,
> > but this comes to my mind: did you check your near clip plane? if an
> > edge of the rotating quad gets too close to the camera it might get
> > clipped.
> >
>
> Does anyone know how I should fix that? This is not pure OpenGL.
you probably wanted to write to the list, not to me in private.
i have no clue, but if i had to debug this, i'd try to give the quad a
different "depth" position.
Cheers,
Peter
--
[ signature omitted ]