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

71 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 Translation extends Transformation {
public Vector3 vec;
public Translation(Vector3 vec) {
2013-07-16 17:58:02 +10:00
this.vec = vec;
}
2014-04-07 14:02:47 +10:00
public Translation(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.add(this.vec);
}
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
}
@Override
2014-04-07 14:02:47 +10:00
public void apply(Matrix4 mat) {
2013-07-16 17:58:02 +10:00
mat.translate(vec);
}
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 at(Vector3 point) {
2013-07-16 17:58:02 +10:00
return this;
}
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.glTranslated(vec.x, vec.y, vec.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() {
2013-07-16 17:58:02 +10:00
return new Translation(-vec.x, -vec.y, -vec.z);
}
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 Translation)
2013-09-05 17:41:31 +10:00
return new Translation(vec.copy().add(((Translation) next).vec));
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 vec.equalsT(Vector3.zero);
}
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 "Translation(" + new BigDecimal(vec.x, cont) + ", " + new BigDecimal(vec.y, cont) + ", " + new BigDecimal(vec.z, cont) + ")";
2013-07-16 17:58:02 +10:00
}
}