/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2001 */ public class Transform3D { public double [][] m = new double[4][4]; public Transform3D() { for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) m[i][j] = 0.0 ; } public void toIdentite() { for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) m[i][j] = ( i == j ) ? 1.0 : 0.0 ; } public void toTranslation(double dx,double dy,double dz) { toIdentite(); m[0][3] = dx; m[1][3] = dy; m[2][3] = dz; } public void toRotationX(double a) { toIdentite(); m[2][1] = Math.sin(a); m[1][2] = -m[2][1]; m[1][1] = m[2][2] = Math.cos(a); } public void toRotationY(double a) { toIdentite(); m[0][2] = Math.sin(a); m[2][0] = -m[0][2]; m[0][0] = m[2][2] = Math.cos(a); } public void toRotationZ(double a) { toIdentite(); m[1][0] = Math.sin(a); m[0][1] = -m[1][0]; m[1][1] = m[0][0] = Math.cos(a); } public Vector3d mult(Vector3d v) { Vector3d r = new Vector3d(); r.x = m[0][0]*v.x+m[0][1]*v.y+m[0][2]*v.z+m[0][3]; r.y = m[1][0]*v.x+m[1][1]*v.y+m[1][2]*v.z+m[1][3]; r.z = m[2][0]*v.x+m[2][1]*v.y+m[2][2]*v.z+m[2][3]; return(r); } }