Problem with Object picking

Started by cintix, November 18, 2011, 09:19:25 AM

Previous topic - Next topic

cintix

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



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

EgonOlsen

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

Interact2D.reproject2D3DWS(...)

instead of

Interact2D.reproject2D3D(...)

..or otherwise, it won't work when the camera starts moving (i.e. if world and camera space start to differ).

cintix

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

EgonOlsen

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.

cintix

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

EgonOlsen

It might be a bit faster depending on the scene but the accuracy is the same.