mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-16 10:44:51 +00:00
Initial 1.7 commit
This commit is contained in:
1 parent
34154fc011
commit
ca675b5f31
72 files changed
+2967
-3335
No files matched your search
@@ -1,9 +1,10 @@
|
||||
package codechicken.lib.vec;
|
||||
|
||||
import codechicken.lib.util.Copyable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import codechicken.lib.math.MathHelper;
|
||||
|
||||
public class BlockCoord implements Comparable<BlockCoord>
|
||||
public class BlockCoord implements Comparable<BlockCoord>, Copyable<BlockCoord>
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
@@ -4,10 +4,11 @@ import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import codechicken.lib.util.Copyable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
public class Cuboid6
|
||||
public class Cuboid6 implements Copyable<Cuboid6>
|
||||
{
|
||||
public static Cuboid6 full = new Cuboid6(0, 0, 0, 1, 1, 1);
|
||||
|
||||
@@ -47,7 +48,23 @@ public class Cuboid6
|
||||
{
|
||||
return new Cuboid6(this);
|
||||
}
|
||||
|
||||
|
||||
public Cuboid6 set(Cuboid6 c) {
|
||||
return set(c.min, c.max);
|
||||
}
|
||||
|
||||
public Cuboid6 set(Vector3 min, Vector3 max) {
|
||||
this.min.set(min);
|
||||
this.max.set(max);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Cuboid6 set(double minx, double miny, double minz, double maxx, double maxy, double maxz) {
|
||||
min.set(minx, miny, minz);
|
||||
max.set(maxx, maxy, maxz);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Cuboid6 add(Vector3 vec)
|
||||
{
|
||||
min.add(vec);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package codechicken.lib.vec;
|
||||
|
||||
import codechicken.lib.util.Copyable;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CuboidCoord implements Iterable<BlockCoord>
|
||||
public class CuboidCoord implements Iterable<BlockCoord>, Copyable<CuboidCoord>
|
||||
{
|
||||
public BlockCoord min;
|
||||
public BlockCoord max;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package codechicken.lib.vec;
|
||||
|
||||
/**
|
||||
* Abstract supertype for any VectorN transformation
|
||||
* @param <Vector> The vector type
|
||||
* @param <Transformation> The transformation type
|
||||
*/
|
||||
public abstract class ITransformation<Vector, Transformation extends ITransformation>
|
||||
{
|
||||
/**
|
||||
* Applies this transformation to vec
|
||||
*/
|
||||
public abstract void apply(Vector vec);
|
||||
|
||||
/**
|
||||
* @param point The point to apply this transformation around
|
||||
* @return Wraps this transformation in a translation to point and then back from point
|
||||
*/
|
||||
public abstract Transformation at(Vector point);
|
||||
|
||||
/**
|
||||
* Creates a TransformationList composed of this transformation followed by t
|
||||
* If this is a TransformationList, the transformation will be appended and this returned
|
||||
*/
|
||||
public abstract Transformation with(Transformation t);
|
||||
|
||||
/**
|
||||
* Returns a simplified transformation that performs this, followed by next. If such a transformation does not exist, returns null
|
||||
*/
|
||||
public Transformation merge(Transformation next) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this transformation is redundant, eg. Scale(1, 1, 1), Translation(0, 0, 0) or Rotation(0, a, b, c)
|
||||
*/
|
||||
public boolean isRedundant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract Transformation inverse();
|
||||
|
||||
/**
|
||||
* Scala ++ operator
|
||||
*/
|
||||
public Transformation $plus$plus(Transformation t) {
|
||||
return with(t);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ package codechicken.lib.vec;
|
||||
@SuppressWarnings("serial")
|
||||
public class IrreversibleTransformationException extends RuntimeException
|
||||
{
|
||||
public Transformation t;
|
||||
public ITransformation t;
|
||||
|
||||
public IrreversibleTransformationException(Transformation t)
|
||||
public IrreversibleTransformationException(ITransformation t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.DoubleBuffer;
|
||||
|
||||
import codechicken.lib.util.Copyable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class Matrix4 extends Transformation
|
||||
public class Matrix4 extends Transformation implements Copyable<Matrix4>
|
||||
{
|
||||
private static DoubleBuffer glBuf = ByteBuffer.allocateDirect(16*8).order(ByteOrder.nativeOrder()).asDoubleBuffer();
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.lib.util.Copyable;
|
||||
|
||||
public class Quat
|
||||
public class Quat implements Copyable<Quat>
|
||||
{
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public double s;
|
||||
public static final double SQRT2 = Math.sqrt(2D);
|
||||
|
||||
public Quat()
|
||||
{
|
||||
|
||||
@@ -139,7 +139,7 @@ public class Rotation extends Transformation
|
||||
{
|
||||
Vector3 axis = Rotation.axes[rotateSide(side^1, r)];
|
||||
double d = look.scalarProject(axis);
|
||||
if(max > d)//TODO wrong way round
|
||||
if(d > max)
|
||||
{
|
||||
max = d;
|
||||
maxr = r;
|
||||
|
||||
@@ -9,72 +9,62 @@ import org.lwjgl.opengl.GL11;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class Scale extends Transformation
|
||||
{
|
||||
private Vector3 factor;
|
||||
|
||||
public Scale(Vector3 factor)
|
||||
{
|
||||
public class Scale extends Transformation {
|
||||
public Vector3 factor;
|
||||
|
||||
public Scale(Vector3 factor) {
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
public Scale(double factor)
|
||||
{
|
||||
public Scale(double factor) {
|
||||
this(new Vector3(factor, factor, factor));
|
||||
}
|
||||
|
||||
public Scale(double x, double y, double z)
|
||||
{
|
||||
|
||||
public Scale(double x, double y, double z) {
|
||||
this(new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vector3 vec)
|
||||
{
|
||||
public void apply(Vector3 vec) {
|
||||
vec.multiply(factor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void applyN(Vector3 normal)
|
||||
{
|
||||
public void applyN(Vector3 normal) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply(Matrix4 mat)
|
||||
{
|
||||
public void apply(Matrix4 mat) {
|
||||
mat.scale(factor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void glApply()
|
||||
{
|
||||
public void glApply() {
|
||||
GL11.glScaled(factor.x, factor.y, factor.z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation inverse()
|
||||
{
|
||||
return new Scale(1/factor.x, 1/factor.y, 1/factor.z);
|
||||
public Transformation inverse() {
|
||||
return new Scale(1 / factor.x, 1 / factor.y, 1 / factor.z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation merge(Transformation next) {
|
||||
if(next instanceof Scale)
|
||||
if (next instanceof Scale)
|
||||
return new Scale(factor.copy().multiply(((Scale) next).factor));
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRedundant() {
|
||||
return factor.equalsT(Vector3.one);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
|
||||
return "Scale("+new BigDecimal(factor.x, cont)+", "+new BigDecimal(factor.y, cont)+", "+new BigDecimal(factor.z, cont)+")";
|
||||
return "Scale(" + new BigDecimal(factor.x, cont) + ", " + new BigDecimal(factor.y, cont) + ", " + new BigDecimal(factor.z, cont) + ")";
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,54 @@
|
||||
package codechicken.lib.vec;
|
||||
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Interface for any 3D vector transformation
|
||||
* Abstract supertype for any 3D vector transformation
|
||||
*/
|
||||
public abstract class Transformation
|
||||
{
|
||||
/**
|
||||
* Applies this transformation to a position vector
|
||||
* @param vec The vector to transform
|
||||
*/
|
||||
public abstract void apply(Vector3 vec);
|
||||
|
||||
public abstract class Transformation extends ITransformation<Vector3, Transformation> implements CCRenderState.IVertexOperation
|
||||
{
|
||||
public static final int operationIndex = CCRenderState.registerOperation();
|
||||
|
||||
/**
|
||||
* Applies this transformation to a normal (doesn't translate)
|
||||
* @param normal The normal to transform
|
||||
*/
|
||||
public abstract void applyN(Vector3 normal);
|
||||
|
||||
|
||||
/**
|
||||
* Applies this transformation to a matrix as a multiplication on the right hand side.
|
||||
* @param mat The matrix to combine this transformation with
|
||||
*/
|
||||
public abstract void apply(Matrix4 mat);
|
||||
|
||||
/**
|
||||
* @param point The point in OBJECT space to apply this transformation around
|
||||
* @return Wraps this transformation in a translation to point and then back from point
|
||||
*/
|
||||
public Transformation at(Vector3 point)
|
||||
{
|
||||
|
||||
public Transformation at(Vector3 point) {
|
||||
return new TransformationList(new Translation(-point.x, -point.y, -point.z), this, point.translation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transformation list composed of this transformation followed by t
|
||||
* If this is a TransformationList, the transformation will be appended and this returned
|
||||
*/
|
||||
public TransformationList with(Transformation t)
|
||||
{
|
||||
|
||||
public TransformationList with(Transformation t) {
|
||||
return new TransformationList(this, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simplified transformation that performs this, followed by next. If such a transformation does not exist, returns null
|
||||
*/
|
||||
public Transformation merge(Transformation next)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this transformation is redundant, eg. Scale(1, 1, 1), Translation(0, 0, 0) or Rotation(0, a, b, c)
|
||||
*/
|
||||
public boolean isRedundant()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void glApply();
|
||||
|
||||
public abstract Transformation inverse();
|
||||
|
||||
public TransformationList $plus$plus(Transformation t)
|
||||
{
|
||||
return with(t);
|
||||
@Override
|
||||
public boolean load() {
|
||||
CCRenderState.pipeline.addRequirement(CCRenderState.normalAttrib.operationID());
|
||||
return !isRedundant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operate() {
|
||||
apply(CCRenderState.vert.vec);
|
||||
if(CCRenderState.normalAttrib.active)
|
||||
applyN(CCRenderState.normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int operationID() {
|
||||
return operationIndex;
|
||||
}
|
||||
}
|
||||
@@ -9,73 +9,63 @@ import org.lwjgl.opengl.GL11;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class Translation extends Transformation
|
||||
{
|
||||
private Vector3 vec;
|
||||
|
||||
public Translation(Vector3 vec)
|
||||
{
|
||||
public class Translation extends Transformation {
|
||||
public Vector3 vec;
|
||||
|
||||
public Translation(Vector3 vec) {
|
||||
this.vec = vec;
|
||||
}
|
||||
|
||||
public Translation(double x, double y, double z)
|
||||
{
|
||||
public Translation(double x, double y, double z) {
|
||||
this(new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Vector3 vec)
|
||||
{
|
||||
public void apply(Vector3 vec) {
|
||||
vec.add(this.vec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyN(Vector3 normal)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Matrix4 mat)
|
||||
{
|
||||
public void applyN(Vector3 normal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Matrix4 mat) {
|
||||
mat.translate(vec);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation at(Vector3 point)
|
||||
{
|
||||
public Transformation at(Vector3 point) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void glApply()
|
||||
{
|
||||
public void glApply() {
|
||||
GL11.glTranslated(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation inverse()
|
||||
{
|
||||
public Transformation inverse() {
|
||||
return new Translation(-vec.x, -vec.y, -vec.z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation merge(Transformation next) {
|
||||
if(next instanceof Translation)
|
||||
if (next instanceof Translation)
|
||||
return new Translation(vec.copy().add(((Translation) next).vec));
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRedundant() {
|
||||
return vec.equalsT(Vector3.zero);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
|
||||
return "Translation("+new BigDecimal(vec.x, cont)+", "+new BigDecimal(vec.y, cont)+", "+new BigDecimal(vec.z, cont)+")";
|
||||
return "Translation(" + new BigDecimal(vec.x, cont) + ", " + new BigDecimal(vec.y, cont) + ", " + new BigDecimal(vec.z, cont) + ")";
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import codechicken.lib.util.Copyable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import org.lwjgl.util.vector.Vector4f;
|
||||
@@ -17,7 +18,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
public class Vector3
|
||||
public class Vector3 implements Copyable<Vector3>
|
||||
{
|
||||
public static Vector3 zero = new Vector3();
|
||||
public static Vector3 one = new Vector3(1, 1, 1);
|
||||
|
||||
Reference in new issue
Block a user