Picking

4 views
Skip to first unread message

Chris Bolduc

unread,
May 16, 2006, 2:27:23 PM5/16/06
to GameDev370
I am trying to set up picking for collision detection, but it doesn't
work at all.

I declared a PickTool at the top of my World:
protected PickTool picker;

Next, I set all of the shapes I want to pick from to be pickable:
shape3d.setPickable(true);

Then I try picking:

public void doPicking() {
picker.setShapeRay(p_eye, velocity);
PickResult picked = picker.pickClosest();
if (picked != null) {
velocity.z = 0;
velocity.x = 0;
}
else {
return;
}
PickIntersection intersect = picked.getIntersection(0);
Point3d nextpoint = intersect.getPointCoordinates();
}

This is from a tutorial at http://www.benmoxon.info/Java3d/purple7.htm.

Nothing happens when there is a collision. The PickResult is always
null. What am I doing wrong?

W. Wood Harter

unread,
May 16, 2006, 4:21:54 PM5/16/06
to GameD...@googlegroups.com
Do you get an exception?

Here is one of my picking routines from fps370. This checks the camera movement. The ball movement is verysimilar but more complex after it has a result as it  has to calculate the bounce.

    if (pickTool == null)
    {
      // create the picktool to always use the map
      pickTool = new PickTool (bgMap);
    }
     
    // set the shape of the pick tool as a ray from the current location
    // in the direction of the move
    pickTool.setShapeRay( new Point3d (vViewPos.x,vViewPos.y,vViewPos.z),
                       new Vector3d (vMove.x,vMove.y,vMove.z));
   
    // get a pick to the closest shape
    PickResult res = pickTool.pickClosest();
   
    // if we got a result, check for the closest intersection distance
    if (res != null)
    {
      int j;
      float closestIntersect = Double.MAX_VALUE ; // a big number just in case
      for (j = 0 ;j < res.numIntersections();j ++ )
      {
        if ((j == 0 ) || (res.getIntersection(j).getDistance() < closestIntersect))
          closestIntersect = ( float ) res.getIntersection(j).getDistance();
      }

      if (closestIntersect < 2.0 )
      {
        // collision, adjust accordingly
        vMove.set( 0.0f , 0.0f , 0.0f );
        return true;
      }      
    }    

I also had a lot of trouble with setPickable. It didn't work for me, but it gave an exception and that is why I asked about exceptions. This is what I had to use instead of setPickable.

        PickTool.setCapabilities((Shape3D)o,PickTool.INTERSECT_COORD);
 

Wood

--
http://www.memorize-it.com



From: "Chris Bolduc" <chris....@gmail.com>
Sent: Tuesday, May 16, 2006 11:28 AM
To: "GameDev370" <GameD...@googlegroups.com>
Subject: [GameDev370] Picking

Chris Bolduc

unread,
May 23, 2006, 6:15:40 PM5/23/06
to GameDev370
Gaaah! Formatting! I fixed it for you:

/**
* Does picking
* @see http://www.benmoxon.info/Java3d/purple7.htm
* @return true if something was picked
*/
public boolean doPicking() {
if (pick_tool == null) {
// create the pick_tool to always use the map
pick_tool = new PickTool(bgMain);


}
// set the shape of the pick tool as a ray from the current location
// in the direction of the move

pick_tool.setShapeRay(p_eye, velocity);


// get a pick to the closest shape

PickResult res = pick_tool.pickClosest();


// if we got a result, check for the closest intersection distance
if (res != null) {

float closestIntersect = Float.MAX_VALUE;


// a big number just in case

for (int j = 0;j < res.numIntersections(); j++) {


if ( (j == 0) || (res.getIntersection(j).getDistance() <

closestIntersect) ) {
closestIntersect = (float) res.getIntersection(j).getDistance();
}
}
if (closestIntersect < 2.0) {
// collision, adjust accordingly
}
return true;
}
return false;
}

W. Wood Harter

unread,
May 23, 2006, 6:37:46 PM5/23/06
to GameD...@googlegroups.com
What did you fix? The version I sent you is working fine for me.

Wood

--
http://www.memorize-it.com



From: "Chris Bolduc" <chris....@gmail.com>
Sent: Tuesday, May 23, 2006 3:16 PM
To: "GameDev370" <GameD...@googlegroups.com>
Subject: [GameDev370] Re: Picking

Darrell Noice

unread,
May 23, 2006, 6:48:06 PM5/23/06
to GameDev370
wood, albeit clean in email, on the groups page, the code you presented
had tons of whitespace interlaced in it making it rather difficult to
read, that's all.

berm...@chapman.edu

unread,
May 23, 2006, 6:51:32 PM5/23/06
to gamed...@googlegroups.com
---------------------------- Original Message ----------------------------
Subject: [GameDev370] Re: Picking
From: "Chris Bolduc" <chris....@gmail.com>
Date: Tue, May 23, 2006 3:15 pm
To: "GameDev370" <GameD...@googlegroups.com>
--------------------------------------------------------------------------


Gaaah! Even more evil Formatting! I fixed it for you:

Reply all
Reply to author
Forward
0 new messages