www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: tinhtinhcd on May 17, 2017, 01:43:48 pm

Title: Child Object go on wrong direction when rotate Parent.
Post by: tinhtinhcd 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();
}
Title: Re: Child Object go on wrong direction when rotate Parent.
Post by: EgonOlsen on May 18, 2017, 08:52:46 am
That's that, or isn't it: http://www.jpct.net/forum2/index.php/topic,608.msg33437.html#msg33437 (http://www.jpct.net/forum2/index.php/topic,608.msg33437.html#msg33437)?
Title: Re: Child Object go on wrong direction when rotate Parent.
Post by: tinhtinhcd 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.

Title: Re: Child Object go on wrong direction when rotate Parent.
Post by: EgonOlsen 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!?
Title: Re: Child Object go on wrong direction when rotate Parent.
Post by: tinhtinhcd on May 19, 2017, 08:46:50 am
Hi EgonOlsen,

i finally find a work around for my application.

^^ thanks for your help .