Author Topic: Picking Objects (Pegando Objetos)  (Read 2988 times)

Offline MegasXLS

  • byte
  • *
  • Posts: 29
    • View Profile
Picking Objects (Pegando Objetos)
« on: February 10, 2011, 08:02:25 pm »
Hello everybody,

would like a hint of you forum,
I like to picking objects in my world(one applet)?

I'm using these instructions:

SimpleVector dir = Interact2D.reproject2D3DWS (world.getCamera (), buffer, e.getX (), e.getY ());
  Object [] res = world.calcMinDistanceAndObject3D (world.getCamera (). GetPosition (), dir, 1000 / * or whatever * /);

I can even take a 3D object, but not very accurately, need to click under the object3D to get your res [1].

after i use:

if (res [1] == Object3D) {
System.out.println ("I'm clicking on the object");
}

Thanks in advance

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Picking Objects (Pegando Objetos)
« Reply #1 on: February 10, 2011, 09:45:10 pm »
The usual reason for this is, that your x/y-coordinates are not the ones that you think they are. Maybe parts of the framebuffer are hidden by a window's title bar or similar (happens if you blit directly into a frame for example). So that 0,0 in the window actually is something like 2,10 in the framebuffer.

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Picking Objects (Pegando Objetos)
« Reply #2 on: February 10, 2011, 10:05:09 pm »
getY() - 24 might help. 24 is about the default height for a title bar, taskbar etc etc.
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline MegasXLS

  • byte
  • *
  • Posts: 29
    • View Profile
Re: Picking Objects (Pegando Objetos)
« Reply #3 on: February 10, 2011, 10:53:11 pm »
Thanks guys.

The solutions was: SimpleVector dir=Interact2D.reproject2D3DWS(world.getCamera(), buffer, e.getX(), e.getY() + 30);

Olsen, congratulations for the JPCT. This is awesome.

Thanks too Kaiidyn. /o/

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Picking Objects (Pegando Objetos)
« Reply #4 on: February 10, 2011, 10:56:15 pm »
You can get the insets from a frame. That's better than using fixed values that will change from OS to OS.