Improved transformation compacting.

This commit is contained in:
Chicken Bones committed 2013-09-05 17:41:31 +10:00
1 parent 5c5384f79c
commit ea515682c1
6 files changed
+56 -34

No files matched your search

@@ -35,6 +35,11 @@ public class RedundantTransformation extends Transformation
return next;
}
@Override
public boolean isRedundant() {
return true;
}
@Override
public String toString()
{
+9 -7
View File
@@ -232,18 +232,20 @@ public class Rotation extends Transformation
public Transformation merge(Transformation next) {
if(next instanceof Rotation) {
Rotation r = (Rotation)next;
if(r.axis.equalsT(axis)) {
double d = angle+r.angle;
if(d == 0)
return new RedundantTransformation();
return new Rotation(angle, axis);
}
if(r.axis.equalsT(axis))
return new Rotation(angle+r.angle, axis);
return new Rotation(toQuat().copy().multiply(r.toQuat()));
}
return null;
}
@Override
public boolean isRedundant() {
return MathHelper.between(-1E-5, angle, 1E-5);
}
@Override
public String toString()
{
+7 -7
View File
@@ -60,17 +60,17 @@ public class Scale extends Transformation
@Override
public Transformation merge(Transformation next) {
if(next instanceof Scale) {
Vector3 vec = factor.copy().multiply(((Scale) next).factor);
if(vec.equalsT(Vector3.one))
return new RedundantTransformation();
return new Scale(vec);
}
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()
{
+8
View File
@@ -52,6 +52,14 @@ public abstract class Transformation
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();
+20 -16
View File
@@ -74,7 +74,7 @@ public class TransformationList extends Transformation
@Override
public TransformationList with(Transformation t)
{
if(t instanceof RedundantTransformation)
if(t.isRedundant())
return this;
mat = null;//matrix invalid
@@ -89,7 +89,7 @@ public class TransformationList extends Transformation
public TransformationList prepend(Transformation t)
{
if(t instanceof RedundantTransformation)
if(t.isRedundant())
return this;
mat = null;//matrix invalid
@@ -103,25 +103,24 @@ public class TransformationList extends Transformation
}
private void compact() {
if(transformations.isEmpty())
return;
ArrayList<Transformation> newList = new ArrayList<Transformation>(transformations.size());
Iterator<Transformation> iterator = transformations.iterator();
Transformation prev = iterator.next();
Transformation prev = null;
while(iterator.hasNext()) {
Transformation t = iterator.next();
Transformation m = prev == null ? null : prev.merge(t);
if(m instanceof RedundantTransformation) {
prev = null;
}
else if(m != null) {
prev = m;
}
else {
newList.add(prev);
prev = t;
if(t.isRedundant())
continue;
if(prev != null) {
Transformation 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);
@@ -131,6 +130,11 @@ public class TransformationList extends Transformation
mat = null;
}
}
@Override
public boolean isRedundant() {
return transformations.size() == 0;
}
@Override
@SideOnly(Side.CLIENT)
+7 -4
View File
@@ -61,14 +61,17 @@ public class Translation extends Transformation
@Override
public Transformation merge(Transformation next) {
if(next instanceof Translation) {
Vector3 vec2 = vec.copy().add(((Translation) next).vec);
return vec2.isZero() ? new RedundantTransformation() : new Translation(vec2);
}
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()
{