Author Topic: Problem with Object picking  (Read 2475 times)

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Problem with Object picking
« on: November 18, 2011, 09:19:25 am »
Hi trying to do some object picking, like i readed about on the wiki.
Now it seems to work, until I move the Camera around, then it does not work anymore. It's like when the camera moved then, the positions are not valid anymore. it still uses old positions ? any Ideas ??


Code: [Select]
    //my Call
     pickingObject(mouseMapper.getMouseX(), mouseMapper.getMouseY());
    // My method
    private Object3D pickingObject(int mouseX, int mouseY) {
        SimpleVector direction = Interact2D.reproject2D3D(world.getCamera(), buffer, mouseX, mouseY).normalize();
        float distance = world.calcMinDistance(world.getCamera().getPosition(), direction, 10000);
        int[] res = Interact2D.pickPolygon(world.getVisibilityList(), direction);

        if (res != null) {
            System.out.println("YAHOO!"); // never happends since I compile the objects
            Object3D picked = world.getObject(res[1]);
            return picked;
        }
        if (distance != Object3D.COLLISION_NONE) { // works sometime
            Object[] objects = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), direction, 20000);
            Object3D object3D = (Object3D) objects[1];
            return (Object3D) objects[1];
        }
        return null;
    }
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with Object picking
« Reply #1 on: November 18, 2011, 09:40:07 am »
You are mixing both approaches here. For the latter (which is the only one that works on compiled objects, so you can remove the first one), you have to use

Code: [Select]
Interact2D.reproject2D3DWS(...)
instead of

Code: [Select]
Interact2D.reproject2D3D(...)
..or otherwise, it won't work when the camera starts moving (i.e. if world and camera space start to differ).

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Problem with Object picking
« Reply #2 on: November 18, 2011, 10:18:03 am »
Thank you Egon.
Using Interact2D.reproject2D3DWS(...) made it work MUCH better, I should have noticed that.
I think its so great you take out the time, to support and help even idiots like me ;-)

I know I'm using both methods, and the first one will not work in my current code.
The reason for it, is that the object3d don't have to be compiled, it a setting I use and now its set to compile.
I just have not yet transfered the setting to the method, so it only do the correct check based on the setting.

its it a bad idea to have some object build and others not ? would it be to expensive to run both calls, if I have a mix of Objects some compiled and others not ?
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with Object picking
« Reply #3 on: November 18, 2011, 10:54:26 am »
The second method works for all objects, not just compiled ones. You can remove the first method, it won't hurt uncompiled object.

You can freely mix compiled and uncompiled objects. There's no performance penalty when doing so.

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Problem with Object picking
« Reply #4 on: November 18, 2011, 11:03:07 am »
Okay,

I just thought the first method that worked for none-compiled object was a bit faster and then maybe more precis, so if it was possible then it would be a more correct approach to use.
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problem with Object picking
« Reply #5 on: November 18, 2011, 11:26:23 am »
It might be a bit faster depending on the scene but the accuracy is the same.