Translation Tipoff

Started by paulscode, March 14, 2008, 10:55:59 PM

Previous topic - Next topic

paulscode

Hey, I was wondering if there is a method in Object3D that gets called from a child object when it's parent gets translated.

I want to bind to an object to know when it gets moved.  The way I was thinking of doing this, is to create a class that extends Object3D and registering it as a child to the object in question.  Then, I would just need a way to be tipped of that a translation has taken place, and then figure out what that translation is ( I could use getTranslation() for the later, right? )

JavaMan

Maybe for your main object you could extend object3d. Then inside that class you would have a reference for the object you want to "tip off". That way you could override the translate method, and inside it call super.translate as well as call translate for the tip off object.

I think this is what you want, if I understand right.

EgonOlsen

If i understand you correctly, you ask if some method on a child gets called when the parent does a translation? If so, then no. There no such thing. In jPCT no parent object knows its childs, it's the other way round. I would also suggest to extend Object3D and make it child-aware. That's quite easy to do. That way, you can notify an object's childs in case of a translation of the parent. For whatever that may be useful... ;D

paulscode

#3
I see, well my goal is not to hear about parent translations from a child object, anyway, that was just a means to the goal.

My goal is simply to be tipped of when an object gets translated so I can check what that translation is.  From your response, extending Object3D and overriding the "translate" methods would not help me anyway, because if my object were to be a child of another object which gets translated, My object would not know about it.  (Besides, doing an extension of Object3D would not be practical for what I am doing, anyway - this is related to creating a method for binding a sound source to an Object3D.  It is for a library that will be used by multiple users and different applications ).

So to achieve my goal, I will have to approach this problem from a different angle.  I think I will create a method that gets called from the main game loop, which calls "getTransformedCenter()" on the object in question to determine if a translation has taken place and what that translation is.

Thanks for the advice!

EgonOlsen

I see...well, then polling the object seems to be the best solution.