/** * @see <a href="gluLookAt.html">gluLookAt</a> */ public void look_at(double eyex, double eyey, double eyez, double centerx, double centery, double centerz, double upx, double upy, double upz) { Matrix4d matrix = new Matrix4d (); Vector4d eye = new Vector4d (eyex, eyey, eyez, 1.0); Vector4d center = new Vector4d (centerx, centery, centerz, 1.0); Vector4d up = new Vector4d (upx, upy, upz, 1.0); Vector4d forward = new Vector4d (); Vector4d side = new Vector4d (); //-- make rotation matrix // forward = center - eye forward.minus (center, eye).normalize (); // side = (forward x up), then normalized side.cross (forward, up).normalize (); // up = side x forward up.cross (side, forward); /* [side_x up_x -forward_x 0] * [side_y up_y -forward_y 0] * [side_z up_z -forward_z 0] * [ 0 0 0 1] */ matrix.set_column (side, up, forward.negate (), Vector4d.ZERO); matrix.set_row (3, 0.0, 0.0, 0.0, 1.0); gl.mult_matrixd (matrix.m); //-- translate eye to origin gl.translated (-eyex, -eyey, -eyez); }
/** * @see <a href="gluUnProject.html">gluUnProject</a> */ public double[] un_project(double window_x, double window_y, double window_z, double [] modelview, double [] projection, int [] viewport) { Matrix4d product = new Matrix4d (); Matrix4d.multiply (modelview, projection, product.m); if (product.invert () == null) return null; Vector4d A = new Vector4d (window_x, window_y, window_z, 1.0); // map x and y from window coordinates A.v [0] = (A.v [0] - viewport [0]) / viewport [2]; A.v [1] = (A.v [1] - viewport [1]) / viewport [3]; // map to range -1 to 1, A = 2*A - I A.scalar_multiply (2).scalar_minus (1); A.multiply_right (product); double d = A.v [3]; if (d == 0) return null; double [] result = new double [3]; // vs. 4 result [0] = A.v [0] / d; result [1] = A.v [1] / d; result [2] = A.v [2] / d; return result; }
public Matrix4d set_row(Vector4d V0, Vector4d V1, Vector4d V2, Vector4d V3) { set_row (m, V0.v, V1.v, V2.v, V3.v); return this; }
/** * @see <a href="gluProject.html">gluProject</a> */ public double[] project(double object_x, double object_y, double object_z, double [] modelview, double [] projection, int [] viewport) { Vector4d window = new Vector4d (); return window.v; }
public Matrix4d set_column(int i, Vector4d A) { set_column (m, i, A.v); return this; }
public Matrix4d set_row(int j, Vector4d A) { set_row (m, j, A.v); return this; }
public Vector4d scalar_minus(Vector4d A, double d) { scalar_minus (A.v, d, v); return this; }
public Vector4d scalar_multiply(Vector4d A, double d) { scalar_multiply (A.v, d, v); return this; }
public Vector4d normalize(Vector4d A) { normalize (A.v, v); return this; }
public Vector4d scalar_divide(Vector4d A, double d) { scalar_divide (A.v, d, v); return this; }
public Vector4d negate(Vector4d A) { negate (A.v, v); return this; }
public Vector4d multiply_right(Vector4d V, Matrix4d A) { double [] B = v; if (V == this) B = new double [4]; v = multiply_right (V.v, A.m, B); return this; }
public Vector4d multiply_left(Matrix4d A, Vector4d V) { double [] B = v; if (V == this) B = new double [4]; v = multiply_left (A.m, V.v, B); return this; }
public Vector4d minus(Vector4d A, Vector4d B) { minus (A.v, B.v, v); return this; }
public Vector4d cross(Vector4d A, Vector4d B) { double [] C = v; if (A == this || B == this) C = new double [4]; v = cross (A.v, B.v, C); return this; }