Commit 229da88d by Kai Westerkamp

for Desktop

parent 450e6140
...@@ -23,6 +23,7 @@ void CubeWidget::initializeGL () ...@@ -23,6 +23,7 @@ void CubeWidget::initializeGL ()
tesselation = 0; tesselation = 0;
// enable default shading // enable default shading
home();
showFlat(); showFlat();
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
...@@ -42,9 +43,11 @@ void CubeWidget::paintGL ( ) ...@@ -42,9 +43,11 @@ void CubeWidget::paintGL ( )
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0f,0.0f,-3.0f); glTranslatef(0.0f,0.0f,-zoom);
glRotated(45,1,0,0); QMatrix4x4 mat = QMatrix4x4();
glRotated(45,0,1,0); mat.rotate(*rotation);
glMultMatrixf(mat.data());
GLfloat red[] = {1.0,0.0,0.0}; GLfloat red[] = {1.0,0.0,0.0};
...@@ -67,12 +70,7 @@ void CubeWidget::paintGL ( ) ...@@ -67,12 +70,7 @@ void CubeWidget::paintGL ( )
} }
} }
setMaterial(magenta); setMaterial(magenta);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, -0.5f,y+increment); glVertex3f( x+increment, -0.5f,y+increment);
...@@ -132,7 +130,7 @@ void CubeWidget::resizeGL(int width , int height ) ...@@ -132,7 +130,7 @@ void CubeWidget::resizeGL(int width , int height )
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glLoadIdentity(); glLoadIdentity();
perspective(45.0,1.0*width/height,0.01,5.0); perspective(45.0,1.0*width/height,0.01,100.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }
...@@ -193,6 +191,29 @@ void CubeWidget::setTessellation(int t) ...@@ -193,6 +191,29 @@ void CubeWidget::setTessellation(int t)
qDebug()<<"Tesselation" << t; qDebug()<<"Tesselation" << t;
} }
void CubeWidget::mousePressEvent(QMouseEvent *event ) {} void CubeWidget::home()
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {} {
void CubeWidget::wheelEvent(QWheelEvent *event ) {} zoom = 3;
rotation = new QQuaternion();
updateGL();
}
void CubeWidget::mousePressEvent(QMouseEvent *event )
{
}
void CubeWidget::mouseMoveEvent(QMouseEvent *event )
{
//http://web.cse.ohio-state.edu/~hwshen/781/Site/Slides_files/trackball.pdf
}
void CubeWidget::wheelEvent(QWheelEvent *event )
{
if(event->delta()<0)
zoom++;
else
zoom--;
updateGL();
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <QGLFunctions> #include <QGLFunctions>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <math.h> #include <math.h>
#include <QMatrix4x4>
#include <QQuaternion>
...@@ -31,11 +33,15 @@ public slots: ...@@ -31,11 +33,15 @@ public slots:
void showFlat(); void showFlat();
void showGouraut(); void showGouraut();
void showPhong(); void showPhong();
void home();
void setTessellation(int t ); void setTessellation(int t );
private: private:
int tesselation; int tesselation;
int zoom;
QQuaternion *rotation;
QPoint *lastPos;
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
void setMaterial(GLfloat *color ); void setMaterial(GLfloat *color );
}; };
......
...@@ -60,6 +60,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -60,6 +60,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox())); connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox()));
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar); camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
connect(camHome, SIGNAL(triggered(bool)),mainWidget,SLOT(home()));
slider = new QSlider(Qt::Horizontal,toolBar); slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 ); slider->setMinimum( 0 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment