www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Gohome on July 23, 2012, 02:48:48 pm

Title: How to pick and move object on a plane?
Post by: Gohome on July 23, 2012, 02:48:48 pm
I create a fixed plane and a fixed camera. And I put objects on the plane. With these codes, I can pick a specific object and remove it correctly. But, if I replace the codes doing remove with rotate or translate. Then it doesn't work.

Remove
Code: [Select]
public void pickChess() {
SimpleVector dir = Interact2D.reproject2D3DWS(cam, fb, (int)firstX, (int)firstY).normalize();
Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000 /*or whatever*/);

if (res[1] != null) {
    Object3D pickedObj = (Object3D)res[1];

    RigidBody box = (RigidBody)pickedObj.getUserObject();
    bodyList.remove(pickedObj.getUserObject());
    dynamicWorld.removeRigidBody(box);
    world.removeObject(pickedObj);
}
}


Rotate
Code: [Select]
public void pickChess() {
SimpleVector dir = Interact2D.reproject2D3DWS(cam, fb, (int)firstX, (int)firstY).normalize();
Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000 /*or whatever*/);

if (res[1] != null) {
    Object3D pickedObj = (Object3D)res[1];

    pickedObj.rotateX(50);
}
}]

 What happened? Thanks.

Gohome
Title: Re: How to rotate and translate object on a plane?
Post by: EgonOlsen on July 23, 2012, 02:57:23 pm
"Doesn't work" is a buit vague. What do you expect it to do and what does it do instead?
Title: Re: How to rotate and translate object on a plane?
Post by: Gohome on July 23, 2012, 03:03:22 pm
I want to drag or upside down the picked object. But now if I touch the object, nothing was happened.
Title: Re: How to rotate and translate object on a plane?
Post by: Thomas. on July 23, 2012, 04:17:47 pm
Look at  the source code of physics example (http://www.jpct.net/forum2/index.php/topic,2622.0.html). You can move with any object by long touch. Is it what you want?
Title: Re: How to rotate and translate object on a plane?
Post by: EgonOlsen on July 23, 2012, 04:22:08 pm
Are you using enableLazyTransformations(). If so, then don't.
Title: Re: How to rotate and translate object on a plane?
Post by: Gohome on July 24, 2012, 10:40:30 am
To Thomas.
I'll try it. Thank you. :)

To EgonOlsen
No, I didn't use the function.
Title: Re: How to rotate and translate object on a plane?
Post by: EgonOlsen on July 24, 2012, 11:27:53 am
Then it should work and you might be doing something wrong, but judging from the code snippets that you've posted, this is impossible to say (maybe apart from the fact that 50 isn't a very reasonable rotation value, because the value has to be given in radians, not degrees).