diff --git a/Lighting.java b/Lighting.java index aea7b3f..05347c0 100644 --- a/Lighting.java +++ b/Lighting.java @@ -8,7 +8,7 @@ public class Lighting { static final int NONE = 0; static final int AMBIENT = 1; static final int POINT = 2; - List lights; + List lights; /* Internal Class describing a light source */ private class Light { @@ -22,7 +22,7 @@ public class Lighting { } public Lighting() { - lights = new LinkedList(); + lights = new LinkedList(); } /* Adds a new ambient light source of intensity @ia to the environment. */ @@ -54,13 +54,14 @@ public class Lighting { double[] litColor = new double[3]; /* total light intensity */ double I = 0.0; - Iterator it = lights.iterator(); + Iterator it = lights.iterator(); while (it.hasNext()) { Light light = (Light) it.next(); switch (light.type) { case AMBIENT: - /* Ambient light : A COMPLETER */ - /* I += ... */ + /* Ambient light */ + double Ia = light.params[0]; + I += Ia * ka; break; case POINT: try { @@ -68,19 +69,24 @@ public class Lighting { Vector3 e = new Vector3(cameraPosition); e.subtract(position); e.normalize(); + /* vector from point to light */ Vector3 l = new Vector3(light.params[0], light.params[1], light.params[2]); l.subtract(position); l.normalize(); + /* half-vector between e and l */ Vector3 h = new Vector3(e); h.add(l); h.normalize(); + /* diffuse contribution : A COMPLETER */ - /* double Id = ... */ + double Id = kd * ... + /* specular contribution : A COMPLETER */ - /* double Is = ... */ - /* I += Id + Is; */ + double Is = ks * ... + + I += Id + Is; } catch (InstantiationException ex) { /* should not reach */ } catch (SizeMismatchException ex) { /* should not reach */ } diff --git a/Mesh.java b/Mesh.java index 0eef389..5b2df48 100644 --- a/Mesh.java +++ b/Mesh.java @@ -120,9 +120,17 @@ public class Mesh { try { for (int i = 0; i < 3 * getNumFaces(); i += 3) { - /* A COMPLETER */ + Vector v0 = vertices[i + 0]; + Vector v1 = vertices[i + 1]; + Vector v2 = vertices[i + 2]; - Vector3 n = new Vector3(); // ? + Vector3 bidule_gauche = new Vector3(v1); + bidule_gauche.subtract(v0); + + Vector3 bidule_droite = new Vector3(v2); + bidule_droite.subtract(v0); + + Vector3 n = bidule_gauche.cross(bidule_droite); // ajoute la normale calculee a chq sommet de la face for (int j = 0; j < 3; j++) {