Mouse to pick up objects

Started by yxbnnl, March 23, 2009, 09:18:23 AM

Previous topic - Next topic

yxbnnl

 How to use the mouse to pick up objects in the jpct!

EgonOlsen

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.


yxbnnl

Can you give me some simple example for the interact2D ~
thanks   :)

fireside

#3
This is something I'm experimenting with:
    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();
        }
click here->Fireside 7 Games<-

yxbnnl

How to use MuseEvent add to  the JFramebuffer ?

EgonOlsen

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