Images en lancer de rayons (à gauche) et en Z-Buffer sous OpenGL (à droite)
Fichier source : Direction3D.h
Direction3D *reflexion(Direction3D *n);
int reflexion(Direction3D *i,Direction3D *n);
int transmission(Direction3D *i,Direction3D *n,double niSurNt);
Fichier source : Direction3D.cpp
Direction3D *Direction3D::reflexion(Direction3D *n) {
double ps = produitScalaire(n);
if ( ps < 0.0 )
return(NULL);
Direction3D *r = new Direction3D();
r->c[0] = 2.0*ps*n->c[0]-c[0];
r->c[1] = 2.0*ps*n->c[1]-c[1];
r->c[2] = 2.0*ps*n->c[2]-c[2];
return(r);
}
int Direction3D::reflexion(Direction3D *i,Direction3D *n) {
double ps = i->produitScalaire(n);
if ( ps < 0.0 )
return(0);
c[0] = 2.0*ps*n->c[0]-i->c[0];
c[1] = 2.0*ps*n->c[1]-i->c[1];
c[2] = 2.0*ps*n->c[2]-i->c[2];
c[3] = 0.0;
return(1);
}
int Direction3D::transmission(Direction3D *i,Direction3D *n,double niSurNt) {
double ps = i->produitScalaire(n);
double v = 1.0-(niSurNt*niSurNt*(1.0-ps*ps));
if ( v < 0.0 )
return(0);
v = niSurNt*ps-sqrt(v);
c[0] = v*n->c[0] - niSurNt*i->c[0];
c[1] = v*n->c[1] - niSurNt*i->c[1];
c[2] = v*n->c[2] - niSurNt*i->c[2];
c[3] = 0.0;
return(1);
}