mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Merge branch 'master' into obj-loader
This commit is contained in:
commit
45e775b8f9
@ -30,16 +30,16 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
|
||||
if(useNormalMap) {
|
||||
vec3 vNorm = texture(texNormal, texCoords).rgb;
|
||||
nfNormal = -normalize(normalMatrix * vNorm);
|
||||
nfNormal = normalMatrix * normalize(2 * vNorm - 1);
|
||||
} else {
|
||||
nfNormal = normalize(fNorm);
|
||||
}
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
||||
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
vec3 Rl = reflect(LightDirection, nfNormal);
|
||||
vec3 Rl = reflect(-LightDirection, nfNormal);
|
||||
float spec = 0.2*pow(max(0.0, dot(/*normalMatrix */ Rl, nviewDirection)), 64);
|
||||
|
||||
// Compute ambient component
|
||||
@ -60,7 +60,8 @@ vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
|
||||
if(useNormalMap) {
|
||||
vec3 vNorm = texture(texNormal, texCoords).rgb;
|
||||
nfNormal = -normalize(normalMatrix * vNorm);
|
||||
//nfNormal = normalize(normalMatrix * vNorm);
|
||||
nfNormal = normalMatrix * normalize(2 * vNorm - 1);
|
||||
} else {
|
||||
nfNormal = normalize(fNorm);
|
||||
}
|
||||
|
||||
@ -232,13 +232,13 @@ void Viewer::draw()
|
||||
|
||||
void Viewer::drawUi(){
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
glCullFace(GL_BACK);
|
||||
glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top
|
||||
|
||||
QMatrix4x4 projectionMatrix;
|
||||
QMatrix4x4 uiViewMatrix;
|
||||
|
||||
uiViewMatrix.translate(0, -1.5, -4);
|
||||
uiViewMatrix.translate(0, -1.45, -4);
|
||||
camera()->getProjectionMatrix(projectionMatrix);
|
||||
|
||||
float colorMult = 0.2 + std::fabs(0.8 * cos(std::fmod(angle_mult * frame + 300, 360) / 360 * M_PI));
|
||||
@ -254,9 +254,13 @@ void Viewer::drawUi(){
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
TexturePrograms[i]->bind();
|
||||
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -302,7 +306,9 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
||||
container->addChild(c);
|
||||
root.addChild(container);
|
||||
}
|
||||
else QGLViewer::mousePressEvent(e);
|
||||
else{
|
||||
QGLViewer::mousePressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::mouseReleaseEvent(QMouseEvent* e) {
|
||||
@ -314,6 +320,56 @@ void Viewer::mouseReleaseEvent(QMouseEvent* 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()
|
||||
{
|
||||
identityMatrix.setToIdentity();
|
||||
@ -325,6 +381,7 @@ void Viewer::init()
|
||||
showEntireScene();
|
||||
|
||||
// Init OpenGL objects
|
||||
//setMouseBinding(Qt::NoModifier, Qt::LeftButton, CAMERA, LOOK_AROUND, true);
|
||||
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &Viewer::cleanup);
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
@ -524,7 +581,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()
|
||||
{
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@ -95,6 +95,8 @@ protected :
|
||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void keyPressEvent(QKeyEvent *);
|
||||
virtual void keyReleaseEvent(QKeyEvent *);
|
||||
|
||||
SceneGroup root;
|
||||
std::stack<QMatrix4x4> modelStack;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user