Ejemplo n.º 1
0
        /**
         * @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);
        }