How to pick and move object on a plane?

Started by Gohome, July 23, 2012, 02:48:48 PM

Previous topic - Next topic

Gohome

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

EgonOlsen

"Doesn't work" is a buit vague. What do you expect it to do and what does it do instead?

Gohome

I want to drag or upside down the picked object. But now if I touch the object, nothing was happened.

Thomas.

Look at the source code of physics example. You can move with any object by long touch. Is it what you want?

EgonOlsen

Are you using enableLazyTransformations(). If so, then don't.

Gohome

To Thomas.
I'll try it. Thank you. :)

To EgonOlsen
No, I didn't use the function.

EgonOlsen

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).