Author Topic: Translation Tipoff  (Read 2188 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Translation Tipoff
« on: March 14, 2008, 10:55:59 pm »
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? )

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Translation Tipoff
« Reply #1 on: March 14, 2008, 11:20:54 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translation Tipoff
« Reply #2 on: March 14, 2008, 11:26:39 pm »
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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Translation Tipoff
« Reply #3 on: March 15, 2008, 12:33:15 am »
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!
« Last Edit: March 15, 2008, 01:08:26 am by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translation Tipoff
« Reply #4 on: March 15, 2008, 10:38:35 am »
I see...well, then polling the object seems to be the best solution.