2025-11-24 22:52:51 +03:00

46 lines
1.7 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.joml.Matrix4f
* org.joml.Matrix4fc
* org.joml.Vector3f
* org.joml.Vector3fc
*/
package net.minecraft.client.renderer.block.model;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
public record BlockElementRotation(Vector3fc origin, Direction.Axis axis, float angle, boolean rescale, Matrix4fc transform) {
private static final Vector3fc NO_RESCALE = new Vector3f(1.0f, 1.0f, 1.0f);
public BlockElementRotation(Vector3fc origin, Direction.Axis axis, float angle, boolean rescale) {
this(origin, axis, angle, rescale, (Matrix4fc)BlockElementRotation.computeTransform(axis, angle, rescale));
}
private static Matrix4f computeTransform(Direction.Axis axis, float angle, boolean rescale) {
Vector3fc rotateAround = axis.getPositive().getUnitVec3f();
return new Matrix4f().rotation(angle * ((float)Math.PI / 180), rotateAround).scale(BlockElementRotation.computeRescale(rescale, angle, axis));
}
private static Vector3fc computeRescale(boolean rescale, float angle, Direction.Axis axis) {
if (!rescale || angle == 0.0f) {
return NO_RESCALE;
}
float absAngle = Math.abs(angle);
float scale = 1.0f / Mth.cos(absAngle * ((float)Math.PI / 180));
return switch (axis) {
default -> throw new MatchException(null, null);
case Direction.Axis.X -> new Vector3f(1.0f, scale, scale);
case Direction.Axis.Y -> new Vector3f(scale, 1.0f, scale);
case Direction.Axis.Z -> new Vector3f(scale, scale, 1.0f);
};
}
}