This commit is contained in:
Riku Avelar 2016-11-25 19:51:03 -05:00
parent 7c05245201
commit b0169b94a5
4 changed files with 51 additions and 14 deletions

View File

@ -29,13 +29,13 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
// Compute specular component
vec3 Rl = reflect(LightDirection, fNorm);
float spec = 0.2*pow(max(0.0, dot(normalMatrix * Rl, nviewDirection)), 64);
vec3 Rl = reflect(LightDirection, nfNormal);
float spec = 0.2*pow(max(0.0, dot(/*normalMatrix */ Rl, nviewDirection)), 64);
// Compute ambient component
float amb = 0.2;
float mult = max(0.0, -LightDirection.y+1.5);
float mult = 1;//max(0.0, -LightDirection.y+1.5);
//return vec4(0);
return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w);
@ -55,7 +55,7 @@ vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
// Compute specular component
vec3 Rl = reflect(-LightDirection, normalMatrix * fNorm);
vec3 Rl = reflect(-LightDirection, /*normalMatrix */ nfNormal);
float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
// Compute ambient component

View File

@ -78,7 +78,7 @@ main()
vec4 vEyeCoord = mvMatrix * vPosition;
gl_Position = projMatrix * vEyeCoord;
fPosition = -vEyeCoord.xyz;
fNormal = /*normalMatrix **/ vNormal;
fNormal = normalMatrix * vNormal;
texCoords = vUv;

View File

@ -154,11 +154,11 @@ void Viewer::draw()
// Adjust sun position
float rotAngle = std::fmod(angle_mult * frame, 360);
float rotAngle = std::fmod(angle_mult * 25 * frame, 360);
sunRotate.rotate(rotAngle, 0, 0, 1);
//sunRotate.rotate(15, 1, 0, 0);
m_program->setUniformValue(m_lDirLoc, (sunRotate * sun));
m_program->setUniformValue(m_lDirLoc, (QMatrix4x4(modelViewMatrix.normalMatrix())*sunRotate * sun));
selection->transform.setToIdentity();
selection->transform.rotate(rotAngle, 0, 1, 0);
@ -233,6 +233,8 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
selectedObj.shape = selectedGeom.shape;
selectedObj.shape->getParent()->addChild(selection);
cubeSelected(true);
rotateSelected(X_CCW);
}
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
@ -857,7 +859,30 @@ void Viewer::startAniumation(){}
void Viewer::stopAnimation(){}
void Viewer::rotateSelected(RotateDirection dir) {
if(selectedObj.shape == nullptr || selectedObj.shape->getParent() == nullptr) return;
switch(dir) {
case X_CCW:
selectedObj.shape->getParent()->transform.rotate(90, 1, 0, 0);
break;
case X_CW:
selectedObj.shape->getParent()->transform.rotate(-90, 1, 0, 0);
break;
case Y_CCW:
selectedObj.shape->getParent()->transform.rotate(90, 0, 1, 0);
break;
case Y_CW:
selectedObj.shape->getParent()->transform.rotate(-90, 0, 1, 0);
break;
case Z_CCW:
selectedObj.shape->getParent()->transform.rotate(90, 0, 0, 1);
break;
case Z_CW:
selectedObj.shape->getParent()->transform.rotate(-90, 0, 0, 1);
break;
}
}
PickedGeom Viewer::pickGeom(int x, int y){

View File

@ -152,6 +152,15 @@ private:
Shape* generateShapeFromIndex(int);
enum RotateDirection {
X_CCW,
X_CW,
Y_CCW,
Y_CW,
Z_CCW,
Z_CW
};
enum Textures{
TEX_DRYGOUND,
TEX_GRANITEFLOOR,
@ -162,6 +171,7 @@ private:
TEX_LENGTH
};
unsigned int selectedTexture = TEX_WOODFLOOR;
QString TexturePaths[TEX_LENGTH] = {
@ -187,6 +197,8 @@ private:
QQuaternion rot;
double frame;
void rotateSelected(RotateDirection);
};
#endif // SIMPLEVIEWER_H