Selectable objects

Started by Tornado7, May 12, 2004, 05:08:42 PM

Previous topic - Next topic

Tornado7

Hi,

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  :)

EgonOlsen

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.

Anonymous

Ok, I'll try it as soon as possible....Thnaks  :D