Author Topic: Selection Mode  (Read 4458 times)

Offline jmrives

  • byte
  • *
  • Posts: 2
    • View Profile
Selection Mode
« on: October 03, 2003, 02:43:27 am »
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
Remember, wherever you go, there you are!"

                                     -- B. Bonzai

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Selection Mode
« Reply #1 on: October 03, 2003, 03:08:09 am »
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.

Offline jmrives

  • byte
  • *
  • Posts: 2
    • View Profile
Selection Mode
« Reply #2 on: October 03, 2003, 02:56:18 pm »
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
Remember, wherever you go, there you are!"

                                     -- B. Bonzai

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Selection Mode
« Reply #3 on: October 03, 2003, 03:14:00 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Selection Mode
« Reply #4 on: October 03, 2003, 03:16:32 pm »
Basically, it's used like this:

Code: [Select]

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));
}


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.

Anonymous

  • Guest
Selection Mode
« Reply #5 on: October 09, 2003, 11:30:49 pm »
Thanks Egon, that was very helpful. It was also reassuring that it does not have to happen after the image is rendered, which was one of my concerns.

Joel