www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: yxbnnl on March 23, 2009, 09:18:23 am

Title: Mouse to pick up objects
Post by: yxbnnl on March 23, 2009, 09:18:23 am
 How to use the mouse to pick up objects in the jpct!
Title: Re: Mouse to pick up objects
Post by: EgonOlsen 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) (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) (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.

Title: Re: Mouse to pick up objects
Post by: yxbnnl on March 24, 2009, 01:57:13 am
Can you give me some simple example for the interact2D ~
thanks   :)
Title: Re: Mouse to pick up objects
Post by: fireside 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();
        }
Title: Re: Mouse to pick up objects
Post by: yxbnnl on March 24, 2009, 10:10:30 am
How to use MuseEvent add to  the JFramebuffer ?
Title: Re: Mouse to pick up objects
Post by: EgonOlsen 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 (http://lwjgl.org/javadoc/org/lwjgl/input/Mouse.html)).