Author Topic: Asymmetrical Scaling  (Read 84 times)

Offline AGP

  • quad
  • ******
  • Posts: 1591
    • View Profile
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();
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11865
    • View Profile
    • http://www.jpct.net
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?

Offline AGP

  • quad
  • ******
  • Posts: 1591
    • View Profile
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11865
    • View Profile
    • http://www.jpct.net
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.

Offline AGP

  • quad
  • ******
  • Posts: 1591
    • View Profile
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 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11865
    • View Profile
    • http://www.jpct.net
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.

Offline AGP

  • quad
  • ******
  • Posts: 1591
    • View Profile
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 »