style: autoformat

This commit is contained in:
Laureηt 2022-04-14 11:33:39 +02:00
parent 08c323f8b3
commit 8fee10f2a5
No known key found for this signature in database
GPG key ID: D88C6B294FD40994

View file

@ -1,37 +1,56 @@
import java.lang.*; import java.util.*; import algebra.*; import java.lang.*;
import java.util.*;
import algebra.*;
/* * The Lighting class describes a scene lighting environment /* * The Lighting class describes a scene lighting environment
* @author: gmorin, smondet */ * @author: gmorin, smondet */
public class Lighting { public class Lighting {
static final int NONE = 0 ; static final int AMBIENT = 1 ; static final int NONE = 0;
static final int AMBIENT = 1;
static final int POINT = 2; static final int POINT = 2;
List lights; List lights;
/* Internal Class describing a light source */ /* Internal Class describing a light source */
private class Light { private class Light {
public int type = NONE; public int type = NONE;
public double[] params; public double[] params;
public Light(int type, double[] params) { public Light(int type, double[] params) {
this.type = type; this.params = params; this.type = type;
this.params = params;
} }
} }
public Lighting() { public Lighting() {
lights = new LinkedList(); } lights = new LinkedList();
}
/* Adds a new ambient light source of intensity @ia to the environment. */ /* Adds a new ambient light source of intensity @ia to the environment. */
public void addAmbientLight(double ia) { public void addAmbientLight(double ia) {
double[] v = new double[1]; double[] v = new double[1];
v[0] = ia; lights.add (new Light (AMBIENT, v)); } v[0] = ia;
lights.add(new Light(AMBIENT, v));
}
/** Addsa */ /** Addsa */
public void addPointLight (double x, double y, double z, double id) public void addPointLight(double x, double y, double z, double id) {
{
double[] v = new double[5]; double[] v = new double[5];
v[0] = x; v[1] = y; v[2] = z; v[3] = id; v[0] = x;
lights.add (new Light (POINT, v)); } v[1] = y;
/* Computes the illuminated color of a 3D points of given position, normal and color, v[2] = z;
v[3] = id;
lights.add(new Light(POINT, v));
}
/*
* Computes the illuminated color of a 3D points of given position, normal and
* color,
* and given the camera position and material parameters. * and given the camera position and material parameters.
* Returns an array of size 3. */ * Returns an array of size 3.
*/
public double[] applyLights(Vector3 position, Vector3 normal, double[] color, public double[] applyLights(Vector3 position, Vector3 normal, double[] color,
Vector3 cameraPosition, Vector3 cameraPosition,
double ka, double kd, double ks, double s) double ka, double kd, double ks, double s) {
{
double[] litColor = new double[3]; double[] litColor = new double[3];
/* total light intensity */ /* total light intensity */
double I = 0.0; double I = 0.0;
@ -62,15 +81,18 @@ public class Lighting {
/* specular contribution : A COMPLETER */ /* specular contribution : A COMPLETER */
/* double Is = ... */ /* double Is = ... */
/* I += Id + Is; */ /* I += Id + Is; */
} catch (InstantiationException ex) { /* should not reach*/ } } catch (InstantiationException ex) {
catch (SizeMismatchException ex) { /* should not reach*/ } /* should not reach */ } catch (SizeMismatchException ex) {
/* should not reach */ }
break; break;
default: default:
/* ignore unknow lights */ /* ignore unknow lights */
break; break;
} }
} }
litColor[0] = I * color[0]; litColor[1] = I * color[1]; litColor[2] = I * color[2]; litColor[0] = I * color[0];
litColor[1] = I * color[1];
litColor[2] = I * color[2];
return litColor; return litColor;
} }
} }