mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Spheres... not working
This commit is contained in:
parent
a0f82956c9
commit
2b38d0b793
@ -4,6 +4,7 @@ uniform bool isSky;
|
||||
uniform bool isPhong;
|
||||
uniform sampler2D tex;
|
||||
uniform float skyMult;
|
||||
uniform bool drawTextures;
|
||||
|
||||
in vec3 fNormal;
|
||||
in vec3 fPosition;
|
||||
@ -15,7 +16,12 @@ out vec4 fColor;
|
||||
void
|
||||
main()
|
||||
{
|
||||
vec4 texColor = texture(tex, texCoords);
|
||||
vec4 texColor;
|
||||
if(drawTextures) {
|
||||
texColor = texture(tex, texCoords);
|
||||
} else {
|
||||
texColor = ifColor;
|
||||
}
|
||||
if(isSky) {
|
||||
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
|
||||
} else if(isPhong) {
|
||||
|
||||
@ -57,6 +57,8 @@ namespace
|
||||
|
||||
QVector3D sun = QVector3D(0,-1,0);
|
||||
QMatrix4x4 sunRotate;
|
||||
|
||||
SceneGroup* selection;
|
||||
}
|
||||
|
||||
class SkyboxCamera : public qglviewer::Camera
|
||||
@ -114,6 +116,7 @@ void Viewer::drawSkybox()
|
||||
m_program->setUniformValue(m_skyMultLoc, colorMult);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_isSkyLoc, true);
|
||||
m_program->setUniformValue(m_drawTextLoc, true);
|
||||
|
||||
int faces = floor(numVerticesCube/6);
|
||||
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
||||
@ -150,6 +153,16 @@ void Viewer::draw()
|
||||
|
||||
modelViewMatrix.rotate(30,0,1,0);
|
||||
|
||||
|
||||
glBindVertexArray(m_VAOs[VAO_Sphere]);
|
||||
m_program->setUniformValue(m_isSkyLoc, false);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255));
|
||||
m_program->setUniformValue(m_drawTextLoc, false);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0);
|
||||
|
||||
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
|
||||
@ -242,12 +255,29 @@ void Viewer::init()
|
||||
Shape* cube = new Cube();
|
||||
cube->setColor(*activeColor);
|
||||
|
||||
Shape* s1 = new Sphere();
|
||||
Shape* s2 = new Sphere();
|
||||
Shape* s3 = new Sphere();
|
||||
|
||||
s1->transform.rotate(360 * 1/3,0,1,0);
|
||||
s1->transform.translate(1.5,0,0);
|
||||
s2->transform.rotate(360 * 2/3,0,1,0);
|
||||
s2->transform.translate(1.5,0,0);
|
||||
s3->transform.rotate(360 * 3/3,0,1,0);
|
||||
s3->transform.translate(1.5,0,0);
|
||||
|
||||
// uncomment this and the quaternion transformation in draw()
|
||||
// to see the cube rotate. This is how we can easily make the sun.
|
||||
// cube->transform.translate(3, 0, 0);
|
||||
|
||||
selection = new SceneGroup();
|
||||
selection->addChild(s1);;
|
||||
selection->addChild(s2);;
|
||||
selection->addChild(s3);
|
||||
|
||||
SceneGroup *c = new SceneGroup();
|
||||
c->addChild(cube);
|
||||
//c->addChild(selection);
|
||||
root.addChild(c);
|
||||
}
|
||||
}
|
||||
@ -310,7 +340,12 @@ void Viewer::initShaders()
|
||||
if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0)
|
||||
qDebug() << "Unable to find m_shader location for" << "skyMult";
|
||||
|
||||
if ((m_drawTextLoc = m_program->uniformLocation("drawTextures")) < 0)
|
||||
qDebug() << "Unable to find m_shader location for" << "drawTextures";
|
||||
|
||||
|
||||
m_program->setUniformValue(m_isPhongLoc, true);
|
||||
m_program->setUniformValue(m_drawTextLoc, true);
|
||||
/*
|
||||
* Adding Texture Shader
|
||||
*/
|
||||
@ -584,16 +619,17 @@ void Viewer::initGeometries()
|
||||
|
||||
void Viewer::visit(Cube &s)
|
||||
{
|
||||
return;
|
||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||
|
||||
int faces = floor(numVerticesCube/6);
|
||||
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
m_program->setUniformValue(m_isSkyLoc, false);
|
||||
m_program->setUniformValue(m_isPhongLoc, true);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
m_program->setUniformValue(m_colorLocation, s.getColor());
|
||||
m_program->setUniformValue(m_drawTextLoc, true);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
||||
}
|
||||
@ -602,14 +638,15 @@ void Viewer::visit(Cube &s)
|
||||
|
||||
void Viewer::visit(Sphere &s)
|
||||
{
|
||||
// std::cout << "Sphere found";
|
||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||
|
||||
glBindVertexArray(m_VAOs[VAO_Sphere]);
|
||||
m_program->setUniformValue(m_isSkyLoc, false);
|
||||
m_program->setUniformValue(m_isPhongLoc, true);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
m_program->setUniformValue(m_colorLocation, s.getColor());
|
||||
m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255));
|
||||
m_program->setUniformValue(m_drawTextLoc, false);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ private:
|
||||
int m_isSkyLoc;
|
||||
int m_lDirLoc;
|
||||
int m_skyMultLoc;
|
||||
int m_drawTextLoc;
|
||||
|
||||
float angle_mult;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user