Author Topic: Interact2D behaviour  (Read 3487 times)

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Interact2D behaviour
« on: May 19, 2004, 02:54:11 pm »
Hi, Iím here again to waste your timeÖ but Iíve another question. Iíve implemented the selection objects function, as Iíve wrote in some previous thread, and Iíve place, as you said,  the following code:

Code: [Select]

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

                     if (res!=null) {
                         Object3D pickedObjs=theWorld.getObject(Interact2D.getObjectID(res));
                     }
                     
                     feritoID = Interact2D.getObjectID(res);
                     
                     System.out.println("ID: "+feritoID);


after:

Code: [Select]

 theWorld.renderScene(buffer);


When I run my applet and look in Java Console, I see that it repeats many times the string ID: 120 when I click in the applet on a non-selectable objs (I guess this code is a default code for non-selectable objs) or the string ID: with the selectable obj code. Why it repeats many times this string instead that just one time?
Second question: I need that this string appears on the java console just when I make a click on a obj; Iíve experimented that if I place the mouseís arrow on the applet window and I use the keyboard keys to move in my scene, when the arrow passes on a selectable obj (without pressing a mouseís button) appears the string ID: in the java console. Is it possible to prevent this behaviour making string appears just when I press a mouse button?

Bye and thanks a lot
 :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Interact2D behaviour
« Reply #1 on: May 19, 2004, 04:05:09 pm »
No, 120 isn't a default ID or whatever. If 120 is reported, an object with this ID has been selected, unless the method is faulty which i'm not aware of.
However, it may be related to the fact that you call the picking all the time, not just when a mouse button has been pressed. I assume that your mouse-click-method sets mouseX and mouseY? If so, let it set a flag like "clicked=true" too and do the picking only if this flag is set (and reset it afterwards). See if this fixes your problem.
The picking doesn't care if a mouse button has been pressed or not. It just fires a ray into the scene according to the coordinates you give it. If you do this every frame, so be it...
If the "120"-problem remains, please try to find out which object's ID this is and where it is located.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Interact2D behaviour
« Reply #2 on: May 19, 2004, 05:09:18 pm »
Did it, Iíve solved my problem: no more indesirable obj selection and one istance of the string returned when I select an obj.
The ď120Ē is still here. It appears whenever I click on an obj that I havenít defined as selectable (Iíve defined 3 selectable obj one that returns id 0, another that returns id 2 and the last that returns id 4, if I select every other obj, the returned value is 120). But, this isnít a great problem for me because Iíve just to ignore this id using an if conditionÖ.. so, thanks another time for your help  :D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Interact2D behaviour
« Reply #3 on: May 19, 2004, 05:25:19 pm »
Fine, but i'll look into this 120-issue...i don't see a reason for this behaviour. If nothing has been selected, null should be returned. Not an array containing nonsense values.

Edit: Please let me know if an object with ID=120 really exists (even if you haven't created it yourself). Try to get the actual object with this ID from World by calling getObject(int id). If such object exists, please tell be the name of it (getName()). Or does getObject() returns null and prints out an error?

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Interact2D behaviour
« Reply #4 on: May 20, 2004, 10:43:44 am »
Here the results:

theWorld.getObject(120)

returns: com.threed.jpct.Object3D@787c16
theWorld.getObject(120).getName()

returns: object122
Iíve loaded four separate 3ds objs: the first, the second and the third are the selecable objs the fourth is the rest of my world (it can be compared to your level in fps and itís loaded exactly as is loaded your level). Objcect122 is the rest of my world. Whose is strange is that it behaves as jPCT consider it as a selectable obj, but I have not defined it as selectable.

Bye

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Interact2D behaviour
« Reply #5 on: May 20, 2004, 12:19:44 pm »
Selectable is default. You don't have to enable selection on desired objects but disable it on all others. What i don't understand is, that the unselectable objects doesn't block the ray to prevent the "rest of the world" from being picked. Then again, i don't know how your world looks like exactly, so i guess that this is a correct behaviour in your case. I double checked the picking code and can't find anything wrong with it.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Interact2D behaviour
« Reply #6 on: May 21, 2004, 02:31:04 pm »
Don't worry....thanks  :D