diff --git a/src/shaders/basicShader.frag b/src/shaders/basicShader.frag index 1a47f79..f4c656c 100644 --- a/src/shaders/basicShader.frag +++ b/src/shaders/basicShader.frag @@ -26,16 +26,16 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) { vec3 nviewDirection = normalize(fPos); // 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 - vec3 Rl = reflect(-LightDirection, fNorm); - float spec = pow(max(0.0, dot(normalMatrix * Rl, nviewDirection)), 64); + vec3 Rl = reflect(LightDirection, fNorm); + 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); + float mult = max(0.0, -LightDirection.y+1.5); //return vec4(0); return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w); @@ -89,10 +89,10 @@ main() vec3 nfNormal = normalize(fNormal); vec3 nviewDirection = normalize(fPosition); - fColor = calcDirLight(texColor, fPosition, fNormal) - + calcPointLight(texColor, fPosition, fNormal, 0)/4 - + calcPointLight(texColor, fPosition, fNormal, 1)/4 - + calcPointLight(texColor, fPosition, fNormal, 2)/4; + fColor = calcDirLight(texColor, fPosition, fNormal) + + calcPointLight(texColor, fPosition, fNormal, 0)/4 + + calcPointLight(texColor, fPosition, fNormal, 1)/4 + + calcPointLight(texColor, fPosition, fNormal, 2)/4; } else { fColor = texColor + ifColor; } diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 1313213..cb9f765 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -166,12 +166,9 @@ void Viewer::draw() modelStack.push(modelViewMatrix); root.accept(*this); - frame += 1; sunRotate.setToIdentity(); //float rotAngle = (frame * angle_mult) % 360; - - update(); } void Viewer::mouseMoveEvent(QMouseEvent* e) { @@ -230,12 +227,6 @@ void Viewer::init() identityMatrix.setToIdentity(); SkyboxCamera *_cam = new SkyboxCamera(); 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). setSceneRadius(5); @@ -290,7 +281,7 @@ void Viewer::init() Shape* cube = new Cube(); SceneGroup *sc = new SceneGroup(); cube->setColor(*c1); - cube->setType(1); + cube->setType(TEX_GRASS); sc->addChild(cube); sc->transform.translate(-5+i, 0, -5+j); root.addChild(sc); @@ -298,6 +289,8 @@ void Viewer::init() } } + startTime = clock(); + startAnimation(); } void Viewer::resetSphereColors(){ @@ -796,6 +789,18 @@ void Viewer::changeColor(QColor c){ 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){ makeCurrent(); diff --git a/src/viewer/simpleViewer.h b/src/viewer/simpleViewer.h index 356d3b6..c9326ee 100644 --- a/src/viewer/simpleViewer.h +++ b/src/viewer/simpleViewer.h @@ -86,6 +86,10 @@ private: void deselect(); PickedGeom pickGeom(int, int); + void animate(); + void startAniumation(); + void stopAnimation(); + // shader switching variables and constants; QOpenGLShaderProgram *colorPickerShaderProgram; QOpenGLShaderProgram *textureRenderShaderprogram; @@ -124,6 +128,9 @@ private: bool isPickingActivated = false; float angle_mult; + float frame_mult = 1; + + clockid_t startTime; QOpenGLTexture *s_texture; @@ -174,7 +181,7 @@ private: QMatrix4x4 identityMatrix; QQuaternion rot; - unsigned int frame; + double frame; }; #endif // SIMPLEVIEWER_H