### Author Topic: Asymmetrical Scaling  (Read 3517 times)

#### AGP

• Posts: 1639
##### Asymmetrical Scaling
« on: June 21, 2018, 06:24:00 am »
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?

Code: [Select]
`     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

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #1 on: June 21, 2018, 09:07:26 am »
The vertex controller works in object space, not in world space. What exactly is the problem?

#### AGP

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #2 on: June 21, 2018, 06:04:45 pm »
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

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #3 on: June 21, 2018, 10:04:01 pm »
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

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #4 on: June 21, 2018, 10:06:48 pm »
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:

Code: [Select]
`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:

Code: [Select]
`SimpleVector to = obj.getTransformedCenter();SimpleVector o = glow.getTransformedCenter();glow.translate(to.x-o.x, to.y-o.y, to.z-o.z);`
« Last Edit: June 22, 2018, 06:38:11 am by AGP »

#### EgonOlsen

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #5 on: June 22, 2018, 08:27:26 am »
Yes, you have to call build and yes, getTransformedCenter() should apply all parent transformations.

#### AGP

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #6 on: June 22, 2018, 10:11:29 am »
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(...).
« Last Edit: June 23, 2018, 04:51:13 am by AGP »

#### EgonOlsen

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #7 on: June 24, 2018, 04:52:18 pm »
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

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #8 on: June 24, 2018, 09:27:10 pm »
There's nothing. This is how glow is created. I even added the setRotationMatrix() call to see if that would help, but nothing changed.

Code: [Select]
` 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

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #9 on: June 25, 2018, 08:38:12 am »
Have you checked which vealue you are actually getting from getTransformedcenter() before and after doing the additional translation. Something has to be there.

#### AGP

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #10 on: June 25, 2018, 08:32:46 pm »
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

• Posts: 12027
##### Re: Asymmetrical Scaling
« Reply #11 on: June 26, 2018, 09:04:23 am »
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

• Posts: 1639
##### Re: Asymmetrical Scaling
« Reply #12 on: June 26, 2018, 09:21:29 am »
No, that was my failed attempt to solve the problem. It doesn't work with or without it.