Commit 0122e0aa by Alisa Jung

active viewport highlighting

parent 5df31a29
...@@ -35,7 +35,11 @@ void Controller::showSingleView(){ ...@@ -35,7 +35,11 @@ void Controller::showSingleView(){
views[i]->hide(); views[i]->hide();
} }
views[0]->show(); views[0]->show();
views[currentWidgetIndex]->setFocused(false);
currentWidgetIndex = 0; currentWidgetIndex = 0;
views[currentWidgetIndex]->setFocused(true);
} }
void Controller::showDoubleView(){ void Controller::showDoubleView(){
...@@ -49,7 +53,11 @@ void Controller::showDoubleView(){ ...@@ -49,7 +53,11 @@ void Controller::showDoubleView(){
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
views[i]->show(); views[i]->show();
} }
if (currentWidgetIndex > 1) currentWidgetIndex = 0; if (currentWidgetIndex > 1) {
views[currentWidgetIndex]->setFocused(false);
currentWidgetIndex = 0;
views[currentWidgetIndex]->setFocused(true);
}
} }
void Controller::showQuadView(){ void Controller::showQuadView(){
...@@ -98,7 +106,12 @@ void Controller::processMousePressEvent(QMouseEvent *event, MyGLWidget *widget){ ...@@ -98,7 +106,12 @@ void Controller::processMousePressEvent(QMouseEvent *event, MyGLWidget *widget){
leftButtonPressed = true; leftButtonPressed = true;
lastClickPosition = event->pos(); lastClickPosition = event->pos();
} }
currentWidgetIndex = widget->getIndex(); if (currentWidgetIndex != widget->getIndex()){
qDebug("Mouse Press event with other index");
views[currentWidgetIndex]->setFocused(false);
currentWidgetIndex = widget->getIndex();
views[currentWidgetIndex]->setFocused(true);
}
} }
void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){ void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-10T14:37:55. --> <!-- Written by QtCreator 3.5.1, 2015-11-15T21:45:35. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -19,8 +19,7 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion ...@@ -19,8 +19,7 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion
rightButtonPressed = false; rightButtonPressed = false;
controller = c; controller = c;
this->isPerspective = isPerspective; this->isPerspective = isPerspective;
this->isFocused = isPerspective; //start with focus on perspective view
setStyleSheet(" border:3px solid rgb(255, 255, 0); ");
} }
MyGLWidget::~MyGLWidget() MyGLWidget::~MyGLWidget()
...@@ -137,25 +136,8 @@ void MyGLWidget::paintGL(){ ...@@ -137,25 +136,8 @@ void MyGLWidget::paintGL(){
//cam rotation //cam rotation
QMatrix4x4 camRot = QMatrix4x4(); QMatrix4x4 camRot = QMatrix4x4();
camRot.rotate(cameraRotation); camRot.rotate(cameraRotation);
//for cube rotation
QMatrix4x4 m = QMatrix4x4();
m.rotate(qubeRotation);
//for cube translation
QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,cubeTranslation.x(),0,1,0,cubeTranslation.y(),0,0,1,cubeTranslation.z(),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);
// //zoom camera
// glTranslatef(0,0,cameraZoom);//Kamera sitzt sonst in (0,0,0) und man sieht nichts (duh)
// glTranslatef(cameraX,cameraY,0);//TODO anständig machen, kamerarotation fehlt noch.
//So scheint das zumindest für die Kamera zu funktionieren: //So scheint das zumindest für die Kamera zu funktionieren:
//1. ins Rotationszentrum verschieben - Wenn Rotationszentrum geändert wird, schon rotation berücksichtigen //1. ins Rotationszentrum verschieben - Wenn Rotationszentrum geändert wird, schon rotation berücksichtigen
//2. Rotieren //2. Rotieren
...@@ -165,6 +147,13 @@ void MyGLWidget::paintGL(){ ...@@ -165,6 +147,13 @@ void MyGLWidget::paintGL(){
glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z()); glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z());
//for cube rotation
QMatrix4x4 m = QMatrix4x4();
m.rotate(qubeRotation);
//for cube translation
QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,cubeTranslation.x(),0,1,0,cubeTranslation.y(),0,0,1,cubeTranslation.z(),0,0,0,1);
//stack matrices //stack matrices
glMultMatrixf(translateRot1.data());//Punkte zurück schieben damit rotation um qube zentrum ist glMultMatrixf(translateRot1.data());//Punkte zurück schieben damit rotation um qube zentrum ist
glMultMatrixf(m.data()); glMultMatrixf(m.data());
...@@ -276,13 +265,59 @@ void MyGLWidget::paintGL(){ ...@@ -276,13 +265,59 @@ void MyGLWidget::paintGL(){
} }
glEnd(); glEnd();
} }
//has to be down here or will be overpainted by above code
if (isFocused) highlightViewport();
}
void MyGLWidget::setFocused(bool isFocused){
this->isFocused = isFocused;
updateGL();
}
void MyGLWidget::highlightViewport(){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1,1,-1,1, -1, 1);//to draw yellow rectangle in screen coordinates
GLfloat specularColor[] = {1,1,1};
GLfloat shininess[] = {128};//specular exponent
glMaterialfv(GL_FRONT,GL_SPECULAR,specularColor);
glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
GLfloat yellow[] = {1,1,0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,yellow);
glNormal3f(0,0,1);
glDisable(GL_DEPTH_TEST);
glLineWidth(15.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(1,1);
glVertex2f(1,-1);
glVertex2f(-1,-1);
glVertex2f(-1,1);
glEnd();
glEnable(GL_DEPTH_TEST);
resetProjectionMatrix();
} }
void MyGLWidget::resizeGL(int width, int height){ void MyGLWidget::resizeGL(int width, int height){
double p = (double)width / (double)height; windowWidth = width;
qDebug() << "Resize to " << width << "," << height << ", Perspective: " << p; windowHeight = height;
qDebug() << "Resize to " << width << "," << height << ", Perspective: " << (double)windowWidth / (double)windowHeight;
glViewport(0,0,width,height); glViewport(0,0,width,height);
resetProjectionMatrix();
controller->setScreenScenter(QPoint((double)width/2.0,(double)height/2.0));//lieber zu oft casten bevors nicht tut...
}
void MyGLWidget::resetProjectionMatrix(){
double p = (double)windowWidth / (double)windowHeight;
glMatrixMode(GL_PROJECTION);//from HelloGL example glMatrixMode(GL_PROJECTION);//from HelloGL example
glLoadIdentity(); glLoadIdentity();
...@@ -294,7 +329,6 @@ void MyGLWidget::resizeGL(int width, int height){ ...@@ -294,7 +329,6 @@ void MyGLWidget::resizeGL(int width, int height){
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
controller->setScreenScenter(QPoint((double)width/2.0,(double)height/2.0));//lieber zu oft casten bevors nicht tut...
} }
void MyGLWidget::mousePressEvent(QMouseEvent *event){ void MyGLWidget::mousePressEvent(QMouseEvent *event){
...@@ -318,30 +352,6 @@ void MyGLWidget::keyReleaseEvent(QKeyEvent *event){ ...@@ -318,30 +352,6 @@ void MyGLWidget::keyReleaseEvent(QKeyEvent *event){
} }
} }
void MyGLWidget::paintEvent(QPaintEvent *pe)
{
//reaaaaally weird:
// QStyleOption o;
// o.initFrom(this);
// QPainter p(this);
// style()->drawPrimitive(
// QStyle::PE_Widget, &o, &p, this);
//even weider:
// QStyleOption opt;
// opt.init(this);
// QStylePainter p(this);
// p.drawPrimitive(QStyle::PE_Widget, opt);
//Anyway, the internet tells me I need to do something here in Order to use the style sheet
//and I didn't find any other plausible option to add a border to the selected view.
//A little hint on the assignment would have helped a great deal here...
//need this to actually draw gl stuff
QGLWidget::paintEvent(pe);
};
void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff) void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff)
{ {
//in order to "move parallel to image plane", we have to rotate the image coordinates xDiff and yDiff by our current camera rotation. //in order to "move parallel to image plane", we have to rotate the image coordinates xDiff and yDiff by our current camera rotation.
......
...@@ -41,6 +41,7 @@ class MyGLWidget : public QGLWidget ...@@ -41,6 +41,7 @@ class MyGLWidget : public QGLWidget
void initShaderStuff(); void initShaderStuff();
int getIndex(); int getIndex();
void setFocused(bool isFocused);//Tell view if it is focused and therefore needs a yellow border
protected: protected:
//4.1 Core Functionality //4.1 Core Functionality
...@@ -50,9 +51,8 @@ protected: ...@@ -50,9 +51,8 @@ protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent * event); void keyPressEvent(QKeyEvent * event);//for ctrl key for mode switch
void keyReleaseEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event);//for ctrl key for mode switch
void paintEvent(QPaintEvent *event);
Controller* controller; Controller* controller;
...@@ -84,7 +84,10 @@ private: ...@@ -84,7 +84,10 @@ private:
QGLShaderProgram *phongShader; QGLShaderProgram *phongShader;
void highlightViewport();
void resetProjectionMatrix();
double windowWidth, windowHeight;
bool isFocused;
public slots: public slots:
//4.1.1 slots for shading modes //4.1.1 slots for shading modes
......
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