jPCT - a 3d engine for Java > Support

Selection Mode

(1/2) > >>

jmrives:
Do you have any plans to provide a selection mode as per OpenGL?  This would be very useful in writing an efficient picking function.

Thanks,
Joel

EgonOlsen:
Why do you want to implement your own picking? There is picking in jPCT (have a look at the Interact2D class). Does this not satisfy your needs? If it doesn't, please let me know what you are missing.

jmrives:
Hello Egon,

Yes, I saw the picking via Interact2D and it looks very straight forward to use. I just do not know the underlying algorithm. Could you perhaps reveal this to us?

Thanks and I appreciate all the good work you have done here. The interfaces are very clean and the documentation has been helpful.

Joel

EgonOlsen:
It's a geometrical approach using a ray-polygon intersection test. I should really include an example of how to do it exactly in jPCT...
The object has to be "selectable" (see setSelectable() in Object3D) to be picked. None-selectable objects will still act as a "block" to the ray, i.e. if the object to be picked lies behind an object that is not selectable, the ray will still be blocked by that object and no object will be returned as picked.

EgonOlsen:
Basically, it's used like this:


--- Code: ---
SimpleVector ray=Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
int[] res=Interact2D.pickPolygon(theWorld.getVisibilityList(), ray);

if (res!=null) {
   Object3D pickedObj=theWorld.getObject(Interact2D.getObjectID(res));
}

--- End code ---


This has to be done after calling renderScene(). The docs for Interact2D state that it has to be done after "rendering the image", which is misleading. The image doesn't have to be drawn into the framebuffer yet, you just have to make sure that renderScene() has been called before. I'll correct this flaw in the docs.

Navigation

[0] Message Index

[#] Next page

Go to full version