mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-11 07:47:47 +00:00
Improved transformation compacting.
This commit is contained in:
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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user