Author Topic: How to pick and move object on a plane?  (Read 1292 times)

Offline Gohome

  • byte
  • *
  • Posts: 5
    • View Profile
How to pick and move object on a plane?
« 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
« Last Edit: July 24, 2012, 12:11:33 pm by Gohome »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: How to rotate and translate object on a plane?
« Reply #1 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?

Offline Gohome

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to rotate and translate object on a plane?
« Reply #2 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: How to rotate and translate object on a plane?
« Reply #3 on: July 23, 2012, 04:17:47 pm »
Look at the source code of physics example. You can move with any object by long touch. Is it what you want?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: How to rotate and translate object on a plane?
« Reply #4 on: July 23, 2012, 04:22:08 pm »
Are you using enableLazyTransformations(). If so, then don't.

Offline Gohome

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to rotate and translate object on a plane?
« Reply #5 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: How to rotate and translate object on a plane?
« Reply #6 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).