Commit b06d9373 by Alisa Jung

layout and splitter. fuck this.

parent 4e889a03
......@@ -75,11 +75,39 @@ MainWindow::MainWindow(QWidget *parent)
statusBar->showMessage("test status message");
setStatusBar(statusBar);
//4.0 Widget
//4.0 Widget //Assignment 2: Multiple Widgets.
controller = new Controller();
myGLWidget = new MyGLWidget(controller,this);
myGLWidget = new MyGLWidget(controller, true, QQuaternion(),this);
setCentralWidget(myGLWidget);
viewFront = new MyGLWidget(controller, false, QQuaternion(0,1,0,0),this);
double costhetahalf = cos(45);
viewLeft = new MyGLWidget(controller, true, QQuaternion(costhetahalf,1,0,0),this);//TODO check rotations.
viewTop = new MyGLWidget(controller, false, QQuaternion(costhetahalf,0,1,0),this);
viewLayout = new QGridLayout(this);
viewSplitter1 = new QSplitter;
viewSplitter1->addWidget(myGLWidget);
viewSplitter1->addWidget(viewFront);
viewSplitter2 = new QSplitter;
viewSplitter2->addWidget(viewLeft);
viewSplitter2->addWidget(viewTop);
viewSplitter3->setOrientation(Qt::Vertical);
viewSplitter3->addWidget(viewSplitter1);
viewSplitter3->addWidget(viewSplitter2);
viewSplitter3 = new QSplitter;
viewLayout->addWidget(viewSplitter3);
QWidget* central_widget = new QWidget(this);
central_widget->setLayout(viewLayout);
setCentralWidget(central_widget);
//4.1.1 connect shading actions to slot
connect(shadeWireframeAction,SIGNAL(triggered(bool)),myGLWidget,SLOT(shadeWireframeSlot()));
connect(shadeFlatAction,SIGNAL(triggered(bool)),myGLWidget,SLOT(shadeFlatSlot()));
......
......@@ -14,6 +14,8 @@
#include <QSlider>
#include <QToolButton>
#include <controller.h>
#include <QLayout>
#include <QSplitter>
class MainWindow : public QMainWindow
{
......@@ -64,6 +66,13 @@ private:
//Widgets
MyGLWidget *myGLWidget;
MyGLWidget *viewFront;
MyGLWidget *viewLeft;
MyGLWidget *viewTop;
QGridLayout *viewLayout;
QSplitter *viewSplitter1;
QSplitter *viewSplitter2;
QSplitter *viewSplitter3;
//4.1.1 Slider
QSlider* tesselationSlider;
......
#include "myglwidget.h"
#include "controller.h"
MyGLWidget::MyGLWidget(Controller* c, QWidget *parent)
MyGLWidget::MyGLWidget(Controller* c, bool isPerspective, QQuaternion initialRotation, QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
MyGLWidget::modeCamera = true;
tesselation = 1;
qubeRotation = QQuaternion();
cameraRotation = QQuaternion();
cameraRotation = initialRotation;
translatex = 0;
translatey = 0;
cameraX = 0;
cameraY = 0;
cameraZ = 0;
camRotCenter = QVector3D(0,0,0);
cameraZoom = cameraZoomDefault;
clickStartPosition = QPoint(0,0);
rightButtonPressed = false;
controller = c;
this->isPerspective = isPerspective;
}
MyGLWidget::~MyGLWidget()
......@@ -128,8 +126,6 @@ void MyGLWidget::paintGL(){
//for cube translation
QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,translatex,0,1,0,translatey,0,0,1,0,0,0,0,1);
QMatrix4x4 translateCamera = QMatrix4x4(1,0,0,cameraX,0,1,0,cameraY,0,0,1,cameraZ,0,0,0,1);
QMatrix4x4 zoomCameraMatrix = QMatrix4x4(1,0,0,0,0,1,0,0,0,0,1,cameraZoom,0,0,0,1);
......@@ -314,9 +310,11 @@ void MyGLWidget::rotateQube(QQuaternion diff){
}
void MyGLWidget::rotateCamera(QQuaternion diff){
if (isPerspective){
cameraRotation = diff*cameraRotation;
cameraRotation.normalize();
updateGL();
}
}
//4.1.2 User Input: Zooming
......@@ -372,9 +370,6 @@ void MyGLWidget::resetCamera(){
qubeRotation = QQuaternion();
translatex = 0;
translatey = 0;
cameraX = 0;
cameraY = 0;
cameraZ = 0;
camRotCenter = QVector3D(0,0,0);
cameraZoom = cameraZoomDefault;
cameraRotation = QQuaternion();
......
......@@ -19,7 +19,8 @@ class MyGLWidget : public QGLWidget
Q_OBJECT //from HelloGL Example
public:
MyGLWidget(Controller* c, QWidget *parent = 0);
//Pass initial camera rotation and isPerspective = false for fixed views
MyGLWidget(Controller* c, bool isPerspective, QQuaternion initalRotation, QWidget *parent = 0);
~MyGLWidget();
//From HelloGL example.
......@@ -48,10 +49,10 @@ protected:
private:
//tesselation slider
int tesselation;
bool isPerspective;
//zoom camera
const double cameraZoomDefault = -5;
double cameraX,cameraY,cameraZ;
double cameraZoom;
QQuaternion cameraRotation;
QVector3D camRotCenter;
......
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