Transformation.java
com.mojang.math.Transformation
信息
- 全限定名:com.mojang.math.Transformation
- 类型:public final class
- 包:com.mojang.math
- 源码路径:src/main/java/com/mojang/math/Transformation.java
- 起始行号:L19
- 职责:
TODO
字段/常量
-
ZERO_TRANSLATION- 类型:
Vector3fc - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
UNIT_SCALE- 类型:
Vector3fc - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
ZERO_ROTATION- 类型:
Quaternionfc - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
matrix- 类型:
Matrix4fc - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
CODEC- 类型:
Codec<Transformation> - 修饰符:
public static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
EXTENDED_CODEC- 类型:
Codec<Transformation> - 修饰符:
public static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
decomposed- 类型:
boolean - 修饰符:
private - 源码定位:
L36 - 说明:
TODO
- 类型:
-
translation- 类型:
Vector3fc - 修饰符:
private - 源码定位:
L37 - 说明:
TODO
- 类型:
-
leftRotation- 类型:
Quaternionfc - 修饰符:
private - 源码定位:
L38 - 说明:
TODO
- 类型:
-
scale- 类型:
Vector3fc - 修饰符:
private - 源码定位:
L39 - 说明:
TODO
- 类型:
-
rightRotation- 类型:
Quaternionfc - 修饰符:
private - 源码定位:
L40 - 说明:
TODO
- 类型:
-
IDENTITY- 类型:
Transformation - 修饰符:
public static final - 源码定位:
L41 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public Transformation(Matrix4fc matrix) @ L51
- 构造器名:Transformation
- 源码定位:L51
- 修饰符:public
参数:
- matrix: Matrix4fc
说明:
TODO
public Transformation(Vector3fc translation, Quaternionfc leftRotation, Vector3fc scale, Quaternionfc rightRotation) @ L55
- 构造器名:Transformation
- 源码定位:L55
- 修饰符:public
参数:
- translation: Vector3fc
- leftRotation: Quaternionfc
- scale: Vector3fc
- rightRotation: Quaternionfc
说明:
TODO
方法
下面的方法块按源码顺序生成。
public Transformation compose(Transformation that) @ L64
- 方法名:compose
- 源码定位:L64
- 返回类型:Transformation
- 修饰符:public
参数:
- that: Transformation
说明:
TODO
public Transformation inverse() @ L70
- 方法名:inverse
- 源码定位:L70
- 返回类型:Transformation
- 修饰符:public
参数:
- 无
说明:
TODO
private void ensureDecomposed() @ L79
- 方法名:ensureDecomposed
- 源码定位:L79
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private static Matrix4f compose(Vector3fc translation, Quaternionfc leftRotation, Vector3fc scale, Quaternionfc rightRotation) @ L91
- 方法名:compose
- 源码定位:L91
- 返回类型:Matrix4f
- 修饰符:private static
参数:
- translation: Vector3fc
- leftRotation: Quaternionfc
- scale: Vector3fc
- rightRotation: Quaternionfc
说明:
TODO
public Matrix4fc getMatrix() @ L114
- 方法名:getMatrix
- 源码定位:L114
- 返回类型:Matrix4fc
- 修饰符:public
参数:
- 无
说明:
TODO
public Matrix4f getMatrixCopy() @ L118
- 方法名:getMatrixCopy
- 源码定位:L118
- 返回类型:Matrix4f
- 修饰符:public
参数:
- 无
说明:
TODO
public Vector3fc translation() @ L122
- 方法名:translation
- 源码定位:L122
- 返回类型:Vector3fc
- 修饰符:public
参数:
- 无
说明:
TODO
public Quaternionfc leftRotation() @ L127
- 方法名:leftRotation
- 源码定位:L127
- 返回类型:Quaternionfc
- 修饰符:public
参数:
- 无
说明:
TODO
public Vector3fc scale() @ L132
- 方法名:scale
- 源码定位:L132
- 返回类型:Vector3fc
- 修饰符:public
参数:
- 无
说明:
TODO
public Quaternionfc rightRotation() @ L137
- 方法名:rightRotation
- 源码定位:L137
- 返回类型:Quaternionfc
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean equals(Object o) @ L142
- 方法名:equals
- 源码定位:L142
- 返回类型:boolean
- 修饰符:public
参数:
- o: Object
说明:
TODO
public int hashCode() @ L154
- 方法名:hashCode
- 源码定位:L154
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public Transformation slerp(Transformation that, float progress) @ L159
- 方法名:slerp
- 源码定位:L159
- 返回类型:Transformation
- 修饰符:public
参数:
- that: Transformation
- progress: float
说明:
TODO
public static Matrix4fc compose(Matrix4fc parent, Optional<Transformation> transform) @ L168
- 方法名:compose
- 源码定位:L168
- 返回类型:Matrix4fc
- 修饰符:public static
参数:
- parent: Matrix4fc
- transform: Optional
说明:
TODO
代码
public final class Transformation {
private static final Vector3fc ZERO_TRANSLATION = new Vector3f();
private static final Vector3fc UNIT_SCALE = new Vector3f(1.0F, 1.0F, 1.0F);
private static final Quaternionfc ZERO_ROTATION = new Quaternionf();
private final Matrix4fc matrix;
public static final Codec<Transformation> CODEC = RecordCodecBuilder.create(
i -> i.group(
ExtraCodecs.VECTOR3F.fieldOf("translation").forGetter(Transformation::translation),
ExtraCodecs.QUATERNIONF.fieldOf("left_rotation").forGetter(Transformation::leftRotation),
ExtraCodecs.VECTOR3F.fieldOf("scale").forGetter(Transformation::scale),
ExtraCodecs.QUATERNIONF.fieldOf("right_rotation").forGetter(Transformation::rightRotation)
)
.apply(i, Transformation::new)
);
public static final Codec<Transformation> EXTENDED_CODEC = Codec.withAlternative(
CODEC, ExtraCodecs.MATRIX4F.xmap(Transformation::new, Transformation::getMatrix)
);
private boolean decomposed;
private @Nullable Vector3fc translation;
private @Nullable Quaternionfc leftRotation;
private @Nullable Vector3fc scale;
private @Nullable Quaternionfc rightRotation;
public static final Transformation IDENTITY = Util.make(() -> {
Transformation identity = new Transformation(new Matrix4f());
identity.translation = ZERO_TRANSLATION;
identity.leftRotation = ZERO_ROTATION;
identity.scale = UNIT_SCALE;
identity.rightRotation = ZERO_ROTATION;
identity.decomposed = true;
return identity;
});
public Transformation(Matrix4fc matrix) {
this.matrix = matrix;
}
public Transformation(@Nullable Vector3fc translation, @Nullable Quaternionfc leftRotation, @Nullable Vector3fc scale, @Nullable Quaternionfc rightRotation) {
this.matrix = compose(translation, leftRotation, scale, rightRotation);
this.translation = Objects.requireNonNullElse(translation, ZERO_TRANSLATION);
this.leftRotation = Objects.requireNonNullElse(leftRotation, ZERO_ROTATION);
this.scale = Objects.requireNonNullElse(scale, UNIT_SCALE);
this.rightRotation = Objects.requireNonNullElse(rightRotation, ZERO_ROTATION);
this.decomposed = true;
}
public Transformation compose(Transformation that) {
Matrix4f matrix = this.getMatrixCopy();
matrix.mul(that.getMatrix());
return new Transformation(matrix);
}
public @Nullable Transformation inverse() {
if (this == IDENTITY) {
return this;
} else {
Matrix4f matrix = this.getMatrixCopy().invertAffine();
return matrix.isFinite() ? new Transformation(matrix) : null;
}
}
private void ensureDecomposed() {
if (!this.decomposed) {
float scaleFactor = 1.0F / this.matrix.m33();
Triple<Quaternionf, Vector3f, Quaternionf> triple = MatrixUtil.svdDecompose(new Matrix3f(this.matrix).scale(scaleFactor));
this.translation = this.matrix.getTranslation(new Vector3f()).mul(scaleFactor);
this.leftRotation = new Quaternionf(triple.getLeft());
this.scale = new Vector3f(triple.getMiddle());
this.rightRotation = new Quaternionf(triple.getRight());
this.decomposed = true;
}
}
private static Matrix4f compose(
@Nullable Vector3fc translation, @Nullable Quaternionfc leftRotation, @Nullable Vector3fc scale, @Nullable Quaternionfc rightRotation
) {
Matrix4f result = new Matrix4f();
if (translation != null) {
result.translation(translation);
}
if (leftRotation != null) {
result.rotate(leftRotation);
}
if (scale != null) {
result.scale(scale);
}
if (rightRotation != null) {
result.rotate(rightRotation);
}
return result;
}
public Matrix4fc getMatrix() {
return this.matrix;
}
public Matrix4f getMatrixCopy() {
return new Matrix4f(this.matrix);
}
public Vector3fc translation() {
this.ensureDecomposed();
return this.translation;
}
public Quaternionfc leftRotation() {
this.ensureDecomposed();
return this.leftRotation;
}
public Vector3fc scale() {
this.ensureDecomposed();
return this.scale;
}
public Quaternionfc rightRotation() {
this.ensureDecomposed();
return this.rightRotation;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o != null && this.getClass() == o.getClass()) {
Transformation that = (Transformation)o;
return Objects.equals(this.matrix, that.matrix);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hash(this.matrix);
}
public Transformation slerp(Transformation that, float progress) {
return new Transformation(
this.translation().lerp(that.translation(), progress, new Vector3f()),
this.leftRotation().slerp(that.leftRotation(), progress, new Quaternionf()),
this.scale().lerp(that.scale(), progress, new Vector3f()),
this.rightRotation().slerp(that.rightRotation(), progress, new Quaternionf())
);
}
public static Matrix4fc compose(Matrix4fc parent, Optional<Transformation> transform) {
return (Matrix4fc)(transform.isPresent() ? parent.mul(transform.get().getMatrix(), new Matrix4f()) : parent);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
MatrixUtil.svdDecompose()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.make()
- 引用位置: