When does getTransformedCenter() not work?

Started by AGP, February 11, 2014, 06:19:43 PM

Previous topic - Next topic

AGP

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.


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

AGP

I take it that the lack of response comes from the fact that you verified the problem. Am I right?

EgonOlsen

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:


// 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()


// To setup the particle
this.translate(initialPosition);

//...

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

AGP

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.


     public void resetOrigin() {
this.calcCenter();
initialPosition = this.getTransformedCenter();
     }

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

EgonOlsen

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....?

AGP

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.

EgonOlsen

QuoteI 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...

AGP

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.

EgonOlsen

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.