Author Topic: When does getTransformedCenter() not work?  (Read 865 times)

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
When does getTransformedCenter() not work?
« on: February 11, 2014, 06:19:43 pm »
In that same town whose parts are its children, which gets rotated and translated into place, so are the waterfall particles its children. At the end of the waterfall loop, I try to reposition each particle at their origin. But with each new spin of the loop they get farther and farther away from each other. The following is the simple method that should put each individual particle in its origin, but doesn't.

Code: [Select]
     public void returnToOrigin() {
this.calcCenter();
SimpleVector position = this.getTransformedCenter();
this.translate(initialPosition.x-position.x, initialPosition.y-position.y, initialPosition.z-position.z);
     }

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: When does getTransformedCenter() not work?
« Reply #1 on: February 11, 2014, 08:08:52 pm »
I take it that the lack of response comes from the fact that you verified the problem. Am I right?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: When does getTransformedCenter() not work?
« Reply #2 on: February 11, 2014, 08:27:48 pm »
No, the lack of response comes from the fact that i have a day job...

Anyway, there is no problem with getTransformedCenter(). It gives you the transformed center. You logic implies that there are no rotations applied and that the object's center is exactly at (0,0,0). In any other case, this won't work. However, it doesn't have to, because this solution is more complicated than it has to be. If initialPosition is the particle's starting position, there a two better solutions for this:

Code: [Select]
// To setup the particle
this.setOrigin(initialPosition); //...no further translation needed

//...

public void returnToOrigin() {
     this.clearTranslation();
}

or, if you don't want to use setOrigin()

Code: [Select]
// To setup the particle
this.translate(initialPosition);

//...

public void returnToOrigin() {
     this.clearTranslation();
     this.translate(initialPosition);
}

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: When does getTransformedCenter() not work?
« Reply #3 on: February 11, 2014, 08:54:01 pm »
After I have rotated the town, I call resetOrigin(). At the end of the loop, as per your suggestion, the new returnToOrigin(). I no longer see any particles. I don't think that the value for initialPosition is correct.

Code: [Select]
     public void resetOrigin() {
this.calcCenter();
initialPosition = this.getTransformedCenter();
     }

     public void returnToOrigin() {
this.clearTranslation();
this.translate(initialPosition);
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: When does getTransformedCenter() not work?
« Reply #4 on: February 11, 2014, 09:26:09 pm »
I'm not sure what you want with this.getTransformedCenter() here!? Isn't initialPosition somehow set by yourself? Who else knows where a particle should start? I don't see any need to fiddle around with getTransformedCenter() here at all. It's there to get the current position of the center in world space. I don't see why you want that here....?

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: When does getTransformedCenter() not work?
« Reply #5 on: February 11, 2014, 09:27:52 pm »
Initial position is NOT set by me. The particles are exported into place as OBJs, then rotated and translated as children of the town. I need getTransformedCenter() to store their initial position.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: When does getTransformedCenter() not work?
« Reply #6 on: February 11, 2014, 09:39:06 pm »
Quote
I need getTransformedCenter() to store their initial position.
I don't think so. If they are part of an OBJ file, they have no translation at the beginning, just different "centers" in object space. getTransformedCenter() would give you that center transformed (i.e. all transformations of the object and its parents applied to it)...that's not what you want. I would say that in this case, it all comes down to one single line of code to reset them:

Quote
this.clearTranslation();


Then there would be no need to store their initial position, because the (0,0,0)-translation IS their initial position. If that doesn't work, i still haven't understood it...

Offline AGP

  • quad
  • ******
  • Posts: 1515
    • View Profile
Re: When does getTransformedCenter() not work?
« Reply #7 on: February 12, 2014, 04:16:28 pm »
That did it, thank you. I understand your point, but it is counter-intuitive that I can't store the non-origin initial position then move it back to it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: When does getTransformedCenter() not work?
« Reply #8 on: February 12, 2014, 04:33:11 pm »
You can...but it's (0,0,0) in your case. You are mixing translations and transformations. Storing the actual transformation and applying it as a translation is just wrong in almost any case.