Author Topic: Selectable objects  (Read 3207 times)

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Selectable objects
« on: May 12, 2004, 05:08:42 pm »

Iíd want to have three selectable objs in my jpctís scene applet and I need, when I do a mouseís click on one of these, that some text appears, for example showing his id, on the applet area.
Iíve read the Selection Mode thread where youíve posted the following 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));

Iíve made my objs selectable using the following code:

ferito1.setSelectable(ferito1.MOUSE_SELECTABLE); (where ferito1 is an Object3D).

First question: mouseX, mouseY should contain the x,y value of the mouse on the applet area; I guess Iíve to get these values, isnít so? If itís so, using which method?

Second question: pickedObj contains the obj that Iíve selected by a mouseís click? If itís so, using the method, getID(), I get this objís id?

Bye and thanks  :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
Selectable objects
« Reply #1 on: May 12, 2004, 05:20:29 pm »
Yes, you have to get x and y of your mouse. In an applet, overwriting processMouseMotionEvent(MouseEvent e) or processMouseEvent(MouseEvent e) from Component should work (depends if you want to get an Event in case of a click or everytime the mouse moves...maybe both...). You can then query the MouseEvent for x and y.

The picking already returns the object's ID. You can obtain it simply by calling Interact2D.getObjectID(res). You don't have to ask the world for the object with ID x and ask the returned object for its ID afterwards. Both IDs are the same in this case.

Hope this helps.


  • Guest
Selectable objects
« Reply #2 on: May 12, 2004, 08:01:08 pm »
Ok, I'll try it as soon as possible....Thnaks  :D