Child Object go on wrong direction when rotate Parent.

Started by tinhtinhcd, May 17, 2017, 01:43:48 PM

Previous topic - Next topic

tinhtinhcd

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:


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();
}


tinhtinhcd

Hi, it have some common with my issue.
But the answer not work for my case.

SimpleVector trsl=new SimpleVector(1,2,0);
trsl.matMul(p1.getWorldTransformation());
p2.translate(trsl);

or

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.


EgonOlsen

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

tinhtinhcd

Hi EgonOlsen,

i finally find a work around for my application.

^^ thanks for your help .