com.parzivail.util.math.Transform Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
package com.parzivail.util.math;
import com.google.common.collect.Queues;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import java.util.Deque;
import net.minecraft.class_156;
public class Transform
{
public static final class State
{
final Matrix4f modelMatrix;
State(Matrix4f matrix4f)
{
this.modelMatrix = matrix4f;
}
public Matrix4f getModel()
{
return this.modelMatrix;
}
}
private final Deque stack = class_156.method_654(Queues.newArrayDeque(), (stack) -> {
stack.add(new State(new Matrix4f()));
});
public void translate(double x, double y, double z)
{
this.stack.getLast().modelMatrix.translate((float)x, (float)y, (float)z);
}
public void scale(float x, float y, float z)
{
this.stack.getLast().modelMatrix.scale(x, y, z);
}
public void multiply(Matrix4f matrix4f)
{
this.stack.getLast().modelMatrix.mul(matrix4f);
}
public void multiply(Quaternionf quaternion)
{
this.stack.getLast().modelMatrix.rotate(quaternion);
}
public void save()
{
var state = this.stack.getLast();
this.stack.addLast(new State(new Matrix4f(state.modelMatrix)));
}
public void restore()
{
this.stack.removeLast();
}
public State value()
{
return this.stack.getLast();
}
public boolean isEmpty()
{
return this.stack.size() == 1;
}
public void loadIdentity()
{
this.stack.getLast().modelMatrix.identity();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy