mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-25 12:01:21 +00:00
fixing some light bullshit
This commit is contained in:
parent
d86f533f94
commit
29aeb866b1
@ -26,16 +26,16 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
|||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
|
|
||||||
// Compute diffuse component
|
// Compute diffuse component
|
||||||
float diff = 0.4*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, fNorm);
|
||||||
float spec = 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);
|
float mult = 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);
|
||||||
|
|||||||
@ -166,12 +166,9 @@ void Viewer::draw()
|
|||||||
|
|
||||||
modelStack.push(modelViewMatrix);
|
modelStack.push(modelViewMatrix);
|
||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
frame += 1;
|
|
||||||
|
|
||||||
sunRotate.setToIdentity();
|
sunRotate.setToIdentity();
|
||||||
//float rotAngle = (frame * angle_mult) % 360;
|
//float rotAngle = (frame * angle_mult) % 360;
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
void Viewer::mouseMoveEvent(QMouseEvent* e) {
|
||||||
@ -230,12 +227,6 @@ void Viewer::init()
|
|||||||
identityMatrix.setToIdentity();
|
identityMatrix.setToIdentity();
|
||||||
SkyboxCamera *_cam = new SkyboxCamera();
|
SkyboxCamera *_cam = new SkyboxCamera();
|
||||||
setCamera(_cam);
|
setCamera(_cam);
|
||||||
//camera()->setType(qglviewer::Camera::PERSPECTIVE);
|
|
||||||
//setMouseBinding(Qt::NoModifier, Qt::LeftButton, CAMERA, SCREEN_ROTATE);
|
|
||||||
//setMouseBinding(Qt::AltModifier, Qt::LeftButton, CAMERA, NO_MOUSE_ACTION);
|
|
||||||
//setMouseBinding(Qt::NoModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
//setMouseBinding(Qt::ControlModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
//setMouseBinding(Qt::ShiftModifier, Qt::MouseButton(Qt::LeftButton + Qt::MidButton), CAMERA, NO_MOUSE_ACTION);
|
|
||||||
|
|
||||||
// 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(5);
|
||||||
@ -290,7 +281,7 @@ void Viewer::init()
|
|||||||
Shape* cube = new Cube();
|
Shape* cube = new Cube();
|
||||||
SceneGroup *sc = new SceneGroup();
|
SceneGroup *sc = new SceneGroup();
|
||||||
cube->setColor(*c1);
|
cube->setColor(*c1);
|
||||||
cube->setType(1);
|
cube->setType(TEX_GRASS);
|
||||||
sc->addChild(cube);
|
sc->addChild(cube);
|
||||||
sc->transform.translate(-5+i, 0, -5+j);
|
sc->transform.translate(-5+i, 0, -5+j);
|
||||||
root.addChild(sc);
|
root.addChild(sc);
|
||||||
@ -298,6 +289,8 @@ void Viewer::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
startTime = clock();
|
||||||
|
startAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::resetSphereColors(){
|
void Viewer::resetSphereColors(){
|
||||||
@ -796,6 +789,18 @@ void Viewer::changeColor(QColor c){
|
|||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::animate(){
|
||||||
|
clock_t time = clock();
|
||||||
|
double dt = time - startTime;
|
||||||
|
frame += dt * 0.006 * frame_mult; // 60fps
|
||||||
|
startTime = time;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Viewer::startAniumation(){}
|
||||||
|
|
||||||
|
void Viewer::stopAnimation(){}
|
||||||
|
|
||||||
PickedGeom Viewer::pickGeom(int x, int y){
|
PickedGeom Viewer::pickGeom(int x, int y){
|
||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
|
|||||||
@ -86,6 +86,10 @@ private:
|
|||||||
void deselect();
|
void deselect();
|
||||||
PickedGeom pickGeom(int, int);
|
PickedGeom pickGeom(int, int);
|
||||||
|
|
||||||
|
void animate();
|
||||||
|
void startAniumation();
|
||||||
|
void stopAnimation();
|
||||||
|
|
||||||
// shader switching variables and constants;
|
// shader switching variables and constants;
|
||||||
QOpenGLShaderProgram *colorPickerShaderProgram;
|
QOpenGLShaderProgram *colorPickerShaderProgram;
|
||||||
QOpenGLShaderProgram *textureRenderShaderprogram;
|
QOpenGLShaderProgram *textureRenderShaderprogram;
|
||||||
@ -124,6 +128,9 @@ private:
|
|||||||
bool isPickingActivated = false;
|
bool isPickingActivated = false;
|
||||||
|
|
||||||
float angle_mult;
|
float angle_mult;
|
||||||
|
float frame_mult = 1;
|
||||||
|
|
||||||
|
clockid_t startTime;
|
||||||
|
|
||||||
QOpenGLTexture *s_texture;
|
QOpenGLTexture *s_texture;
|
||||||
|
|
||||||
@ -174,7 +181,7 @@ private:
|
|||||||
QMatrix4x4 identityMatrix;
|
QMatrix4x4 identityMatrix;
|
||||||
|
|
||||||
QQuaternion rot;
|
QQuaternion rot;
|
||||||
unsigned int frame;
|
double frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIMPLEVIEWER_H
|
#endif // SIMPLEVIEWER_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user