/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2006 */ /* Transformation geometrique en coordonnees homogenes */ /* pour un changement de repere de type repere global */ /* vers repere observateur avec l'axe (0.0,1.0,0.0) */ /* vertical en coordonnees observateur */ public class LookAt extends Transformation { public LookAt(float pox,float poy,float poz, float pvx,float pvy,float pvz) throws ArithmeticException { super(); remplissage(pox,poy,poz,pvx,pvy,pvz); } public LookAt(Position po,Position pv) throws ArithmeticException { super(); remplissage(po.getX(),po.getY(),po.getZ(), pv.getX(),pv.getY(),pv.getZ()); } private void remplissage(float pox,float poy,float poz, float pvx,float pvy,float pvz) throws ArithmeticException { float nx = pvx-pox; float ny = pvy-poy; float nz = pvz-poz; float d =(float) Math.sqrt(nx*nx+ny*ny+nz*nz); if ( d == 0 ) { throw new ArithmeticException(); } nx /= d; ny /= d; nz /= d; float a = 1.0F/(float) Math.sqrt(1.0F-ny*ny); this.c[0][0] = -a*nz; this.c[0][2] = a*nx; this.c[0][3] = a*(pox*nz-poz*nx); this.c[1][0] = -a*nx*ny; this.c[1][1] = 1.0F/a; this.c[1][2] = -a*ny*nz; this.c[1][3] = a*ny*(pox*nx+poz*nz)-poy/a; this.c[2][0] = -nx; this.c[2][1] = -ny; this.c[2][2] = -nz; this.c[2][3] = pox*nx+poy*ny+poz*nz; } }