feat: lightning now working
This commit is contained in:
parent
aac95baa7f
commit
047b613e03
|
@ -80,14 +80,14 @@ public class Lighting {
|
||||||
h.add(l);
|
h.add(l);
|
||||||
h.normalize();
|
h.normalize();
|
||||||
|
|
||||||
/* diffuse contribution : A COMPLETER */
|
/* diffuse contribution */
|
||||||
double Id = light.params[3];
|
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 */
|
/* specular contribution */
|
||||||
double Is = ks * Id * Math.cos(h,normal)^2;
|
double I_spec = Id * ks * Math.cos(h.dot(normal));
|
||||||
|
|
||||||
I += Id + Is;
|
I += I_diff + I_spec;
|
||||||
} catch (InstantiationException ex) {
|
} catch (InstantiationException ex) {
|
||||||
/* should not reach */ } catch (SizeMismatchException ex) {
|
/* should not reach */ } catch (SizeMismatchException ex) {
|
||||||
/* should not reach */ }
|
/* should not reach */ }
|
||||||
|
|
10
Mesh.java
10
Mesh.java
|
@ -120,9 +120,13 @@ public class Mesh {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < 3 * getNumFaces(); i += 3) {
|
for (int i = 0; i < 3 * getNumFaces(); i += 3) {
|
||||||
|
|
||||||
Vector v0 = vertices[i + 0];
|
int index_v0 = faces[i + 0];
|
||||||
Vector v1 = vertices[i + 1];
|
int index_v1 = faces[i + 1];
|
||||||
Vector v2 = vertices[i + 2];
|
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);
|
Vector3 bidule_gauche = new Vector3(v1);
|
||||||
bidule_gauche.subtract(v0);
|
bidule_gauche.subtract(v0);
|
||||||
|
|
|
@ -156,17 +156,13 @@ public class Renderer {
|
||||||
screen.swapBuffers();
|
screen.swapBuffers();
|
||||||
wait(1);
|
wait(1);
|
||||||
|
|
||||||
wait(10);
|
|
||||||
|
|
||||||
/* solid rendering, with lighting */
|
/* solid rendering, with lighting */
|
||||||
/*
|
screen.clearBuffer();
|
||||||
* screen.clearBuffer ();
|
shader.reset();
|
||||||
* shader.reset ();
|
setLightingEnabled(true);
|
||||||
* setLightingEnabled (true);
|
renderSolid();
|
||||||
* renderSolid ();
|
screen.swapBuffers();
|
||||||
* screen.swapBuffers ();
|
wait(1);
|
||||||
* wait (3);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* solid rendering, with texture */
|
/* solid rendering, with texture */
|
||||||
/*
|
/*
|
||||||
|
@ -178,9 +174,10 @@ public class Renderer {
|
||||||
* setLightingEnabled (true);
|
* setLightingEnabled (true);
|
||||||
* renderSolid ();
|
* renderSolid ();
|
||||||
* screen.swapBuffers ();
|
* screen.swapBuffers ();
|
||||||
* wait (3);
|
* wait (1);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
wait(5);
|
||||||
screen.destroy();
|
screen.destroy();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue