Author Topic: Mouse to pick up objects  (Read 4554 times)

Offline yxbnnl

  • byte
  • *
  • Posts: 19
    • View Profile
Mouse to pick up objects
« on: March 23, 2009, 09:18:23 am »
 How to use the mouse to pick up objects in the jpct!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse to pick up objects
« Reply #1 on: March 23, 2009, 01:21:29 pm »
As long as you don't care about using the compiled Object3Ds that will surface with the upcoming 1.18 release, Interact2D is what you want.

You simply feed your mouse coords into http://www.jpct.net/doc/com/threed/jpct/Interact2D.html#reproject2D3D(com.threed.jpct.Camera,%20com.threed.jpct.FrameBuffer,%20int,%20int)

and the resulting SimpleVector in http://www.jpct.net/doc/com/threed/jpct/Interact2D.html#pickPolygon(com.threed.jpct.VisList,%20com.threed.jpct.SimpleVector)

You'll get an int[] as result (assuming you have actually picked something). From that int[], you can get the picked object's ID, which you can put into World.getObject(<int>) to obtain the actual object instance.


Offline yxbnnl

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Mouse to pick up objects
« Reply #2 on: March 24, 2009, 01:57:13 am »
Can you give me some simple example for the interact2D ~
thanks   :)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Mouse to pick up objects
« Reply #3 on: March 24, 2009, 02:49:01 am »
This is something I'm experimenting with:
Code: [Select]
    public void mouseMoved(MouseEvent e) {
        SimpleVector s = Interact2D.reproject2D3D(world.getCamera(), buffer, e.getX(), e.getY());
        int[] i = Interact2D.pickPolygon(world.getVisibilityList(), s);

        if(Interact2D.getObjectID(i)!= -1)
        {
          obj = world.getObject(Interact2D.getObjectID(i));
          obj.setAdditionalColor(java.awt.Color.RED);
        }
        else if(obj != null) obj.clearAdditionalColor();
        }
« Last Edit: March 24, 2009, 03:13:49 am by fireside »
click here->Fireside 7 Games<-

Offline yxbnnl

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Mouse to pick up objects
« Reply #4 on: March 24, 2009, 10:10:30 am »
How to use MuseEvent add to  the JFramebuffer ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse to pick up objects
« Reply #5 on: March 24, 2009, 12:15:27 pm »
There is no JFrameBuffer...but there is a FrameBuffer. And you can't add listeners to it. If you are using the software renderer or the AWTGLRenderer, you can simply attach your listeners to the component in which you are drawing the rendered frame into.
If you are using the native hardware renderer, there are no listeners. You have to use the Mouse class from LWJGL (http://lwjgl.org/javadoc/org/lwjgl/input/Mouse.html).