Author Topic: translate child object on global axis  (Read 930 times)

Offline Dinin

  • byte
  • *
  • Posts: 28
    • View Profile
translate child object on global axis
« on: May 23, 2012, 07:45:20 am »
Hi !

I want to translate a childobject f.e. 50 units in global x axis.
How can i convert this to the translation of the child object, because translation of child object is done on parents coordinate system.

Thanks and greets
Dinin

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: translate child object on global axis
« Reply #1 on: May 23, 2012, 04:37:01 pm »
I don't get the question.... ???

Offline Dinin

  • byte
  • *
  • Posts: 28
    • View Profile
Re: translate child object on global axis
« Reply #2 on: May 23, 2012, 05:32:40 pm »
i have a childObject attached to a parentObject.
Now i do a:
Code: [Select]
parentObject.translate(10,0,0);
parentObject.rotateZ(Math.Pi/4);

Now i want to translate the childObject to the world position 60,0,0.
But when i do a:
Code: [Select]
childObject.translate(50,0,0);the childobject is moved depending on the rotation of the parentObject.
So i want to convert the
Code: [Select]
childObject.translate(50,0,0);so that the world position is at 60,0,0

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: translate child object on global axis
« Reply #3 on: May 23, 2012, 05:37:14 pm »
Maybe something like

Code: [Select]
Matrix m=parent.getRotationMatrix().invert3x3();
SimpleVector x=m.getXAxis();
x.scalarMul(50);
child.translate(x);

 ??? I'm not sure if this will work though...it's a just a brain fart of mine. It might as well be complete bogus.

Offline Dinin

  • byte
  • *
  • Posts: 28
    • View Profile
Re: translate child object on global axis
« Reply #4 on: May 23, 2012, 06:44:41 pm »
yes ... you're great. Exactly what i was looking for.
mthx.