I got an error posting. I don’t know if it was posted or not. I’ll try it again and try to delete it if its a duplicate.
I’m trying to make a ball squish over time. If I put getLocalScale in a Vector3f, my results wander (too many decimal places) and my squishing doesn’t look right. If I hard code the scale, I get clean results, but I want it to work at any scale.
Sorry for all the redundant casting. I was trying to see if it would help. The if (true) changes the input/output. How can I get clean results with Vector3f?
good results
Ant.antSquash()-localScale=(100.0, 100.0, 100.0)
Ant.antSquish(float)-scale = 0.1
Ant.antSquash()-tx=110.0, ty=90.0, tz=110.0
Ant.antSquash()-localScale=(110.0, 90.0, 110.0)
Ant.antSquish(float)-scale = 0.2
Ant.antSquash()-tx=120.00001, ty=80.0, tz=120.00001
Ant.antSquash()-localScale=(120.00001, 80.0, 120.00001)
Ant.antSquish(float)-scale = 0.3
Ant.antSquash()-tx=130.0, ty=70.0, tz=130.0
Ant.antSquash()-localScale=(130.0, 70.0, 130.0)
Ant.antSquish(float)-scale = 0.4
Ant.antSquash()-tx=140.0, ty=60.000004, tz=140.0
Ant.antSquash()-localScale=(140.0, 60.000004, 140.0)
Ant.antSquish(float)-scale = 0.5
Ant.antSquash()-tx=150.0, ty=50.0, tz=150.0
Ant.antSquash()-localScale=(150.0, 50.0, 150.0)
bad results
Ant.antSquash()-localScale=(100.0, 100.0, 100.0)
Ant.antSquish(float)-scale = 0.1
Ant.antSquash()-scale is +(110.0, 90.0, 110.0)
Ant.antSquash()-localScale=(110.0, 90.0, 110.0)
Ant.antSquish(float)-scale = 0.2
Ant.antSquash()-scale is +(132.0, 72.0, 132.0)
Ant.antSquash()-localScale=(132.0, 72.0, 132.0)
Ant.antSquish(float)-scale = 0.3
Ant.antSquash()-scale is +(171.59999, 50.399998, 171.59999)
Ant.antSquash()-localScale=(171.59999, 50.399998, 171.59999)
Ant.antSquish(float)-scale = 0.4
Ant.antSquash()-scale is +(240.23999, 30.24, 240.23999)
Ant.antSquash()-localScale=(240.23999, 30.24, 240.23999)
Ant.antSquish(float)-scale = 0.5
Ant.antSquash()-scale is +(360.36, 15.12, 360.36)
Ant.antSquash()-localScale=(360.36, 15.12, 360.36)
int step = 0;
float scaleFactor = 0f;
Vector3f antScale = new Vector3f();
//this should squisn anything at any scale
public boolean antSquash(float tpf){
Quaternion Q = new Quaternion();
if (step == 0){
setLocalRotation(Q.fromAngleAxis(0f, new Vector3f())) ;
antScale = getLocalScale();
System.out.println("Ant.antSquash()-localScale=" + getLocalScale());
scaleFactor = 0f;
step++;
return(false);
}
float tx, ty, tz;
switch (step){
case 1:
scaleFactor = scaleFactor + (0.1f);
System.out.println("Ant.antSquish(float)-scale = " + scaleFactor);
if (true){//bad output
antScale.x = antScale.x * (1f + scaleFactor);
antScale.y = antScale.y * (1f - scaleFactor);
antScale.z = antScale.z * (1f + scaleFactor);
System.out.println("Ant.antSquash()-scale is +" + antScale);
setLocalScale(antScale);
}
else{//good output - not flexable (for any scale)
tx = (float)100f * (1f + scaleFactor);
ty = (float)100f * (1f - scaleFactor);
tz = (float)100f * (1f + scaleFactor);
System.out.println("Ant.antSquash()-tx=" + tx + ", ty=" + ty + ", tz=" + tz);
setLocalScale(tx, ty, tz);
}
System.out.println("Ant.antSquash()-localScale=" + getLocalScale());
if (scaleFactor >= 0.5){
step++;
return(true);//end here - data makes no sense
}
break;
//end here - data makes no sense
case 2:
setLocalScale(antScale.x * (1 + scaleFactor), antScale.y * (1 - scaleFactor), antScale.z * (1 + scaleFactor));
scaleFactor += (0.5 * tpf);
if (scaleFactor >= 1){
step++;
//return(false);
}
break;
case 3:
System.out.println("Ant.antSquish(float)-done");
setLocalScale(antScale.x, antScale.y, antScale.z);
scaleFactor = 0;
step = 0;
return(true);
}
return(false);
}
public boolean antStretch(float tpf){
if (step == 0){
System.out.println("Ant.antStretch(float)");
step = 1;
return(false);
}