Author Topic: Child Object go on wrong direction when rotate Parent.  (Read 166 times)

Offline tinhtinhcd

  • byte
  • *
  • Posts: 16
    • View Profile
Child Object go on wrong direction when rotate Parent.
« on: May 17, 2017, 01:43:48 pm »
Hi, my app have 2 object.
The object2 is a child of object1.

At the first time run app. I click on child and call translate, it go on the correct direction that i that my finger move.
After I rotate the parent, it go on the opposite way with my finger.

I only want the child move along with it out Axis, not in work Axis.
 
in pic1 it correct, in pic2 it wrong direction.

here is my code:

Code: [Select]
public void onDrawFrame(GL10 gl) {
SimpleVector dir = Interact2D.reproject2D3DWS(cam, fragment3D.fb, (int) fragment3D.xPos, (int)fragment3D.yPos).normalize();
world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), dir, 10000F);

if (this.hasToCreateBuffer) {
hasToCreateBuffer = false;
fb = new FrameBuffer(w, h);
}
if (object2.wasTargetOfLastCollision()){
SimpleVector direction = new SimpleVector(dis*scale,0,0);
object1.translate(direction);
}else{
if (touchTurn != 0) {
object1.rotateY(touchTurn);
touchTurn = 0;
}
if (touchTurnUp != 0) {
object1.rotateX(touchTurnUp);
touchTurnUp = 0;
}
}
updateFrame();
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net

Offline tinhtinhcd

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Child Object go on wrong direction when rotate Parent.
« Reply #2 on: May 18, 2017, 10:34:18 am »
Hi, it have some common with my issue.
But the answer not work for my case.
Code: [Select]
SimpleVector trsl=new SimpleVector(1,2,0);
trsl.matMul(p1.getWorldTransformation());
p2.translate(trsl);
or
Code: [Select]
p2.translate(p1.getXAxis());
that code make my child moving on the world space, i don't want it happen, my child should move on it's parent space.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Child Object go on wrong direction when rotate Parent.
« Reply #3 on: May 18, 2017, 08:37:47 pm »
I'm not entirely sure what you mean then? Can you draw some picture or something? The attached screen shots don't really help me to understand what exactly you want to do!?

Offline tinhtinhcd

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Child Object go on wrong direction when rotate Parent.
« Reply #4 on: May 19, 2017, 08:46:50 am »
Hi EgonOlsen,

i finally find a work around for my application.

^^ thanks for your help .