public Vector3f cross(double x, double y, double z) { return cross((float) x, (float) y, (float) z); }
public Vector3f cross(Vector3f v) { return cross(v.x, v.y, v.z); }
public Vector3f cross(Vector3f v) { return cross(v.x, v.y, v.z); }
public Vector3f cross(double x, double y, double z) { return cross((float) x, (float) y, (float) z); }
/** * Creates a new quaternion from the angle-axis rotation defined from the first to the second vector. * * @param from The first vector * @param to The second vector * @return The quaternion defined by the angle-axis rotation between the vectors */ public static Quaternionf fromRotationTo(Vector3f from, Vector3f to) { return Quaternionf.fromAngleRadAxis(TrigMath.acos(from.dot(to) / (from.length() * to.length())), from.cross(to)); }
/** * Creates a new quaternion from the angle-axis rotation defined from the first to the second vector. * * @param from The first vector * @param to The second vector * @return The quaternion defined by the angle-axis rotation between the vectors */ public static Quaternionf fromRotationTo(Vector3f from, Vector3f to) { return Quaternionf.fromAngleRadAxis(TrigMath.acos(from.dot(to) / (from.length() * to.length())), from.cross(to)); }
private static boolean checkForOverlap(Vector3f p0, Vector3f v0, Vector3f p1, Vector3f v1) { final Vector3f p10 = p1.sub(p0); if (!isZero(p10.cross(v0))) { return false; } float t = getNonNaN(p10.div(v0)); if (t >= 0 && t <= 1) { return true; } t = getNonNaN(p0.sub(p1).div(v1)); return t >= 0 && t <= 1; }
/** * 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()); }
if (isZero(v00.cross(v10)) && checkForOverlap(p00, v00, p10, v10)) { return new Vector2i(0, 0); } else if (isZero(v00.cross(v11)) && checkForOverlap(p00, v00, p11, v11)) { return new Vector2i(0, 1); } else if (isZero(v00.cross(v12)) && checkForOverlap(p00, v00, p12, v12)) { return new Vector2i(0, 2); } else if (isZero(v01.cross(v10)) && checkForOverlap(p01, v01, p10, v10)) { return new Vector2i(1, 0); } else if (isZero(v01.cross(v11)) && checkForOverlap(p01, v01, p11, v11)) { return new Vector2i(1, 1); } else if (isZero(v01.cross(v12)) && checkForOverlap(p01, v01, p12, v12)) { return new Vector2i(1, 2); } else if (isZero(v02.cross(v10)) && checkForOverlap(p02, v02, p10, v10)) { return new Vector2i(2, 0); } else if (isZero(v02.cross(v11)) && checkForOverlap(p02, v02, p11, v11)) { return new Vector2i(2, 1); } else if (isZero(v02.cross(v12)) && checkForOverlap(p02, v02, p12, v12)) { return new Vector2i(2, 2); } else {
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @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 MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @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 MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }