Asymmetrical Scaling

Started by AGP, June 21, 2018, 06:24:00 AM

Previous topic - Next topic

AGP

I'm trying to create a flickering glow. To that end, I wrote the following thickening method in a vertex controller. The problem happens when the base object, from which the glow object is created, is rotated because the glow appears to be modified in worldspace as opposed to in objectspace. What should I do to calculate the x/z distortion in objectspace?


     public void thicken(final float deltaTime) {
SimpleVector[] vertices = this.getSourceMesh();
SimpleVector[] destination = this.getDestinationMesh();
for (int i = 0; i < vertices.length; i++) {
     SimpleVector v = vertices[i];
     v.x *= (1f+deltaTime);
     v.z *= (1f+deltaTime);
     destination[i] = v;
}
this.updateMesh();
     }

EgonOlsen

The vertex controller works in object space, not in world space. What exactly is the problem?

AGP

Obviously, that it's scaling in the wrong axis. But only in my real-world use. The test in which I didn't rotate the object worked fine.

EgonOlsen

Must be something else then. The controller works in object space. I don't see how this code snippet alone can cause wrong scaling unless the object is somehow rotated around Z and your Z-scaling should actually be Y.

AGP

#4
That's weird. I actually have two different, possibly related, problems. The second one is that the glow object, though both parallel and near the original object, is not in the exact same space as the original object. Yet I initialize it like so:


glow = new Object3D(obj, false);


Do you have to call build() on the glow object? Also, does getTransformedCenter() always consider the translations of all parents? Because I can't place the glow over the glower even with:


SimpleVector to = obj.getTransformedCenter();
SimpleVector o = glow.getTransformedCenter();
glow.translate(to.x-o.x, to.y-o.y, to.z-o.z);

EgonOlsen

Yes, you have to call build and yes, getTransformedCenter() should apply all parent transformations.

AGP

#6
Then why doesn't that snippet place the glow over the glower? Can you think of a possible solution?

Edit: I should mention that the original object was created with ExtendedPrimitives.createCylinder(...).

EgonOlsen

Maybe because the transformation as a whole is different (some additional rotation involved)? Try to offset the glow by a scaled version of the results from get?Axis() instead.

AGP

There's nothing. This is how glow is created. I even added the setRotationMatrix() call to see if that would help, but nothing changed.


if (deltaGrowth > 1.00f) {
     obj.removeChild(glow);
     theWorld.removeObject(glow);
     glow = new Object3D(obj, false);
     glow.setTexture("Glow");
     glow.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
     glow.build();
     glow.setRotationMatrix(obj.getRotationMatrix());
     moveTo(glow, obj.getTransformedCenter());
     glow.setTransparency(100);
     deltaGrowth = 0.00f;
     obj.addChild(glow);
     theWorld.addObject(glow);
     vController = new VertexController(glow);
}

EgonOlsen

Have you checked which vealue you are actually getting from getTransformedcenter() before and after doing the additional translation. Something has to be there.

AGP

This is what I get:

Quote
Glow before build(): (0.20492004,0.06320784,0.28592888)
Glow after build(): (0.20492004,0.06320784,0.28592888)
Glow after translation: (0.31077987,0.6419327,1.6769919) blade: (0.31077987,0.6419327,1.6769919)

EgonOlsen

Looking at your code snippet again, I noticed that you set the glow's rotation matrix to the one of the object. I'm not sure if that's a good idea, because it sets the exact some instance. I might be better to make one the child of the other or do a cloneMatrix() on that rotation matrix before setting it. Maybe that helps.

AGP

No, that was my failed attempt to solve the problem. It doesn't work with or without it.

EgonOlsen

Do you have a screen shot? Looking at the log output, it's pretty hard for me to imagine the actual problem.