/** * Returns a new transform representing a rotation around an axis, * around a given point. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. The block corner * flag change the point to be the block corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3(Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis .toVector3d())).translate(pointDouble)); }
/** * Adds a a rotation to this transform, around an axis, * around a given point, and returns it as a new transform. * The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The block corner flag changes * the point to be the block upper corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3( this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d())) .translate(pointDouble)); }
Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())).translate( pointDouble));
this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())) .translate(pointDouble));
txMin = (this.max.getX() - start.getX()) / direction.getX(); txMax = (this.min.getX() - start.getX()) / direction.getX(); xNormal = Vector3d.UNIT_X.negate(); tyMin = (this.max.getY() - start.getY()) / direction.getY(); tyMax = (this.min.getY() - start.getY()) / direction.getY(); yNormal = Vector3d.UNIT_Y.negate(); if (tyMin == txMin) { tMin = tyMin; normalMin = xNormal.negate().sub(yNormal); } else if (tyMin > txMin) { tMin = tyMin; normalMin = yNormal.negate(); } else { tMin = txMin; normalMin = xNormal.negate(); tzMin = (this.max.getZ() - start.getZ()) / direction.getZ(); tzMax = (this.min.getZ() - start.getZ()) / direction.getZ(); zNormal = Vector3d.UNIT_Z.negate(); } else if (tzMin > tMin) { tMin = tzMin; normalMin = zNormal.negate();
/** * Returns a new transform representing a rotation around an axis, * around a given point. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. The block corner * flag change the point to be the block corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3(Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis .toVector3d())).translate(pointDouble)); }
/** * Adds a a rotation to this transform, around an axis, * around a given point, and returns it as a new transform. * The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The block corner flag changes * the point to be the block upper corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3( this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d())) .translate(pointDouble)); }
Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())).translate( pointDouble));
this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())) .translate(pointDouble));
txMin = (this.max.getX() - start.getX()) / direction.getX(); txMax = (this.min.getX() - start.getX()) / direction.getX(); xNormal = Vector3d.UNIT_X.negate(); tyMin = (this.max.getY() - start.getY()) / direction.getY(); tyMax = (this.min.getY() - start.getY()) / direction.getY(); yNormal = Vector3d.UNIT_Y.negate(); if (tyMin == txMin) { tMin = tyMin; normalMin = xNormal.negate().sub(yNormal); } else if (tyMin > txMin) { tMin = tyMin; normalMin = yNormal.negate(); } else { tMin = txMin; normalMin = xNormal.negate(); tzMin = (this.max.getZ() - start.getZ()) / direction.getZ(); tzMax = (this.min.getZ() - start.getZ()) / direction.getZ(); zNormal = Vector3d.UNIT_Z.negate(); } else if (tzMin > tMin) { tMin = tzMin; normalMin = zNormal.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 Matrix4d createLookAt(Vector3d eye, Vector3d at, Vector3d up) { final Vector3d f = at.sub(eye).normalize(); final Vector3d s = f.cross(up).normalize(); final Vector3d u = s.cross(f); final Matrix4d mat = new Matrix4d( 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 Matrix4d createLookAt(Vector3d eye, Vector3d at, Vector3d up) { final Vector3d f = at.sub(eye).normalize(); final Vector3d s = f.cross(up).normalize(); final Vector3d u = s.cross(f); final Matrix4d mat = new Matrix4d( 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()); }