Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 10:29:11 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Xith3D equivalent to Java3D PickTool class
Pages: [1]
Print
Author Topic: Xith3D equivalent to Java3D PickTool class  (Read 575 times)
xurde
Just dropped in

Offline Offline

Posts: 4


View Profile Email
« on: 03. March 2009, 03:14:45 pm »

Hi all,
I’m porting a Java3D application into Xith3D and I’m not sure how to port the picking system.

In Java3D, I used picking in a way completely independent of user actions (i.e. mouse clicks): I just project rays from a mobile robot (an aircraft) and obtain its intersection points (if any) with the terrain.

I show the Java3D source just to make the point clearer:

      // Prepare the pick tool to obtain closest distances to the terrain
      PickTool pickTool = new PickTool(terrain);
      pickTool.setFlags(PickInfo.CLOSEST_DISTANCE);
      pickTool.setMode(PickInfo.PICK_GEOMETRY);

      .......

      // Calculate rays origin (the current aircraft position)
      Point3f rayOrigin = aircraft.getPosition();

      for (Ray ray : Ray.values())
      {
         // Calculate the direction for each ray specified by its euler angles
         Vector3f rayDirection = calculateRayDirection(ray);

         // Calculate the closest distance to the terrain for each ray
         pickTool.setShapeRay(rayOrigin, rayDirection);
         PickInfo pickInfo = pickTool.pickClosest();
         distances[ray.ordinal()] = (pickInfo != null)?pickInfo.getClosestDistance():INFINITY;
         ......

I cannot see how to implements this in Xith3D, as all the picking system seems to be conceived for user’s pickings with the mouse. I guest Xith3D uses a completely different approach I’m missing...

Thank you a lot!
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 03. March 2009, 07:26:36 pm »

Please have a look at PickingLibrary. Some of its methods take an instance of Ray3f. You can define your Ray3f instance as you like. Maybe you want to use the Ray3f extension "PickRay" to compute it. Then you can pass it to the PickingLibrary. Pass null for the MouseButton parameter. This value is simply forwarded to the PickResult, that is returned by the picking algorithm.

There are some testcases in xith-tk in org.xith3d.test.picking.

Marvin
Logged
xurde
Just dropped in

Offline Offline

Posts: 4


View Profile Email
« Reply #2 on: 06. March 2009, 10:26:56 am »

Right! Thanks

For any reason I ignored that method,  sorry.

By the way, I have included a new version of pickNearest method that takes a userObject parameter ; its useful for me. Maybe you can include it in the SVN trunk.


    /**
     * Finds the closest intersection of a given List of GroupNodes with a
     * given ray.
     * You can use it, if you want to know where your mouse is pointing at.
     *
     * Don't forget to set the static property Node.setDefaultPickable() to true.
     * If you are using (Ext)Xith3DEnvironment, it is already done.
     *
     * @param groups the groups that should be tested
     * @param pickRay the pick ray
     * @param button the mouse button, that was clicked
     * @param userObject the userObject to pass to the listener
     * @param l the listener to be notified of the PickResult
     */
    public static void pickNearest( List< ? extends GroupNode > groups, Ray3f pickRay, MouseButton button, Object userObject, NearestPickListener l )
    {
        pickNearest( groups, pickRay, button, l, userObject );
    }
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 06. March 2009, 02:38:53 pm »

This method already exists. But it wasn't public... for some reason. It is public now.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic