mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
WIP part 2
This commit is contained in:
parent
45e775b8f9
commit
d5ead46e24
@ -2,10 +2,10 @@
|
|||||||
# www.blender.org
|
# www.blender.org
|
||||||
mtllib sonic_screwdriver.mtl
|
mtllib sonic_screwdriver.mtl
|
||||||
o Plane
|
o Plane
|
||||||
v 34.241825 -2.527184 34.241825
|
v 0.0000 0.0000 0.0000
|
||||||
v -34.241825 -2.527184 34.241825
|
v 0.0000 0.0000 0.0000
|
||||||
v 34.241825 -2.527184 -34.241825
|
v 0.0000 0.0000 0.0000
|
||||||
v -34.241825 -2.527184 -34.241825
|
v 0.0000 0.0000 0.0000
|
||||||
vn 0.0000 1.0000 0.0000
|
vn 0.0000 1.0000 0.0000
|
||||||
usemtl floor
|
usemtl floor
|
||||||
s off
|
s off
|
||||||
@ -49,6 +49,7 @@ vn 0.6711 0.7414 0.0000
|
|||||||
vn -0.6711 0.7414 0.0000
|
vn -0.6711 0.7414 0.0000
|
||||||
vn 0.6711 -0.7414 0.0000
|
vn 0.6711 -0.7414 0.0000
|
||||||
vn -0.6711 -0.7414 0.0000
|
vn -0.6711 -0.7414 0.0000
|
||||||
|
g None
|
||||||
usemtl None
|
usemtl None
|
||||||
s off
|
s off
|
||||||
f 5//2 9//2 19//2 17//2
|
f 5//2 9//2 19//2 17//2
|
||||||
@ -46904,6 +46905,7 @@ vn 0.1757 -0.2631 -0.9486
|
|||||||
vn 0.1825 -0.4409 -0.8788
|
vn 0.1825 -0.4409 -0.8788
|
||||||
vn -0.2648 -0.4154 -0.8703
|
vn -0.2648 -0.4154 -0.8703
|
||||||
vn -0.2929 -0.2506 -0.9227
|
vn -0.2929 -0.2506 -0.9227
|
||||||
|
g metal
|
||||||
usemtl metal
|
usemtl metal
|
||||||
s off
|
s off
|
||||||
f 3169//16 3161//16 2983//16 3074//16
|
f 3169//16 3161//16 2983//16 3074//16
|
||||||
@ -57744,6 +57746,7 @@ f 11834//9151 11835//9215 11983//9181 11979//9201
|
|||||||
f 11846//9220 11847//9210 11956//9169 11974//8851
|
f 11846//9220 11847//9210 11956//9169 11974//8851
|
||||||
f 11840//9222 11841//9213 11992//8808 11976//9198
|
f 11840//9222 11841//9213 11992//8808 11976//9198
|
||||||
f 11842//9212 11843//9221 11975//9196 11991//9175
|
f 11842//9212 11843//9221 11975//9196 11991//9175
|
||||||
|
g inside
|
||||||
usemtl inside
|
usemtl inside
|
||||||
f 3842//9127 3841//9128 4001//8792 4002//8792
|
f 3842//9127 3841//9128 4001//8792 4002//8792
|
||||||
f 3876//9174 3877//9173 3973//8796 3972//8796
|
f 3876//9174 3877//9173 3973//8796 3972//8796
|
||||||
@ -57907,6 +57910,7 @@ f 3822//9147 3821//9148 3981//8792 3982//8792
|
|||||||
f 3851//9118 3850//9119 4010//8792 4011//8792
|
f 3851//9118 3850//9119 4010//8792 4011//8792
|
||||||
f 3848//9121 3847//9122 4007//8792 4008//8792
|
f 3848//9121 3847//9122 4007//8792 4008//8792
|
||||||
f 3845//9124 3844//9125 4004//8792 4005//8792
|
f 3845//9124 3844//9125 4004//8792 4005//8792
|
||||||
|
g emitter
|
||||||
usemtl emitter
|
usemtl emitter
|
||||||
f 213//9223 317//9224 90//9225 89//9226
|
f 213//9223 317//9224 90//9225 89//9226
|
||||||
f 92//9227 61//9228 62//9229 63//9230 64//9231 65//9232 66//9233 67//9234 68//9235 69//9236 70//9237 71//9238 72//9239 73//9240 74//9241 75//9242 76//9243 77//9244 78//9245 79//9246 80//9247 81//9248 82//9249 83//9250 84//9251 85//9252 86//9253 87//9254 88//9255 89//9226 90//9225 91//9256
|
f 92//9227 61//9228 62//9229 63//9230 64//9231 65//9232 66//9233 67//9234 68//9235 69//9236 70//9237 71//9238 72//9239 73//9240 74//9241 75//9242 76//9243 77//9244 78//9245 79//9246 80//9247 81//9248 82//9249 83//9250 84//9251 85//9252 86//9253 87//9254 88//9255 89//9226 90//9225 91//9256
|
||||||
@ -58518,6 +58522,7 @@ f 54//9506 374//9826 375//9763 55//9443
|
|||||||
f 51//9453 371//9773 372//9774 52//9454
|
f 51//9453 371//9773 372//9774 52//9454
|
||||||
f 48//9460 368//9780 369//9814 49//9494
|
f 48//9460 368//9780 369//9814 49//9494
|
||||||
f 45//9493 365//9813 366//9746 46//9426
|
f 45//9493 365//9813 366//9746 46//9426
|
||||||
|
g brass
|
||||||
usemtl brass
|
usemtl brass
|
||||||
f 12613//8792 16576//9863 22882//9864 16575//9865
|
f 12613//8792 16576//9863 22882//9864 16575//9865
|
||||||
f 12613//8792 16575//9865 22881//9866 16574//9867
|
f 12613//8792 16575//9865 22881//9866 16574//9867
|
||||||
@ -66519,6 +66524,7 @@ f 15264//16532 22077//16501 25684//16118 21962//16471
|
|||||||
f 15264//16532 21962//16471 25685//16069 22088//16521
|
f 15264//16532 21962//16471 25685//16069 22088//16521
|
||||||
f 15264//16532 22088//16521 25717//9178 22026//8774
|
f 15264//16532 22088//16521 25717//9178 22026//8774
|
||||||
f 15264//16532 22026//8774 25716//8769 22077//16501
|
f 15264//16532 22026//8774 25716//8769 22077//16501
|
||||||
|
g handle
|
||||||
usemtl handle
|
usemtl handle
|
||||||
f 13031//16533 17482//16534 23380//16535 17552//16536
|
f 13031//16533 17482//16534 23380//16535 17552//16536
|
||||||
f 13031//16533 17552//16536 23377//16537 17487//16538
|
f 13031//16533 17552//16536 23377//16537 17487//16538
|
||||||
@ -68344,6 +68350,7 @@ f 15304//18315 22152//18244 23719//18004 18167//18102
|
|||||||
f 15304//18315 18167//18102 23725//18100 22165//18285
|
f 15304//18315 18167//18102 23725//18100 22165//18285
|
||||||
f 15304//18315 22165//18285 25765//10872 22103//18316
|
f 15304//18315 22165//18285 25765//10872 22103//18316
|
||||||
f 15304//18315 22103//18316 25759//18245 22152//18244
|
f 15304//18315 22103//18316 25759//18245 22152//18244
|
||||||
|
g leather
|
||||||
usemtl leather
|
usemtl leather
|
||||||
f 12774//18317 16928//18318 23074//18319 16927//18320
|
f 12774//18317 16928//18318 23074//18319 16927//18320
|
||||||
f 12774//18317 16927//18320 23073//18321 16926//18322
|
f 12774//18317 16927//18320 23073//18321 16926//18322
|
||||||
@ -69467,6 +69474,7 @@ f 15320//19415 17207//19159 23187//18904 17182//19414
|
|||||||
f 15320//19415 17182//19414 25800//18983 22199//19013
|
f 15320//19415 17182//19414 25800//18983 22199//19013
|
||||||
f 15320//19415 22199//19013 25798//19017 17290//19406
|
f 15320//19415 22199//19013 25798//19017 17290//19406
|
||||||
f 15320//19415 17290//19406 23206//19160 17207//19159
|
f 15320//19415 17290//19406 23206//19160 17207//19159
|
||||||
|
g cotton
|
||||||
usemtl cotton
|
usemtl cotton
|
||||||
s off
|
s off
|
||||||
f 12013//19416 15321//19416 22251//19416 15323//19416
|
f 12013//19416 15321//19416 22251//19416 15323//19416
|
||||||
|
|||||||
@ -58,7 +58,7 @@ bool Loader::loadFile(const std::string& filename)
|
|||||||
unload();
|
unload();
|
||||||
|
|
||||||
// Open the input file
|
// Open the input file
|
||||||
std::ifstream file(filename, std::ifstream::in);
|
std::ifstream file(filename.c_str(), std::ifstream::in);
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
std::cout << "Error: Failed to open file " << filename << " for reading!" << std::endl;
|
std::cout << "Error: Failed to open file " << filename << " for reading!" << std::endl;
|
||||||
@ -293,7 +293,7 @@ bool Loader::loadFile(const std::string& filename)
|
|||||||
void Loader::loadMtlFile(const std::string& filename)
|
void Loader::loadMtlFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
// Open the input file
|
// Open the input file
|
||||||
std::ifstream file(filename, std::ifstream::in);
|
std::ifstream file(filename.c_str(), std::ifstream::in);
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
std::cout << "Error: Failed to open material file " << filename << " for reading!" << std::endl;
|
std::cout << "Error: Failed to open material file " << filename << " for reading!" << std::endl;
|
||||||
|
|||||||
@ -3,10 +3,6 @@ uniform vec3 Kd;
|
|||||||
uniform vec3 Ks;
|
uniform vec3 Ks;
|
||||||
uniform float Kn;
|
uniform float Kn;
|
||||||
|
|
||||||
#version 400 core
|
|
||||||
uniform sampler2D texCol;
|
|
||||||
uniform sampler2D texNormal;
|
|
||||||
|
|
||||||
uniform vec3 lDirection;
|
uniform vec3 lDirection;
|
||||||
uniform bool isPhong;
|
uniform bool isPhong;
|
||||||
uniform vec3 pointLight[3];
|
uniform vec3 pointLight[3];
|
||||||
@ -70,18 +66,14 @@ main()
|
|||||||
{
|
{
|
||||||
vec4 texColor;
|
vec4 texColor;
|
||||||
|
|
||||||
texColor = ifColor;
|
// Get lighting vectors
|
||||||
if(isPhong) {
|
vec3 LightDirection = normalize(lDirection);
|
||||||
// Get lighting vectors
|
vec3 nfNormal = normalize(fNormal);
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 nviewDirection = normalize(fPosition);
|
||||||
vec3 nfNormal = normalize(fNormal);
|
|
||||||
vec3 nviewDirection = normalize(fPosition);
|
|
||||||
|
|
||||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
fColor = calcDirLight(texColor, fPosition, fNormal)
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
||||||
} else {
|
fColor.a = 1.0;
|
||||||
fColor = texColor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
#include "../glnodes/shapes.h"
|
#include "../glnodes/shapes.h"
|
||||||
#include "../libs/OBJLoader.h"
|
#include "../libs/OBJLoader.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sstream>
|
||||||
#include <qopengl.h>
|
#include <qopengl.h>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@ -89,9 +89,9 @@ void Viewer::cleanup()
|
|||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
|
|
||||||
// Delete shaders
|
// Delete shaders
|
||||||
delete m_program;
|
delete m_program;
|
||||||
m_program = 0;
|
m_program = 0;
|
||||||
|
|
||||||
delete objShader;
|
delete objShader;
|
||||||
objShader = 0;
|
objShader = 0;
|
||||||
@ -135,9 +135,10 @@ void Viewer::drawSkybox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::loadToolObj() {
|
void Viewer::loadToolObj() {
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
// Load the obj file
|
// Load the obj file
|
||||||
OBJLoader::Loader loader("../data/sonic_screwdriver.obj");
|
OBJLoader::Loader loader("src/data/sonic_screwdriver.obj");
|
||||||
|
|
||||||
// Create a GL object for each mesh extracted from the OBJ file
|
// Create a GL object for each mesh extracted from the OBJ file
|
||||||
const std::vector<OBJLoader::Mesh>& meshes = loader.getMeshes();
|
const std::vector<OBJLoader::Mesh>& meshes = loader.getMeshes();
|
||||||
@ -175,11 +176,11 @@ void Viewer::loadToolObj() {
|
|||||||
// Set VAO that binds the shader vertices inputs to the buffer data
|
// Set VAO that binds the shader vertices inputs to the buffer data
|
||||||
glBindVertexArray(meshGL.vao);
|
glBindVertexArray(meshGL.vao);
|
||||||
|
|
||||||
glVertexAttribPointer(m_vPositionLoc, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(positionOffset));
|
glVertexAttribPointer(o_a_vPos, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(positionOffset));
|
||||||
glEnableVertexAttribArray(m_vPositionLoc);
|
glEnableVertexAttribArray(o_a_vPos);
|
||||||
|
|
||||||
glVertexAttribPointer(m_vNormalLoc, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(normalOffset));
|
glVertexAttribPointer(o_a_vNorm, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(normalOffset));
|
||||||
glEnableVertexAttribArray(m_vNormalLoc);
|
glEnableVertexAttribArray(o_a_vNorm);
|
||||||
|
|
||||||
// Add it to the list
|
// Add it to the list
|
||||||
_meshesGL.push_back(meshGL);
|
_meshesGL.push_back(meshGL);
|
||||||
@ -216,7 +217,14 @@ void Viewer::draw()
|
|||||||
//sunRotate.rotate(15, 1, 0, 0);
|
//sunRotate.rotate(15, 1, 0, 0);
|
||||||
|
|
||||||
m_program->setUniformValue(m_lDirLoc, (QMatrix4x4(modelViewMatrix.normalMatrix())*sunRotate * sun));
|
m_program->setUniformValue(m_lDirLoc, (QMatrix4x4(modelViewMatrix.normalMatrix())*sunRotate * sun));
|
||||||
selection->transform.setToIdentity();
|
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
|
objShader->setUniformValue(o_u_prjMatrix, projectionMatrix);
|
||||||
|
objShader->setUniformValue(o_u_lDir, (QMatrix4x4(modelViewMatrix.normalMatrix())*sunRotate * sun));
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
selection->transform.setToIdentity();
|
||||||
selection->transform.rotate(rotAngle, 0, 1, 0);
|
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
|
||||||
@ -224,14 +232,16 @@ void Viewer::draw()
|
|||||||
modelStack.push(modelViewMatrix);
|
modelStack.push(modelViewMatrix);
|
||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
|
|
||||||
drawUi();
|
drawTool();
|
||||||
|
|
||||||
|
drawUi();
|
||||||
|
|
||||||
sunRotate.setToIdentity();
|
sunRotate.setToIdentity();
|
||||||
//float rotAngle = (frame * angle_mult) % 360;
|
//float rotAngle = (frame * angle_mult) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::drawUi(){
|
void Viewer::drawUi(){
|
||||||
|
m_program->bind();
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top
|
glClear(GL_DEPTH_BUFFER_BIT); // make ui always on top
|
||||||
|
|
||||||
@ -299,7 +309,7 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
|||||||
|
|
||||||
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
{
|
{
|
||||||
Cube* c = new Cube;
|
Cube* c = new Cube;
|
||||||
c->setType(selectedTexture);
|
c->setType(selectedTexture);
|
||||||
SceneGroup* container = new SceneGroup;
|
SceneGroup* container = new SceneGroup;
|
||||||
container->transform = selectedGeom.position;
|
container->transform = selectedGeom.position;
|
||||||
@ -377,7 +387,7 @@ void Viewer::init()
|
|||||||
setCamera(_cam);
|
setCamera(_cam);
|
||||||
|
|
||||||
// Our scene will be from -5 to 5 in X and Y (the grid will be 10x10).
|
// Our scene will be from -5 to 5 in X and Y (the grid will be 10x10).
|
||||||
setSceneRadius(5);
|
setSceneRadius(10);
|
||||||
showEntireScene();
|
showEntireScene();
|
||||||
|
|
||||||
// Init OpenGL objects
|
// Init OpenGL objects
|
||||||
@ -389,6 +399,7 @@ void Viewer::init()
|
|||||||
initShaders();
|
initShaders();
|
||||||
initGeometries();
|
initGeometries();
|
||||||
initBuffers();
|
initBuffers();
|
||||||
|
loadToolObj();
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -425,7 +436,7 @@ void Viewer::init()
|
|||||||
s3->transform.scale(0.05);
|
s3->transform.scale(0.05);
|
||||||
s3->setColor(*c3);
|
s3->setColor(*c3);
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++){
|
for(int i = 0; i < 10; i++){
|
||||||
for(int j = 0; j < 10; j++){
|
for(int j = 0; j < 10; j++){
|
||||||
Shape* cube = new Cube();
|
Shape* cube = new Cube();
|
||||||
SceneGroup *sc = new SceneGroup();
|
SceneGroup *sc = new SceneGroup();
|
||||||
@ -462,7 +473,6 @@ void Viewer::resetSphereColors(){
|
|||||||
void Viewer::initShaders()
|
void Viewer::initShaders()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Load vertex and fragment shaders
|
// Load vertex and fragment shaders
|
||||||
m_program = new QOpenGLShaderProgram;
|
m_program = new QOpenGLShaderProgram;
|
||||||
colorPickerShaderProgram = m_program;
|
colorPickerShaderProgram = m_program;
|
||||||
@ -481,6 +491,7 @@ void Viewer::initShaders()
|
|||||||
|
|
||||||
// Specify shader input paramters
|
// Specify shader input paramters
|
||||||
// The strings "vPosition", "mvMatrix", etc. have to match an attribute name in the vertex shader.
|
// The strings "vPosition", "mvMatrix", etc. have to match an attribute name in the vertex shader.
|
||||||
|
{
|
||||||
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
||||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
qDebug() << "Unable to find shader location for " << "vPosition";
|
||||||
|
|
||||||
@ -553,6 +564,7 @@ void Viewer::initShaders()
|
|||||||
if ((m_isPickingModeLoc = m_program->uniformLocation("isPickingMode")) < 0)
|
if ((m_isPickingModeLoc = m_program->uniformLocation("isPickingMode")) < 0)
|
||||||
qDebug() << "Unable to find m_shader location for" << "isPickingMode" << m_program->log();
|
qDebug() << "Unable to find m_shader location for" << "isPickingMode" << m_program->log();
|
||||||
|
|
||||||
|
}
|
||||||
m_program->setUniformValue(m_isPhongLoc, true);
|
m_program->setUniformValue(m_isPhongLoc, true);
|
||||||
m_program->setUniformValue(m_drawTextLoc, false);
|
m_program->setUniformValue(m_drawTextLoc, false);
|
||||||
m_program->setUniformValue(m_isPickingModeLoc, false);
|
m_program->setUniformValue(m_isPickingModeLoc, false);
|
||||||
@ -561,6 +573,46 @@ void Viewer::initShaders()
|
|||||||
m_program->setUniformValue(m_texColor, 0);
|
m_program->setUniformValue(m_texColor, 0);
|
||||||
m_program->setUniformValue(m_texNormal, 1);
|
m_program->setUniformValue(m_texNormal, 1);
|
||||||
|
|
||||||
|
objShader = new QOpenGLShaderProgram;
|
||||||
|
if (!objShader->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/objShader.vert")) {
|
||||||
|
cerr << "Unable to load Shader" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << objShader->log();
|
||||||
|
}
|
||||||
|
if (!objShader->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/objShader.frag")) {
|
||||||
|
cerr << "Unable to load Shader" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << objShader->log();
|
||||||
|
}
|
||||||
|
|
||||||
|
objShader->link();
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
|
o_u_mvMatrix = objShader->uniformLocation("mvMatrix");
|
||||||
|
o_u_prjMatrix = objShader->uniformLocation("projMatrix");
|
||||||
|
o_u_nmMatrix = objShader->uniformLocation("normalMatrix");
|
||||||
|
o_u_isPhong = objShader->uniformLocation("isPhong");
|
||||||
|
o_u_lDir = objShader->uniformLocation("lDirection");
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
std::ostringstream posAttr;
|
||||||
|
std::ostringstream colAttr;
|
||||||
|
posAttr << "pointLight[" << i << "]";
|
||||||
|
colAttr << "pointLightCol[" << i << "]";
|
||||||
|
|
||||||
|
o_u_pointLightPos[i] = objShader->uniformLocation(posAttr.str().c_str());
|
||||||
|
o_u_pointLightCol[i] = objShader->uniformLocation(colAttr.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
o_u_kd = objShader->uniformLocation("Kd");
|
||||||
|
o_u_ks = objShader->uniformLocation("Ks");
|
||||||
|
o_u_kn = objShader->uniformLocation("Kn");
|
||||||
|
o_a_vPos = objShader->attributeLocation("vPosition");
|
||||||
|
o_a_vNorm = objShader->attributeLocation("vNormal");
|
||||||
|
|
||||||
|
objShader->setUniformValue(o_u_isPhong, true);
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
|
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
|
||||||
@ -583,6 +635,7 @@ void Viewer::initShaders()
|
|||||||
|
|
||||||
void Viewer::initGeometries()
|
void Viewer::initGeometries()
|
||||||
{
|
{
|
||||||
|
m_program->bind();
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable( GL_BLEND );
|
glEnable( GL_BLEND );
|
||||||
glEnable( GL_CULL_FACE );
|
glEnable( GL_CULL_FACE );
|
||||||
@ -826,9 +879,38 @@ void Viewer::initBuffers(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::drawTool() {
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
|
// Get projection and camera transformations
|
||||||
|
QMatrix4x4 modelViewMatrix;
|
||||||
|
|
||||||
|
camera()->getModelViewMatrix(modelViewMatrix);
|
||||||
|
|
||||||
|
QMatrix4x4 scale = QMatrix4x4();
|
||||||
|
// scale.translate(QVector3D(0,1.5,0));
|
||||||
|
scale.scale(2.0);
|
||||||
|
|
||||||
|
objShader->setUniformValue(o_u_mvMatrix, modelViewMatrix * scale);
|
||||||
|
objShader->setUniformValue(o_u_nmMatrix, modelViewMatrix.normalMatrix());
|
||||||
|
|
||||||
|
// Draw the meshes
|
||||||
|
for (unsigned int i=0; i<_meshesGL.size(); ++i)
|
||||||
|
{
|
||||||
|
// Set its material properties
|
||||||
|
objShader->setUniformValue(o_u_kd, _meshesGL[i].diffuse);
|
||||||
|
objShader->setUniformValue(o_u_ks, _meshesGL[i].specular);
|
||||||
|
objShader->setUniformValue(o_u_kn, _meshesGL[i].specularExponent);
|
||||||
|
|
||||||
|
// Draw the mesh
|
||||||
|
glBindVertexArray(_meshesGL[i].vao);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, _meshesGL[i].numVertices);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Viewer::visit(Cube &s)
|
void Viewer::visit(Cube &s)
|
||||||
{
|
{
|
||||||
|
m_program->bind();
|
||||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||||
QColor* faceColor = new QColor;
|
QColor* faceColor = new QColor;
|
||||||
|
|
||||||
@ -863,6 +945,8 @@ void Viewer::visit(Sphere &s)
|
|||||||
// std::cout << "Sphere found";
|
// std::cout << "Sphere found";
|
||||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
|
||||||
if(!isPickingActivated){
|
if(!isPickingActivated){
|
||||||
glBindVertexArray(m_VAOs[VAO_Sphere]);
|
glBindVertexArray(m_VAOs[VAO_Sphere]);
|
||||||
m_program->setUniformValue(m_isSkyLoc, false);
|
m_program->setUniformValue(m_isSkyLoc, false);
|
||||||
@ -880,13 +964,19 @@ void Viewer::visit(Sphere &s)
|
|||||||
|
|
||||||
point = modelViewMatrix * point;
|
point = modelViewMatrix * point;
|
||||||
|
|
||||||
|
|
||||||
int pointLocs[3] = {m_point1Loc, m_point2Loc, m_point3Loc};
|
int pointLocs[3] = {m_point1Loc, m_point2Loc, m_point3Loc};
|
||||||
int pointCLocs[3] = {m_c1Loc, m_c2Loc, m_c3Loc};
|
int pointCLocs[3] = {m_c1Loc, m_c2Loc, m_c3Loc};
|
||||||
|
|
||||||
m_program->setUniformValue(pointLocs[currentPoint], point);
|
m_program->setUniformValue(pointLocs[currentPoint], point);
|
||||||
m_program->setUniformValue(pointCLocs[currentPoint], s.getColor());
|
m_program->setUniformValue(pointCLocs[currentPoint], s.getColor());
|
||||||
|
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
|
objShader->setUniformValue(o_u_pointLightPos[currentPoint], point);
|
||||||
|
objShader->setUniformValue(o_u_pointLightCol[currentPoint], s.getColor());
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
|
||||||
currentPoint = (currentPoint + 1) % 3;
|
currentPoint = (currentPoint + 1) % 3;
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, numTriSphere*3, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, numTriSphere*3, GL_UNSIGNED_INT, 0);
|
||||||
@ -915,6 +1005,8 @@ void Viewer::visit(SceneGroup &s)
|
|||||||
void Viewer::setPhong(bool on) {
|
void Viewer::setPhong(bool on) {
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_program->setUniformValue(m_isPhongLoc, on);
|
m_program->setUniformValue(m_isPhongLoc, on);
|
||||||
|
objShader->bind();
|
||||||
|
objShader->setUniformValue(o_u_isPhong, on);
|
||||||
if(on) std::cout << "Phong ON\n";
|
if(on) std::cout << "Phong ON\n";
|
||||||
else std::cout << "Phong OFF\n";
|
else std::cout << "Phong OFF\n";
|
||||||
this->update();
|
this->update();
|
||||||
@ -963,6 +1055,14 @@ void Viewer::deleteSelected() {
|
|||||||
m_program->setUniformValue(pointCLocs[1], QColor(0,0,0));
|
m_program->setUniformValue(pointCLocs[1], QColor(0,0,0));
|
||||||
m_program->setUniformValue(pointCLocs[2], QColor(0,0,0));
|
m_program->setUniformValue(pointCLocs[2], QColor(0,0,0));
|
||||||
|
|
||||||
|
objShader->bind();
|
||||||
|
|
||||||
|
objShader->setUniformValue(o_u_pointLightCol[0], QColor(0,0,0));
|
||||||
|
objShader->setUniformValue(o_u_pointLightCol[1], QColor(0,0,0));
|
||||||
|
objShader->setUniformValue(o_u_pointLightCol[2], QColor(0,0,0));
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
|
||||||
// Remove Shape from its parent
|
// Remove Shape from its parent
|
||||||
if(selectedObj.shape == nullptr) return;
|
if(selectedObj.shape == nullptr) return;
|
||||||
// selectedObj.shape->getParent()->getChildren()->erase(
|
// selectedObj.shape->getParent()->getChildren()->erase(
|
||||||
|
|||||||
@ -90,6 +90,7 @@ signals:
|
|||||||
protected :
|
protected :
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
virtual void drawSkybox();
|
virtual void drawSkybox();
|
||||||
|
virtual void drawTool();
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||||
@ -157,6 +158,19 @@ private:
|
|||||||
int m_isPickingModeLoc;
|
int m_isPickingModeLoc;
|
||||||
bool isPickingActivated = false;
|
bool isPickingActivated = false;
|
||||||
|
|
||||||
|
int o_u_mvMatrix;
|
||||||
|
int o_u_prjMatrix;
|
||||||
|
int o_u_nmMatrix;
|
||||||
|
int o_u_isPhong;
|
||||||
|
int o_u_lDir;
|
||||||
|
int o_u_pointLightPos[3];
|
||||||
|
int o_u_pointLightCol[3];
|
||||||
|
int o_u_kd;
|
||||||
|
int o_u_ks;
|
||||||
|
int o_u_kn;
|
||||||
|
int o_a_vPos;
|
||||||
|
int o_a_vNorm;
|
||||||
|
|
||||||
float angle_mult;
|
float angle_mult;
|
||||||
float frame_mult = 1;
|
float frame_mult = 1;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user