Commit b06d9373 by Alisa Jung

layout and splitter. fuck this.

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