/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class Position {
public float x;
public float y;
public float z;
public Position() {
x = y = z = 0.0F;
}
public Position(float x,float y,float z) {
this.x = x;
this.y = y;
this.z = z;
}
public Position(Position p) {
x = p.x;
y = p.y;
z = p.z;
}
public float distance(Position p) {
float dx = p.x - x;
float dy = p.y - y;
float dz = p.z - z;
return((float) Math.sqrt(dx*dx + dy*dy + dz*dz));
}
public float carreDistance(Position p) {
float dx = p.x - x;
float dy = p.y - y;
float dz = p.z - z;
return(dx*dx + dy*dy + dz*dz);
}
public String toString() {
return("["+x+","+y+","+z+"]");
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class Direction {
public float dx;
public float dy;
public float dz;
public Direction() {
dx = dy = 0.0F;
dz = -1.0F;
}
public Direction(float dx,float dy,float dz) {
this.dx = dx;
this.dy = dy;
this.dz = dz;
}
public Direction(Direction d) {
dx = d.dx;
dy = d.dy;
dz = d.dz;
}
public Direction(Position p1,Position p2) {
dx = p2.x-p1.x;
dy = p2.y-p1.y;
dz = p2.z-p1.z;
normalise();
}
public float norme() {
return((float) Math.sqrt(dx*dx + dy*dy + dz*dz));
}
public void normalise() {
float norme = norme();
if ( norme != 0 ) {
dx /= norme;
dy /= norme;
dz /= norme; }
}
public float produitScalaire(Direction d) {
return(dx*d.dx + dy*d.dy + dz*d.dz);
}
public static float produitScalaire(Direction d1,Direction d2) {
return(d1.dx*d2.dx + d1.dy*d2.dy + d1.dz*d2.dz);
}
public String toString() {
return("["+dx+","+dy+","+dz+"]");
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class Couleur {
public float r;
public float v;
public float b;
public Couleur() {
r = v = b = 0.0F;
}
public Couleur(float r,float v,float b) {
this.r = r;
this.v = v;
this.b = b;
}
public Couleur(Couleur c) {
r = c.r;
v = c.v;
b = c.b;
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class Materiel {
public Couleur kd;
public Materiel() {
kd = new Couleur(0.8F,0.8F,0.8F);
}
public Materiel(Materiel m) {
kd = new Couleur(m.kd);
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class LumiereDirectionnelle {
public Direction d;
public Couleur c;
public float i;
public LumiereDirectionnelle() {
d = new Direction();
c = new Couleur(1.0F,1.0F,1.0F);
i = 1.0F;
}
public LumiereDirectionnelle(LumiereDirectionnelle ld) {
d = new Direction(ld.d);
c = new Couleur(ld.c);
i = ld.i;
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class LumierePonctuelle {
public Position p;
public Couleur c;
public float i;
public LumierePonctuelle() {
p = new Position();
c = new Couleur(1.0F,1.0F,1.0F);
i = 1.0F;
}
public LumierePonctuelle(LumierePonctuelle lp) {
p = new Position(lp.p);
c = new Couleur(lp.c);
i = lp.i;
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2006 */
public class Energie {
public float r;
public float v;
public float b;
public Energie() {
r = v = b = 0.0F;
}
public Energie(float r,float v,float b) {
this.r = r;
this.v = v;
this.b = b;
}
public Energie(Energie e) {
r = e.r;
v = e.v;
b = e.b;
}
public Energie(LumiereDirectionnelle ld,Materiel m,Direction n) {
float ps = -ld.d.produitScalaire(n);
if ( ps <= 0.0F ) {
r = v = b = 0.0F;
return; }
float fact = ps*ld.i;
r = fact*ld.c.r*m.kd.r;
v = fact*ld.c.v*m.kd.v;
b = fact*ld.c.b*m.kd.b;
}
public Energie(LumierePonctuelle lp,Materiel m,Direction n,Position p) {
Direction l = new Direction(p,lp.p);
float ps = l.produitScalaire(n);
if ( ps <= 0.0F ) {
r = v = b = 0.0F;
return; }
float fact = ps*lp.i/lp.p.carreDistance(p);
r = fact*lp.c.r*m.kd.r;
v = fact*lp.c.v*m.kd.v;
b = fact*lp.c.b*m.kd.b;
}
}