Applying an interpolation between 2 Transforms. [FIXED x2]

I’m in a bit of a bind.



I’ve got this quad I’m using that will eventually display part of a planet’s map so players can harvest resources. What I want is to animate it from a tiny rectangle to the full-scale quad. Thing is, it’s not really animating. When I click “Show map” a tiny rectangle is displayed (expected), but it’s not grown to the wanted size. The same happens if you click to shrink it down.



There’s probably something I’m doing that is wrong. I can’t seem to find what exactly.



Halp!



Here’s the anonymous class that does the grow() and shrink().



[java]

private class MapQuad {



private final static float MAX_WIDTH_SIZE = 1200.0f;

private final static float MAX_HEIGHT_SIZE = 675.0f;

private final static int ZOOM_TIME = 250;

private final static float RATIO = 1f / ZOOM_TIME;

private final Geometry map;

private final Quad quad = new Quad(MAX_WIDTH_SIZE, MAX_HEIGHT_SIZE);

private final Node mapNode = new Node("MapNode");

private Transform startTransform;

private Transform endTransform;

private int step = 1;

private boolean opened;



private MapQuad(int width, int height) {

Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

mat.setTexture("ColorMap", app.getAssetManager().loadTexture("Textures/GUI/allInfoPopup.png"));

map = new Geometry("Planet Map Geometry", quad);

map.setMesh(quad);

map.setLocalTranslation(width / 2.0f, height / 2.0f, 0);

map.setMaterial(mat);

map.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

mapNode.setQueueBucket(Bucket.Gui);

startTransform = new Transform(new Vector3f(width / 2 - (1.77778f / 2f), height / 2 - (1f / 2f), 0),

Quaternion.ZERO,

new Vector3f(RATIO, RATIO, 0));



endTransform = new Transform(new Vector3f(width / 2 - (MAX_WIDTH_SIZE / 2f), height / 2 - (MAX_HEIGHT_SIZE / 2f), 0),

Quaternion.ZERO,

new Vector3f(1f, 1f, 0));



map.getLocalTransform().interpolateTransforms(startTransform, endTransform, RATIO * step);

mapNode.attachChild(map);

}



private void grow() {

if (step == ZOOM_TIME) {

animating = false;

opened = true;

System.out.println("Growing Quad Done " + step + " size ratio " + RATIO * step);

} else {

System.out.println("Growing Quad " + step + " size ratio " + RATIO * step);

step++;

map.getLocalTransform().interpolateTransforms(startTransform, endTransform, RATIO * step);

}

}



private void shrink() {

if (step == 1) {

animating = false;

opened = false;

System.out.println("Shrinking Quad Done " + step + " size ratio " + RATIO * step);

} else {

System.out.println("Shrinking Quad " + step + " size ratio " + RATIO * step);

step–;

map.getLocalTransform().interpolateTransforms(endTransform, startTransform, RATIO * step);

}

}

}

[/java]



The output is fine. I get things like that:


...
Growing Quad 244 size ratio 0.9760001
Growing Quad 245 size ratio 0.98
Growing Quad 246 size ratio 0.984
Growing Quad 247 size ratio 0.98800004
Growing Quad 248 size ratio 0.99200004
Growing Quad 249 size ratio 0.99600005
Growing Quad Done 250 size ratio 1.0

But when "growing", only the first "frame" is put, it's not scaled as it's expanded. When shrinking the only thing I see is when it's done shrinking and it removes everything; but the output is fine.

So, I'm wondering if the scaling isn't applied somehow. Like using "updateGeometricState()" but for transforms? I noticed the "setTransformRefresh()" but it's protected and from what I've seen I don't think I need to call this, but then again, I might...

I think map.getLocalTransform().interpolateTransforms() does not set the refresh flags on the quad.

as a rule of thumb you shouldn’t do get().set() on transformations.

Try with a temp Transform variable and then go

map.setLocaTransform(tempTransform);



This should be a control on the map Spatial btw.

1 Like
@nehon said:
I think map.getLocalTransform().interpolateTransforms() does not set the refresh flags on the quad.


Indeed it doesn't.


as a rule of thumb you shouldn't do get().set() on transformations.


I always try not to do that, but seeing that I could get the transform and apply an interpolation to it, I was sure it would trigger the refresh.


Try with a temp Transform variable and then go
map.setLocaTransform(tempTransform);

That's what I did. It now works perfectly.

Thanks.

Got some more problem with that.



It seems I can’t do the animation I wanted with procedural textures. :confused:



When I try to do this, growing and shrinking after a click on a button, the procedural texture is ALWAYS at the viewport’s origin and not at the geometry’s. It’s also always full size. Meaning it doesn’t take the transform interpolation into consideration. :?



So what I do is, at each frame I “reset” the geometry (with a new one) with the proper size. That works, but the main problem remains, the proc texture is at the viewport’s origin.



Help appreciated here.



Here’s the class.

[java]

class MapSurface {



private Geometry realMap;

private Quad mapSurface;

private Transform endTransform;

private Transform startTransform;

private AssetManager am;

private int width;

private int height;

private Planet body;



MapSurface(AssetManager am, int width, int height, final float ratio, Planet body) {

this.am = am;

this.width = 1200;

this.height = 543;

this.body = body;



startTransform = new Transform(new Vector3f(width / 2 - (1.77778f / 2f), height / 2 - (1f / 2f), 0.6f),

Quaternion.ZERO,

new Vector3f(ratio, ratio, 0));



endTransform = new Transform(new Vector3f(width / 2 - (1200 / 2f), height / 2 - (543 / 2f - 65), 0.6f),

Quaternion.ZERO,

new Vector3f(1f, 1f, 0));

Mesh fake = new Mesh();

realMap = new Geometry(“Fake”, fake);

Material fakeMat = new Material(am, “Common/MatDefs/Misc/Unshaded.j3md”);

realMap.setMaterial(fakeMat);

}



void grow(float stepping) {

Transform stepTransform = new Transform();

stepTransform.interpolateTransforms(startTransform, endTransform, stepping);

remakeGeometry(stepTransform);

}



void shrink(float stepping) {

Transform stepTransform = new Transform();

stepTransform.interpolateTransforms(startTransform, endTransform, stepping);

remakeGeometry(stepTransform);

}



private void remakeGeometry(Transform transform) {

Vector3f scale = transform.getScale();



mapSurface = new Quad(width * scale.x, height * scale.y);

realMap = new Geometry(“Surface”, mapSurface);

realMap.setLocalTranslation(transform.getTranslation());

// Material mapMat = new Material(am, “Common/MatDefs/Misc/Unshaded.j3md”);

// mapMat.setTexture(“ColorMap”, am.loadTexture(“Textures/GUI/Grid2.png”));

// mapMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

Material mapMat = new Material(am, “Materials/Planets/2DPlanetMap.j3md”);

mapMat.setColor(“Color”, body.getColor());

mapMat.setFloat(“Radius”, body.getRadius());

mapMat.setFloat(“Seed”, body.getSeed());

Texture tex = null;

switch (body.getType()) {

case Gas:

tex = am.loadTexture(“Textures/Planets/GasGiants/” + body.getLut() + “gasgiant_lut.png”);

break;

case Rocky:

tex = am.loadTexture(“Textures/Planets/Rocky/rocky_gz_lut.png”);

break;

case RockyHot:

tex = am.loadTexture(“Textures/Planets/Rocky/” + body.getLut() + “rocky_hot_lut.png”);

break;

case RockyCold:

tex = am.loadTexture(“Textures/Planets/Rocky/” + body.getLut() + “rocky_cold_lut.png”);

break;

case Ice:

tex = am.loadTexture(“Textures/Planets/IceGiants/” + body.getLut() + “icegiant_lut.png”);

break;

default:

}

mapMat.setTexture(“LUT”, tex);

realMap.setMaterial(mapMat);

}



Geometry getGeometry() {

return realMap;

}

}

[/java]



If I comment the proc texturing part and uncomment those lines:

[java]

// Material mapMat = new Material(am, “Common/MatDefs/Misc/Unshaded.j3md”);

// mapMat.setTexture(“ColorMap”, am.loadTexture(“Textures/GUI/Grid2.png”));

// mapMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

[/java]



The above puts the “Grid2.png” where it goes on the screen.



If needed I can put a video up to show the weirdness happening.



Thanks a bunch.

Oh gawd.



Had an epiphany right after posting this.



It’s the shader’s projection matrix… DUH.



Solved.



Thank you for your time. Now be on your way.



Thanks. :wink:

1 Like

Mark the topic as [fixed] then :stuck_out_tongue:

@zarch said:
Mark the topic as [fixed] then :p


And yet, after two fixes I failed to do that. I feel some other dumb thing is waiting for me. *hurries to put [FIXED] before those dumb things really happen*
1 Like