Initial 1.7 commit

This commit is contained in:
Chicken-Bomes committed 2014-04-07 14:02:47 +10:00
1 parent 34154fc011
commit ca675b5f31
72 files changed
+2967 -3335

No files matched your search

@@ -0,0 +1,23 @@
package codechicken.lib.render.uv;
import codechicken.lib.vec.IrreversibleTransformationException;
import net.minecraft.util.IIcon;
public class IconTransformation extends UVTransformation {
public IIcon icon;
public IconTransformation(IIcon icon) {
this.icon = icon;
}
@Override
public void apply(UV uv) {
uv.u = icon.getInterpolatedU(uv.u * 16);
uv.v = icon.getInterpolatedV(uv.v * 16);
}
@Override
public UVTransformation inverse() {
throw new IrreversibleTransformationException(this);
}
}
@@ -0,0 +1,24 @@
package codechicken.lib.render.uv;
import codechicken.lib.vec.IrreversibleTransformationException;
import net.minecraft.util.IIcon;
public class MultiIconTransformation extends UVTransformation {
public IIcon[] icons;
public MultiIconTransformation(IIcon... icons) {
this.icons = icons;
}
@Override
public void apply(UV uv) {
IIcon icon = icons[uv.tex % icons.length];
uv.u = icon.getInterpolatedU(uv.u * 16);
uv.v = icon.getInterpolatedV(uv.v * 16);
}
@Override
public UVTransformation inverse() {
throw new IrreversibleTransformationException(this);
}
}
+79
View File
@@ -0,0 +1,79 @@
package codechicken.lib.render.uv;
import codechicken.lib.util.Copyable;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class UV implements Copyable<UV> {
public double u;
public double v;
public int tex;
public UV() {
}
public UV(double u, double v) {
this(u, v, 0);
}
public UV(double u, double v, int tex) {
this.u = u;
this.v = v;
this.tex = tex;
}
public UV(UV uv) {
this(uv.u, uv.v, uv.tex);
}
public UV set(double u, double v, int tex) {
this.u = u;
this.v = v;
this.tex = tex;
return this;
}
public UV set(double u, double v) {
return set(u, v, tex);
}
public UV set(UV uv) {
return set(uv.u, uv.v, uv.tex);
}
public UV copy() {
return new UV(this);
}
public UV add(UV uv) {
u += uv.u;
v += uv.v;
return this;
}
public UV multiply(double d) {
u *= d;
v *= d;
return this;
}
public String toString() {
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
return "UV(" + new BigDecimal(u, cont) + ", " + new BigDecimal(v, cont) + ")";
}
public UV apply(UVTransformation t) {
t.apply(this);
return this;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof UV))
return false;
UV uv = (UV) o;
return u == uv.u && v == uv.v;
}
}
+53
View File
@@ -0,0 +1,53 @@
package codechicken.lib.render.uv;
import codechicken.lib.math.MathHelper;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class UVRotation extends UVTransformation
{
public double angle;
/**
* @param angle The angle to rotate counterclockwise in radians
*/
public UVRotation(double angle) {
this.angle = angle;
}
@Override
public void apply(UV uv) {
double c = MathHelper.cos(angle);
double s = MathHelper.sin(angle);
double u2 = c*uv.u + s*uv.v;
uv.v = - s*uv.u + c*uv.v;
uv.u = u2;
}
@Override
public UVTransformation inverse() {
return new UVRotation(-angle);
}
@Override
public UVTransformation merge(UVTransformation next) {
if(next instanceof UVRotation)
return new UVRotation(angle+((UVRotation)next).angle);
return null;
}
@Override
public boolean isRedundant() {
return MathHelper.between(-1E-5, angle, 1E-5);
}
@Override
public String toString()
{
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
return "UVRotation(" + new BigDecimal(angle, cont) + ")";
}
}
+36
View File
@@ -0,0 +1,36 @@
package codechicken.lib.render.uv;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class UVScale extends UVTransformation {
double su;
double sv;
public UVScale(double scaleu, double scalev) {
su = scaleu;
sv = scalev;
}
public UVScale(double d) {
this(d, d);
}
@Override
public void apply(UV uv) {
uv.u *= su;
uv.v *= sv;
}
@Override
public UVTransformation inverse() {
return new UVScale(1 / su, 1 / sv);
}
@Override
public String toString() {
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
return "UVScale(" + new BigDecimal(su, cont) + ", " + new BigDecimal(sv, cont) + ")";
}
}
@@ -0,0 +1,37 @@
package codechicken.lib.render.uv;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.ITransformation;
/**
* Abstract supertype for any UV transformation
*/
public abstract class UVTransformation extends ITransformation<UV, UVTransformation> implements CCRenderState.IVertexOperation
{
public static final int operationIndex = CCRenderState.registerOperation();
public UVTransformation at(UV point) {
return new UVTransformationList(new UVTranslation(-point.u, -point.v), this, new UVTranslation(point.u, point.v));
}
public UVTransformationList with(UVTransformation t) {
return new UVTransformationList(this, t);
}
@Override
public boolean load() {
return !isRedundant();
}
@Override
public void operate() {
apply(CCRenderState.vert.uv);
}
@Override
public int operationID() {
return operationIndex;
}
}
@@ -0,0 +1,106 @@
package codechicken.lib.render.uv;
import java.util.ArrayList;
import java.util.Iterator;
public class UVTransformationList extends UVTransformation
{
private ArrayList<UVTransformation> transformations = new ArrayList<UVTransformation>();
public UVTransformationList(UVTransformation... transforms)
{
for(UVTransformation t : transforms)
if(t instanceof UVTransformationList)
transformations.addAll(((UVTransformationList)t).transformations);
else
transformations.add(t);
compact();
}
@Override
public void apply(UV uv)
{
for(int i = 0; i < transformations.size(); i++)
transformations.get(i).apply(uv);
}
@Override
public UVTransformationList with(UVTransformation t)
{
if(t.isRedundant())
return this;
if(t instanceof UVTransformationList)
transformations.addAll(((UVTransformationList)t).transformations);
else
transformations.add(t);
compact();
return this;
}
public UVTransformationList prepend(UVTransformation t)
{
if(t.isRedundant())
return this;
if(t instanceof UVTransformationList)
transformations.addAll(0, ((UVTransformationList)t).transformations);
else
transformations.add(0, t);
compact();
return this;
}
private void compact() {
ArrayList<UVTransformation> newList = new ArrayList<UVTransformation>(transformations.size());
Iterator<UVTransformation> iterator = transformations.iterator();
UVTransformation prev = null;
while(iterator.hasNext()) {
UVTransformation t = iterator.next();
if(t.isRedundant())
continue;
if(prev != null) {
UVTransformation m = prev.merge(t);
if(m == null)
newList.add(prev);
else if(m.isRedundant())
t = null;
else
t = m;
}
prev = t;
}
if(prev != null)
newList.add(prev);
if(newList.size() < transformations.size())
transformations = newList;
}
@Override
public boolean isRedundant() {
return transformations.size() == 0;
}
@Override
public UVTransformation inverse()
{
UVTransformationList rev = new UVTransformationList();
for(int i = transformations.size()-1; i >= 0; i--)
rev.with(transformations.get(i).inverse());
return rev;
}
@Override
public String toString()
{
String s = "";
for(UVTransformation t : transformations)
s+="\n"+t.toString();
return s.trim();
}
}
@@ -0,0 +1,54 @@
package codechicken.lib.render.uv;
import codechicken.lib.math.MathHelper;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class UVTranslation extends UVTransformation {
public double du;
public double dv;
public UVTranslation(double u, double v) {
du = u;
dv = v;
}
@Override
public void apply(UV uv) {
uv.u += du;
uv.v += dv;
}
@Override
public UVTransformation at(UV point) {
return this;
}
@Override
public UVTransformation inverse() {
return new UVTranslation(-du, -dv);
}
@Override
public UVTransformation merge(UVTransformation next) {
if (next instanceof UVTranslation) {
UVTranslation t = (UVTranslation)next;
return new UVTranslation(du+t.du, dv+t.dv);
}
return null;
}
@Override
public boolean isRedundant() {
return MathHelper.between(-1E-5, du, 1E-5) && MathHelper.between(-1E-5, dv, 1E-5);
}
@Override
public String toString() {
MathContext cont = new MathContext(4, RoundingMode.HALF_UP);
return "UVTranslation(" + new BigDecimal(du, cont) + ", " + new BigDecimal(dv, cont) + ")";
}
}