Asymmetrical Scaling

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

Previous topic - Next topic

AGP

Have a look at this. The further ahead I move Luke, the further up the glow goes. I've tried, unsuccessfully, rotating getTransformedCenter() of the blade, but it's still wrong.

https://www.dropbox.com/s/ouy2edwxaaxuyfr/TheFurtherAheadTheFurtherUp.webm?dl=0

EgonOlsen

Maybe the location of the glow in object space is off? What are the bouding box values for the glow and the blade?

AGP

It would've been crazy if they weren't in the same place.

Quote
******Blade Bounds:
0.18368883, 0.22368883
-1.0867921, -0.08679211
0.9159291, 0.95592904
******

******Glow Bounds:
0.18368883, 0.22368883
-1.0867921, -0.08679211
0.9159291, 0.95592904
******

EgonOlsen

Soo...the bounding boxes are in the same location, the transformed center is...yet the visual outcome doesn't match!? I'm not sure what's wrong here. Have you tried to replace these objects by some primitives just to see if it's really not something with the objects themselves?

AGP

The original object, blade (obj in the Glow class) is an ExtendedPrimitive. Glow itself is a copy of blade (new Object3D(obj, false)).

EgonOlsen

I really don't know then. In this screen shot, which object is the child of which?

AGP

The glow object is the child of blade (obj in Glow class).

EgonOlsen

What happens if you call clearRotation() and clearTranslation() on the glow object?

AGP

ClearRotation() doesn't do anything (and it shouldn't, since I interpolate the matrices of the lightsaber and the skeletal structure's hand in the loop). ClearTranslation fixed its initial position, thanks very much.

Now, I'm having a hard time keeping glow in the same place. I've tried every permutation of the following method of which I could think:


     public void thicken(final float deltaTime) {
SimpleVector[] vertices = this.getSourceMesh();
SimpleVector[] destination = this.getDestinationMesh();
final SimpleVector c = new SimpleVector(obj.getTransformedCenter());
float minX = Float.MAX_VALUE, minZ = Float.MAX_VALUE, maxX = Float.MIN_VALUE, maxZ = Float.MIN_VALUE;
for (int i = 0; i < vertices.length; i++) {
     SimpleVector v = new SimpleVector(vertices[i]);
     v.x *= (1f+deltaTime);
//      v.x -= deltaTime*.5f;
     v.z *= (1f+deltaTime);
//      v.z -= deltaTime*.5f;
     destination[i] = v;
     if (minX > v.x)
minX = v.x;
     if (maxX < v.x)
maxX = v.x;
     if (minZ > v.z)
minZ = v.z;
     if (maxZ < v.z)
maxZ = v.z;
}
this.updateMesh();
SimpleVector d = new SimpleVector((minX-maxX), 0f, (minZ-maxZ));
obj.translate(d);
// obj.clearTranslation();
// obj.calcCenter();
// Glow.moveTo(obj, c);
// Glow.moveTo(obj, d.calcSub(c));
     }

EgonOlsen

I'm not sure, if I understand...if the glow is a child of the saber...then why doesn't it follow it properly?

AGP

Because I'm altering its vertices with the VertexController.

EgonOlsen

Ok...so it works without that vertex manipulation but with it (to make the glower larger), it doesn't in some way. Is that the problem? I somehow lost track here...

AGP

It works both ways, but it's getting displaced as it gets wider. Read that last version of thicken() and you'll see my many attempts to keep the center in the same place.

EgonOlsen

Maybe because your calculations assume that the center is at the origin? I would try this: Take the vertex, translate it by the negated center, scale it and translate it back by the center.

AGP

#29
This still displaces it, but in a different direction:


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