From 4bc2581e8ea2c9b03d13ee1a8dea649a9253b478 Mon Sep 17 00:00:00 2001
From: Roncal Jossef <jossef@roncal.ch>
Date: Tue, 15 Dec 2020 04:55:33 +0100
Subject: [PATCH] rotation working

---
 lab4/src/lab4.js | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lab4/src/lab4.js b/lab4/src/lab4.js
index ac88cf4..2ce30a4 100644
--- a/lab4/src/lab4.js
+++ b/lab4/src/lab4.js
@@ -274,7 +274,7 @@ function drawShadowFrustum(gl, program, frustum, viewMatrix, projectionMatrix, m
     g_mvpMatrix.set(shadow.viewProjMatrixFromLight);
     // g_mvpMatrix.set(projectionMatrix);
     // g_mvpMatrix.multiply(viewMatrix);
-    // g_mvpMatrix.multiply(modelMatrix);
+    g_mvpMatrix.multiply(modelMatrix);
 
     shadow.mvpMatrixFromLight_f.set(g_mvpMatrix);
 
@@ -292,7 +292,7 @@ function drawShadowSurface(gl, program, surface, viewMatrix, projectionMatrix, m
     g_mvpMatrix.set(shadow.viewProjMatrixFromLight);
     // g_mvpMatrix.set(projectionMatrix);
     // g_mvpMatrix.multiply(viewMatrix);
-    //g_mvpMatrix.multiply(modelMatrix);
+    g_mvpMatrix.multiply(modelMatrix);
     
     shadow.mvpMatrixFromLight_s.set(g_mvpMatrix);
 
@@ -664,6 +664,7 @@ function main() {
 
     frustum.color = [1.0, 0.0, 0.0, 1.0];
     surface.color = [1.0, 1.0, 1.0, 1.0];
+    frustum.angle = 0.0;
 
     let clicked = 0;
 
@@ -679,7 +680,7 @@ function main() {
     position_x.value = light.init[0];
     position_y.value = light.init[1];
 
-	canvas.addEventListener("mousedown", function(event) {
+	canvas.addEventListener("mousedown", async function(event) {
         let x = event.clientX, y = event.clientY;
         let rect = event.target.getBoundingClientRect();
         if (rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom) {
@@ -691,6 +692,16 @@ function main() {
                 //change color
                 frustum.color = frustum.color[0] == 1.0 ? [0.0, 0.0, 1.0, 1.0] : [1.0, 0.0, 0.0, 1.0];
                 drawScene(gl, canvas, fbo, program, shadowProgram, frustum, surface, projectionMatrix, light, shadow)
+
+                let initAngle = frustum.angle;
+                let finalAngle = (frustum.angle + 180) % 360;
+
+                for(let i = 0; i <= 180; i++) {
+                    frustum.modelMatrix.setRotate((initAngle + i)%360, 0, 0, 1)
+                    drawScene(gl, canvas, fbo, program, shadowProgram, frustum, surface, projectionMatrix, light, shadow)
+                    await sleep(20);
+                }
+                
             } else {
                 onCanvas = true; // si c'est pas un click sur le frustum on effectue une rotation de la camera normal
             }
@@ -772,8 +783,12 @@ function main() {
     for(let i = 0; i < directionnels_radio.length; i++) {
         directionnels_radio[i].addEventListener("click", function() {
             light.directionnel =  this.value;
-
             drawScene(gl, canvas, fbo, program, shadowProgram, frustum, surface, projectionMatrix, light, shadow)
         });
     }
 }
+
+function sleep(time) {
+  return new Promise((resolve) => setTimeout(resolve, time));
+}
+
-- 
GitLab