use of org.spongepowered.math.vector.Vector4d in project SpongeCommon by SpongePowered.
the class SpongeTransformation method transformDirection.
@Override
@NonNull
public Vector3d transformDirection(@NonNull final Vector3d original) {
final Vector4d transformed = this.directionTransformation.transform(original.normalize().toVector4(1));
final Vector3d result;
if (this.performRounding) {
result = new Vector3d(GenericMath.round(transformed.x(), 14), GenericMath.round(transformed.y(), 14), GenericMath.round(transformed.z(), 14));
} else {
result = transformed.toVector3();
}
return result.normalize();
}
use of org.spongepowered.math.vector.Vector4d in project SpongeCommon by SpongePowered.
the class SpongeTransformationBuilder method mirror.
@Override
@NonNull
public SpongeTransformationBuilder mirror(@NonNull final Axis axis) {
if (Objects.requireNonNull(axis) == Axis.Y) {
throw new IllegalArgumentException("The Y direction cannot be mirrored.");
}
final Vector4d scale = Vector4d.ONE.sub(axis.toVector3d().toVector4(0).mul(2));
this.transformation = this.transformation.scale(scale);
this.directionTransformation = this.directionTransformation.scale(scale);
// Flip the x or z mirror if that's the axis.
this.flipx = this.flipx ^ axis == Axis.X;
this.flipz = this.flipz ^ axis == Axis.Z;
return this;
}