Sphere rotat

This commit is contained in:
unknown 2016-11-10 13:28:46 -05:00
parent 0663336b94
commit 0d23827d81
4 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,7 @@ uniform bool isPhong;
uniform sampler2D tex; uniform sampler2D tex;
uniform float skyMult; uniform float skyMult;
uniform bool drawTextures; uniform bool drawTextures;
uniform bool isLightSource;
in vec3 fNormal; in vec3 fNormal;
in vec3 fPosition; in vec3 fPosition;
@ -22,7 +23,9 @@ main()
} else { } else {
texColor = ifColor; texColor = ifColor;
} }
if(isSky) { if(isLightSource) {
fColor = texColor;
} else if(isSky) {
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2; fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
} else if(isPhong) { } else if(isPhong) {
// Get lighting vectors // Get lighting vectors

View File

@ -3,6 +3,7 @@ uniform mat4 mvMatrix;
uniform mat4 projMatrix; uniform mat4 projMatrix;
uniform mat3 normalMatrix; uniform mat3 normalMatrix;
uniform vec3 lDirection; uniform vec3 lDirection;
uniform bool isLightSource;
uniform vec4 color; uniform vec4 color;
@ -30,7 +31,7 @@ main()
ifColor = color; ifColor = color;
if(!isPhong && !isSky) { if(!isPhong && !isSky && !isLightSource) {
// Get lighting vectors // Get lighting vectors
vec3 LightDirection = normalize(lDirection); vec3 LightDirection = normalize(lDirection);
vec3 nfNormal = normalize(fNormal); vec3 nfNormal = normalize(fNormal);

View File

@ -69,7 +69,7 @@ class SkyboxCamera : public qglviewer::Camera
Viewer::Viewer() Viewer::Viewer()
{ {
activeColor = new QColor(255, 255, 255, 255); activeColor = new QColor(255, 255, 255, 255);
activeCell = nullptr; activeCell = nullptr;
activeShape = 0; activeShape = 0;
angle_mult = 0.1; angle_mult = 0.1;
@ -117,6 +117,7 @@ void Viewer::drawSkybox()
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
m_program->setUniformValue(m_isSkyLoc, true); m_program->setUniformValue(m_isSkyLoc, true);
m_program->setUniformValue(m_drawTextLoc, true); m_program->setUniformValue(m_drawTextLoc, true);
m_program->setUniformValue(m_isLightLoc, false);
int faces = floor(numVerticesCube/6); int faces = floor(numVerticesCube/6);
for(int i = 0; i < faces; i++){ // 6 vertexes par face for(int i = 0; i < faces; i++){ // 6 vertexes par face
@ -162,6 +163,8 @@ void Viewer::draw()
sunRotate.rotate(rotAngle, 1, 0, 0); sunRotate.rotate(rotAngle, 1, 0, 0);
m_program->setUniformValue(m_lDirLoc, (sun * sunRotate)); m_program->setUniformValue(m_lDirLoc, (sun * sunRotate));
selection->transform.setToIdentity();
selection->transform.rotate(rotAngle, 0, 1, 0);
// Traverse the Scene in order to draw its components // Traverse the Scene in order to draw its components
@ -333,6 +336,9 @@ void Viewer::initShaders()
if ((m_drawTextLoc = m_program->uniformLocation("drawTextures")) < 0) if ((m_drawTextLoc = m_program->uniformLocation("drawTextures")) < 0)
qDebug() << "Unable to find m_shader location for" << "drawTextures"; qDebug() << "Unable to find m_shader location for" << "drawTextures";
if ((m_isLightLoc = m_program->uniformLocation("isLightSource")) < 0)
qDebug() << "Unable to find m_shader location for" << "isLightSource";
m_program->setUniformValue(m_isPhongLoc, true); m_program->setUniformValue(m_isPhongLoc, true);
m_program->setUniformValue(m_drawTextLoc, true); m_program->setUniformValue(m_drawTextLoc, true);
@ -619,6 +625,7 @@ void Viewer::visit(Cube &s)
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
m_program->setUniformValue(m_colorLocation, s.getColor()); m_program->setUniformValue(m_colorLocation, s.getColor());
m_program->setUniformValue(m_drawTextLoc, true); m_program->setUniformValue(m_drawTextLoc, true);
m_program->setUniformValue(m_isLightLoc, false);
glDrawArrays(GL_TRIANGLES, i*6, 6); glDrawArrays(GL_TRIANGLES, i*6, 6);
} }
@ -634,8 +641,9 @@ void Viewer::visit(Sphere &s)
m_program->setUniformValue(m_isSkyLoc, false); m_program->setUniformValue(m_isSkyLoc, false);
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255)); m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 200));
m_program->setUniformValue(m_drawTextLoc, false); m_program->setUniformValue(m_drawTextLoc, false);
m_program->setUniformValue(m_isLightLoc, true);
glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0);
} }

View File

@ -100,6 +100,7 @@ private:
int m_lDirLoc; int m_lDirLoc;
int m_skyMultLoc; int m_skyMultLoc;
int m_drawTextLoc; int m_drawTextLoc;
int m_isLightLoc;
float angle_mult; float angle_mult;