From 047b613e03c0bdd1303088bf25d71178a4c256ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 14 Apr 2022 13:32:08 +0200 Subject: [PATCH] feat: lightning now working --- Lighting.java | 10 +++++----- Mesh.java | 10 +++++++--- Renderer.java | 19 ++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Lighting.java b/Lighting.java index 0f95aad..02948c8 100644 --- a/Lighting.java +++ b/Lighting.java @@ -80,14 +80,14 @@ public class Lighting { h.add(l); h.normalize(); - /* diffuse contribution : A COMPLETER */ + /* diffuse contribution */ double Id = light.params[3]; - double Id = kd *Id* Math.cos(normal,l); + double I_diff = Id * kd * Math.cos(normal.dot(l)); - /* specular contribution : A COMPLETER */ - double Is = ks * Id * Math.cos(h,normal)^2; + /* specular contribution */ + double I_spec = Id * ks * Math.cos(h.dot(normal)); - I += Id + Is; + I += I_diff + I_spec; } catch (InstantiationException ex) { /* should not reach */ } catch (SizeMismatchException ex) { /* should not reach */ } diff --git a/Mesh.java b/Mesh.java index 5b2df48..cd4b95c 100644 --- a/Mesh.java +++ b/Mesh.java @@ -120,9 +120,13 @@ public class Mesh { try { for (int i = 0; i < 3 * getNumFaces(); i += 3) { - Vector v0 = vertices[i + 0]; - Vector v1 = vertices[i + 1]; - Vector v2 = vertices[i + 2]; + int index_v0 = faces[i + 0]; + int index_v1 = faces[i + 1]; + int index_v2 = faces[i + 2]; + + Vector3 v0 = new Vector3(vertices[index_v0]); + Vector3 v1 = new Vector3(vertices[index_v1]); + Vector3 v2 = new Vector3(vertices[index_v2]); Vector3 bidule_gauche = new Vector3(v1); bidule_gauche.subtract(v0); diff --git a/Renderer.java b/Renderer.java index b165901..629afc4 100644 --- a/Renderer.java +++ b/Renderer.java @@ -156,17 +156,13 @@ public class Renderer { screen.swapBuffers(); wait(1); - wait(10); - /* solid rendering, with lighting */ - /* - * screen.clearBuffer (); - * shader.reset (); - * setLightingEnabled (true); - * renderSolid (); - * screen.swapBuffers (); - * wait (3); - */ + screen.clearBuffer(); + shader.reset(); + setLightingEnabled(true); + renderSolid(); + screen.swapBuffers(); + wait(1); /* solid rendering, with texture */ /* @@ -178,9 +174,10 @@ public class Renderer { * setLightingEnabled (true); * renderSolid (); * screen.swapBuffers (); - * wait (3); + * wait (1); */ + wait(5); screen.destroy(); System.exit(0); }