/** * Gets the vector representing the forward direction for the camera. * * @return The camera's forward direction vector */ public Vector3f getForward() { return toCamera(Vector3f.FORWARD.negate()); }
/** * Returns the view matrix, which is the transformation matrix for the position and rotation. * * @return The view matrix */ public Matrix4f getViewMatrix() { if (updateViewMatrix) { rotationMatrixInverse = Matrix4f.createRotation(rotation); final Matrix4f rotationMatrix = Matrix4f.createRotation(rotation.invert()); final Matrix4f positionMatrix = Matrix4f.createTranslation(position.negate()); viewMatrix = rotationMatrix.mul(positionMatrix); updateViewMatrix = false; } return viewMatrix; }
/** * Creates a "look at" matrix for the given eye point. * * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static Matrix4f createLookAt(Vector3f eye, Vector3f at, Vector3f up) { final Vector3f f = at.sub(eye).normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f); final Matrix4f mat = new Matrix4f( s.getX(), s.getY(), s.getZ(), 0, u.getX(), u.getY(), u.getZ(), 0, -f.getX(), -f.getY(), -f.getZ(), 0, 0, 0, 0, 1); return mat.translate(eye.negate()); }
/** * Creates a "look at" matrix for the given eye point. * * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static Matrix4f createLookAt(Vector3f eye, Vector3f at, Vector3f up) { final Vector3f f = at.sub(eye).normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f); final Matrix4f mat = new Matrix4f( s.getX(), s.getY(), s.getZ(), 0, u.getX(), u.getY(), u.getZ(), 0, -f.getX(), -f.getY(), -f.getZ(), 0, 0, 0, 0, 1); return mat.translate(eye.negate()); }
final Vector3f bottom = top.negate();
final Vector3f p0 = p6.negate(); final Vector3f p7 = new Vector3f(-p.getX(), p.getY(), p.getZ()); final Vector3f p1 = p7.negate(); final Vector3f p4 = new Vector3f(-p.getX(), p.getY(), -p.getZ()); final Vector3f p2 = p4.negate(); final Vector3f p5 = new Vector3f(p.getX(), p.getY(), -p.getZ()); final Vector3f p3 = p5.negate(); final Vector3f p0 = p6.negate(); final Vector3f p7 = new Vector3f(-p.getX(), p.getY(), p.getZ()); final Vector3f p1 = p7.negate(); final Vector3f p4 = new Vector3f(-p.getX(), p.getY(), -p.getZ()); final Vector3f p2 = p4.negate(); final Vector3f p5 = new Vector3f(p.getX(), p.getY(), -p.getZ()); final Vector3f p3 = p5.negate();