Files
CodeChickenCore/codechicken/lib/vec/Scale.java
T

70 lines
1.6 KiB
Java
Raw Normal View History

2013-07-16 17:58:02 +10:00
package codechicken.lib.vec;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2014-04-07 14:02:47 +10:00
public class Scale extends Transformation {
public Vector3 factor;
public Scale(Vector3 factor) {
2013-07-16 17:58:02 +10:00
this.factor = factor;
}
2014-04-07 14:02:47 +10:00
public Scale(double factor) {
2013-07-16 17:58:02 +10:00
this(new Vector3(factor, factor, factor));
}
2014-04-07 14:02:47 +10:00
public Scale(double x, double y, double z) {
2013-07-16 17:58:02 +10:00
this(new Vector3(x, y, z));
}
@Override
2014-04-07 14:02:47 +10:00
public void apply(Vector3 vec) {
2013-07-16 17:58:02 +10:00
vec.multiply(factor);
}
2014-04-07 14:02:47 +10:00
2013-07-16 17:58:02 +10:00
@Override
2014-04-07 14:02:47 +10:00
public void applyN(Vector3 normal) {
2013-07-16 17:58:02 +10:00
}
2014-04-07 14:02:47 +10:00
2013-07-16 17:58:02 +10:00
@Override
2014-04-07 14:02:47 +10:00
public void apply(Matrix4 mat) {
2013-07-16 17:58:02 +10:00
mat.scale(factor);
}
2014-04-07 14:02:47 +10:00
2013-07-16 17:58:02 +10:00
@Override
@SideOnly(Side.CLIENT)
2014-04-07 14:02:47 +10:00
public void glApply() {
2013-07-16 17:58:02 +10:00
GL11.glScaled(factor.x, factor.y, factor.z);
}
2014-04-07 14:02:47 +10:00
2013-07-16 17:58:02 +10:00
@Override
2014-04-07 14:02:47 +10:00
public Transformation inverse() {
return new Scale(1 / factor.x, 1 / factor.y, 1 / factor.z);
2013-07-16 17:58:02 +10:00
}
2014-04-07 14:02:47 +10:00
2013-08-29 11:10:33 +10:00
@Override
public Transformation merge(Transformation next) {
2014-04-07 14:02:47 +10:00
if (next instanceof Scale)
2013-09-05 17:41:31 +10:00
return new Scale(factor.copy().multiply(((Scale) next).factor));
2014-04-07 14:02:47 +10:00
2013-08-29 11:10:33 +10:00
return null;
}
2014-04-07 14:02:47 +10:00
2013-09-05 17:41:31 +10:00
@Override
public boolean isRedundant() {
return factor.equalsT(Vector3.one);
}
2014-04-07 14:02:47 +10:00
2013-07-16 17:58:02 +10:00
@Override
2014-04-07 14:02:47 +10:00
public String toString() {
2013-07-16 17:58:02 +10:00
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
2014-04-07 14:02:47 +10:00
return "Scale(" + new BigDecimal(factor.x, cont) + ", " + new BigDecimal(factor.y, cont) + ", " + new BigDecimal(factor.z, cont) + ")";
2013-07-16 17:58:02 +10:00
}
}