 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Paul Drallos Guest
|
Posted: Tue Jun 28, 2005 7:21 pm Post subject: PickResult won't return TransformGroup info |
|
|
I recently borrowed some PickMouseBehavior code from Palmer's book, which seems to work pretty well.
My simple test scene graph consists of a BranchGroup containing three TransformGroups. Each TransformGroup contains one Shape3D object. The scene graph diagram is:
(BG)
/ |
(TG1)(TG2)(TG3)
| Quote: | | |
(S1) (S2) (S3) |
The PickMouseBehavior I'm using does a fine job of picking the Shape3D Leaf Nodes. But the information I need is actually the Leaf's parent, which is a TransformGroup. But when I try to determine the TransformGroup from the PickResult, I only get a null pointer for it. I do not get an error message.
Ultimately, what I need to do is get the indexOfChild for the TransformGroup so that I can temporarily replace it with a different TransformGroup and child). To do that, I need the index of the TG within the BranchGroup. For some reason, my behavior doesn't identify the TransformGroup.
Can someone please help me with this?
Here is the PickMouseBehavior that I'm using:
----------------------------------------------------------------------
----------------------------------------------------------------------
public class pMouseBehavior extends PickMouseBehavior {
private BranchGroup pickRoot;
WakeupOnAWTEvent buttonPressed =
new WakeupOnAWTEvent(MouseEvent.MOUSE_EVENT_MASK);
public pMouseBehavior(Canvas3D pickCanvas, BranchGroup pickRoot,
Bounds pickBounds) {
super(pickCanvas, pickRoot, pickBounds);
setSchedulingBounds(pickBounds);
}
public void initialize() {
wakeupOn(buttonPressed);
}
public void processStimulus(Enumeration criteria) {
WakeupOnAWTEvent theCriterion = (WakeupOnAWTEvent) criteria.nextElement();
AWTEvent theEvents[] = theCriterion.getAWTEvent();
if (theEvents[0].getID() == MouseEvent.MOUSE_RELEASED) {
MouseEvent theMouseEvent = (MouseEvent) theEvents[0];
if((theMouseEvent.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
int xpos = theMouseEvent.getX();
int ypos = theMouseEvent.getY();
Shape3D pickedShape = null;
TransformGroup pickedTransform = null;
PickResult pickResult = null;
pickCanvas.setShapeLocation(xpos,ypos);
pickResult = pickCanvas.pickClosest();
if(pickResult != null) pickedShape = (Shape3D)
pickResult.getNode(PickResult.SHAPE3D);
if(pickedShape != null){
System.out.println("Picked the " + pickedShape.getUserData());
pickedTransform = (TransformGroup)
pickResult.getNode(PickResult.TRANSFORM_GROUP);
if(pickedTransform != null)
System.out.println("picked a transform");
else
System.out.println("transform not picked");
}
else
System.out.println("Nothing picked");
}
}
wakeupOn(buttonPressed);
}
public void updateScene(int xpos, int ypos) {}
} \ end of class pMouseBehavior
-------------
|
|
| Back to top |
|
 |
Paul Drallos Guest
|
Posted: Tue Jun 28, 2005 7:59 pm Post subject: Re: PickResult won't return TransformGroup info |
|
|
Paul Drallos wrote:
| Quote: |
....
The PickMouseBehavior I'm using does a fine job of picking the Shape3D
Leaf Nodes. But the information I need is actually the Leaf's parent,
which is a TransformGroup. But when I try to determine the
TransformGroup from the PickResult, I only get a null pointer for it. I
do not get an error message.
...
|
Man, I'm good! Only half an hour after I posted this question, I figured out the answer: I needed to set the capability to ENABLE_PICK_REPORTING on the TransformGroups in question. Since I wasn't getting a 'capability not set' error, I didn't think that was a problem. But I tried it anyway and it works!
Thanks for your patience.
Paul
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|