Setting up UI and selected cube texture change

This commit is contained in:
Dmitri K 2016-12-02 16:21:18 -05:00
parent 7510788533
commit 2c06d4374d
2 changed files with 64 additions and 6 deletions

View File

@ -177,13 +177,13 @@ void Viewer::draw()
void Viewer::drawUi(){ void Viewer::drawUi(){
glCullFace(GL_FRONT); glCullFace(GL_BACK);
glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top
QMatrix4x4 projectionMatrix; QMatrix4x4 projectionMatrix;
QMatrix4x4 uiViewMatrix; QMatrix4x4 uiViewMatrix;
uiViewMatrix.translate(0, -1.5, -4); uiViewMatrix.translate(0, -1.45, -4);
camera()->getProjectionMatrix(projectionMatrix); camera()->getProjectionMatrix(projectionMatrix);
float colorMult = 0.2 + std::fabs(0.8 * cos(std::fmod(angle_mult * frame + 300, 360) / 360 * M_PI)); float colorMult = 0.2 + std::fabs(0.8 * cos(std::fmod(angle_mult * frame + 300, 360) / 360 * M_PI));
@ -199,9 +199,13 @@ void Viewer::drawUi(){
{ {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
TexturePrograms[i]->bind(); TexturePrograms[i]->bind();
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
uiViewMatrix.translate(1.2, 0, 0); uiViewMatrix.translate(1.2, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 36); if(i == selectedTexture)
uiViewMatrix.scale(1.2);
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
glDrawArrays(GL_TRIANGLES, 0, 6);
if(i == selectedTexture)
uiViewMatrix.scale(1/1.2);
} }
} }
@ -247,7 +251,9 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
container->addChild(c); container->addChild(c);
root.addChild(container); root.addChild(container);
} }
else QGLViewer::mousePressEvent(e); else{
QGLViewer::mousePressEvent(e);
}
} }
void Viewer::mouseReleaseEvent(QMouseEvent* e) { void Viewer::mouseReleaseEvent(QMouseEvent* e) {
@ -259,6 +265,56 @@ void Viewer::mouseReleaseEvent(QMouseEvent* e) {
QGLViewer::mouseReleaseEvent(e); QGLViewer::mouseReleaseEvent(e);
} }
void Viewer::keyPressEvent(QKeyEvent* e) {
switch ( e->key() ) {
case Qt::Key_W:
break;
case Qt::Key_A:
break;
case Qt::Key_S:
break;
case Qt::Key_D:
break;
case Qt::Key_Q:
break;
case Qt::Key_E:
break;
case Qt::Key_1: // 0x31; yaay, fall-through cases!
case Qt::Key_2: // 0x32
case Qt::Key_3: // 0x33
case Qt::Key_4: // 0x34
case Qt::Key_5: // 0x35
case Qt::Key_6: // 0x36
selectedTexture = e->key() - 0x31;
if(selectedObj.shape != nullptr ){
selectedObj.shape->setType(selectedTexture);
}
break;
default: e->ignore(); break;
}
}
void Viewer::keyReleaseEvent(QKeyEvent* e){
switch ( e->key() ) {
case Qt::Key_W:
break;
case Qt::Key_A:
break;
case Qt::Key_S:
break;
case Qt::Key_D:
break;
case Qt::Key_Q:
break;
case Qt::Key_E:
break;
default: e->ignore(); break;
}
}
void Viewer::init() void Viewer::init()
{ {
identityMatrix.setToIdentity(); identityMatrix.setToIdentity();
@ -270,6 +326,7 @@ void Viewer::init()
showEntireScene(); showEntireScene();
// Init OpenGL objects // Init OpenGL objects
//setMouseBinding(Qt::NoModifier, Qt::LeftButton, CAMERA, LOOK_AROUND, true);
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &Viewer::cleanup); connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &Viewer::cleanup);
initializeOpenGLFunctions(); initializeOpenGLFunctions();
@ -469,7 +526,6 @@ void Viewer::initShaders()
}//*/ }//*/
} }
// Creates the basic shapes in memory. We only have 3, so we just prep them all in advance.
void Viewer::initGeometries() void Viewer::initGeometries()
{ {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View File

@ -95,6 +95,8 @@ protected :
virtual void mouseMoveEvent(QMouseEvent* e); virtual void mouseMoveEvent(QMouseEvent* e);
virtual void mouseReleaseEvent(QMouseEvent* e); virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void mousePressEvent(QMouseEvent *e); virtual void mousePressEvent(QMouseEvent *e);
virtual void keyPressEvent(QKeyEvent *);
virtual void keyReleaseEvent(QKeyEvent *);
SceneGroup root; SceneGroup root;
std::stack<QMatrix4x4> modelStack; std::stack<QMatrix4x4> modelStack;