mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Merge branch 'master' of github.com:fataku/LOG750-LAB2
This commit is contained in:
commit
3ff9a79f39
@ -22,20 +22,20 @@ out vec4 fColor;
|
|||||||
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(lDirection);
|
||||||
vec3 nfNormal = normalize(fNorm);
|
vec3 nfNormal = normalize(fNorm);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
|
|
||||||
// Compute diffuse component
|
// 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
|
// Compute specular component
|
||||||
vec3 Rl = reflect(LightDirection, fNorm);
|
vec3 Rl = reflect(LightDirection, nfNormal);
|
||||||
float spec = 0.2*pow(max(0.0, dot(normalMatrix * Rl, nviewDirection)), 64);
|
float spec = 0.2*pow(max(0.0, dot(/*normalMatrix */ Rl, nviewDirection)), 64);
|
||||||
|
|
||||||
// Compute ambient component
|
// Compute ambient component
|
||||||
float amb = 0.2;
|
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(0);
|
||||||
return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w);
|
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));
|
float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
|
||||||
|
|
||||||
// Compute specular component
|
// 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);
|
float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
|
||||||
|
|
||||||
// Compute ambient component
|
// Compute ambient component
|
||||||
@ -90,9 +90,9 @@ main()
|
|||||||
vec3 nviewDirection = normalize(fPosition);
|
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 {
|
} else {
|
||||||
fColor = texColor + ifColor;
|
fColor = texColor + ifColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ main()
|
|||||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||||
gl_Position = projMatrix * vEyeCoord;
|
gl_Position = projMatrix * vEyeCoord;
|
||||||
fPosition = -vEyeCoord.xyz;
|
fPosition = -vEyeCoord.xyz;
|
||||||
fNormal = /*normalMatrix **/ vNormal;
|
fNormal = normalMatrix * vNormal;
|
||||||
|
|
||||||
texCoords = vUv;
|
texCoords = vUv;
|
||||||
|
|
||||||
|
|||||||
@ -154,11 +154,11 @@ void Viewer::draw()
|
|||||||
|
|
||||||
// Adjust sun position
|
// 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(rotAngle, 0, 0, 1);
|
||||||
//sunRotate.rotate(15, 1, 0, 0);
|
//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.setToIdentity();
|
||||||
selection->transform.rotate(rotAngle, 0, 1, 0);
|
selection->transform.rotate(rotAngle, 0, 1, 0);
|
||||||
|
|
||||||
@ -233,6 +233,8 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
|||||||
selectedObj.shape = selectedGeom.shape;
|
selectedObj.shape = selectedGeom.shape;
|
||||||
selectedObj.shape->getParent()->addChild(selection);
|
selectedObj.shape->getParent()->addChild(selection);
|
||||||
cubeSelected(true);
|
cubeSelected(true);
|
||||||
|
|
||||||
|
rotateSelected(X_CCW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
@ -817,17 +819,17 @@ void Viewer::setMinLinear(bool on) {
|
|||||||
void Viewer::deleteSelected() {
|
void Viewer::deleteSelected() {
|
||||||
// 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(
|
||||||
std::remove(selectedObj.shape->getParent()->getChildren()->begin(),
|
// std::remove(selectedObj.shape->getParent()->getChildren()->begin(),
|
||||||
selectedObj.shape->getParent()->getChildren()->end(),
|
// selectedObj.shape->getParent()->getChildren()->end(),
|
||||||
selection),
|
// selection),
|
||||||
selectedObj.shape->getParent()->getChildren()->end());
|
// selectedObj.shape->getParent()->getChildren()->end());
|
||||||
|
|
||||||
selectedObj.shape->getParent()->getChildren()->erase(
|
selectedObj.shape->getParent()->getParent()->getChildren()->erase(
|
||||||
std::remove(selectedObj.shape->getParent()->getChildren()->begin(),
|
std::remove(selectedObj.shape->getParent()->getParent()->getChildren()->begin(),
|
||||||
selectedObj.shape->getParent()->getChildren()->end(),
|
selectedObj.shape->getParent()->getParent()->getChildren()->end(),
|
||||||
selectedObj.shape),
|
selectedObj.shape->getParent()),
|
||||||
selectedObj.shape->getParent()->getChildren()->end());
|
selectedObj.shape->getParent()->getParent()->getChildren()->end());
|
||||||
|
|
||||||
selectedObj.shape = nullptr; // Rebind to "null"
|
selectedObj.shape = nullptr; // Rebind to "null"
|
||||||
|
|
||||||
@ -856,7 +858,30 @@ void Viewer::startAniumation(){}
|
|||||||
void Viewer::stopAnimation(){}
|
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){
|
PickedGeom Viewer::pickGeom(int x, int y){
|
||||||
|
|
||||||
|
|||||||
@ -152,6 +152,15 @@ private:
|
|||||||
|
|
||||||
Shape* generateShapeFromIndex(int);
|
Shape* generateShapeFromIndex(int);
|
||||||
|
|
||||||
|
enum RotateDirection {
|
||||||
|
X_CCW,
|
||||||
|
X_CW,
|
||||||
|
Y_CCW,
|
||||||
|
Y_CW,
|
||||||
|
Z_CCW,
|
||||||
|
Z_CW
|
||||||
|
};
|
||||||
|
|
||||||
enum Textures{
|
enum Textures{
|
||||||
TEX_DRYGOUND,
|
TEX_DRYGOUND,
|
||||||
TEX_GRANITEFLOOR,
|
TEX_GRANITEFLOOR,
|
||||||
@ -162,6 +171,7 @@ private:
|
|||||||
|
|
||||||
TEX_LENGTH
|
TEX_LENGTH
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int selectedTexture = TEX_WOODFLOOR;
|
unsigned int selectedTexture = TEX_WOODFLOOR;
|
||||||
|
|
||||||
QString TexturePaths[TEX_LENGTH] = {
|
QString TexturePaths[TEX_LENGTH] = {
|
||||||
@ -187,6 +197,8 @@ private:
|
|||||||
|
|
||||||
QQuaternion rot;
|
QQuaternion rot;
|
||||||
double frame;
|
double frame;
|
||||||
|
|
||||||
|
void rotateSelected(RotateDirection);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIMPLEVIEWER_H
|
#endif // SIMPLEVIEWER_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user