I think there are two problems:

After you create the myPickingCallback and then you create the

pickSelection  you have to add the myPickingCallback to the pickSelection  .


You do it but after compiling the universeBG

Make your code look like:

PickingCallback myPickingCallback = new myPickingCallbackClass();
PickSelectionBehavior pickSelection = new
PickSelectionBehavior(universeBG,c, behaveBounds,VPTG,true);
pickSelection.setupCallback(myPickingCallback);
universeBG.addChild(pickSelection);
universeBG.compile();

su.addBranchGraph(universeBG);
su.addBranchGraph(scene);
}


The second problem might be in the callback methods:

public void transformChanged(int type, TransformGroup tg)
{ System.out.println("first method"); }
public void transformClicked(int type, TransformGroup tg)
{ System.out.println("second method"); }
public void transformDoubleClicked(int type,TransformGroup tg)
{System.out.println("third method");}



I think you have to have null checks:

public void transformChanged(int type, TransformGroup tg)
{
         if ((tg != null)
         {
                 System.out.println("first method");
         }
}
public void transformClicked(int type, TransformGroup tg)
{
         if ((tg != null)
         {
                 System.out.println("second method");
         }
}
public void transformDoubleClicked(int type,TransformGroup tg)
{
         if ((tg != null)
         {
                 System.out.println("third method");
         }
}




All of the above may be wrong.

The problem might be the hierarchy of how you add your objects to the scene.

pickSelection.setupCallback(myPickingCallback);
universeBG.addChild(pickSelection);
universeBG.compile();
su.addBranchGraph(universeBG);

This is Ok but you have added your objects to the scene branchgroup

public BranchGroup createSceneGraph(Canvas3D Canvas, SimpleUniverse su)
{
BranchGroup objRoot = new BranchGroup();
TransformGroup objScale = new TransformGroup();
objRoot.addChild(objScale);
//createObject() is called to create the textobjects
objScale.addChild(createObject( ));
return objRoot;
}

And then you have
BranchGroup scene = createSceneGraph(c, su);
.
.
.
.
.
.
  su.addBranchGraph(scene);


Your pickselection / callback are in different branchgroups than the objects.

I have one Branchgroup under the SU

pickSelection = new PickSelectionBehavior(universeBG, canvas3D,
behaveBounds, VPTG, behaviorfix);
universeBG.addChild(pickSelection);
pickSelection.setupCallback(myPickingCallback);

universeBG.compile();
simpleU.addBranchGraph(universeBG);

My objects are created dynamically after the scene is rendered which means
that they are in TransformGroups under Branchgroups.  the Branchgroups are
added to the universeBG since only Branchgroups can be added to live scenes.

I would say that your problem is definitely with the hierarchy of how you
added things.

You have added the canvas3D twice.  first with the SimpleUniverse field
then with the branchgroup scene.

I think all you have to do is eliminate the scene lines all together.   And
get rid of the Canvas3D field in the createSceneGraph method since it isn't
used.

public BranchGroup createSceneGraph( SimpleUniverse su)
{
         BranchGroup objRoot = new BranchGroup();
         TransformGroup objScale = new TransformGroup();
         objRoot.addChild(objScale);
         //createObject() is called to create the textobjects
         objScale.addChild(createObject( ));
         return objRoot;
}


public maps (){
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
c.setStereoEnable(false);
add("Center", c);
SimpleUniverse su = new SimpleUniverse(c);
TransformGroup VPTG = new TransformGroup();
VPTG
=su.getViewingPlatform().getMultiTransformGroup().getTransformGroup(0);


BranchGroup universeBG = createSceneGraph(c, su);



su.getViewingPlatform().setNominalViewingTransform();
BoundingSphere behaveBounds = new BoundingSphere(new Point3d(0.0, 0.0,
0.0), 100000.0);
PickingCallback myPickingCallback = new myPickingCallbackClass();
PickSelectionBehavior pickSelection = new
PickSelectionBehavior(universeBG,c, behaveBounds,VPTG,true);

pickSelection.setupCallback(myPickingCallback);

universeBG.addChild(pickSelection);
universeBG.compile();
su.addBranchGraph(universeBG);

}








At 09:20 PM 01/12/2001 +0100, you wrote:
>Dear Eric
>
>I have been trying to work as per your suggestions since u sent the last
>mail.
>i have managed to download all your classes, packaged them rightly
>and have written an inner class called myPickingCallbackClass the same way.
>Now the problem is like this, that the method transformClicked is called but
>everytime one clicks the mouse anywhere on the applet window. this is
>because i still dont know how to relate it to the objects.
>Basically i have a lot of text2D objects and i want that everytime one
>clicks on them some action happens.
>still cant figure out whether the picking action needs to be related to the
>Transform3D or the text object or the bounds itself and how, such that it
>does not affect the other objects.
>my Pseudo code is like this:
>----------------------------------------------------------------------------
>--------------------
>Class maps extends Applet  {
>
>public BranchGroup createSceneGraph(Canvas3D Canvas, SimpleUniverse su)
>{
>          BranchGroup objRoot = new BranchGroup();
>          TransformGroup objScale = new TransformGroup();
>         objRoot.addChild(objScale);
>
>         //createObject() is called to create the textobjects
>         objScale.addChild(createObject( ));
>       return objRoot;
>}
>
>private Group createObject(){
>     //TG for all the text objects
>     TransformGroup bill = new TransformGroup();
>     bill.setPickable(true);
>     //text objects r created and added to bill with
>     return bill;
>}
>
>  public maps (){
>     setLayout(new BorderLayout());
>     Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
>     c.setStereoEnable(false);
>     add("Center", c);
>     SimpleUniverse su = new SimpleUniverse(c);
>      TransformGroup VPTG = new TransformGroup();
>      VPTG
>=su.getViewingPlatform().getMultiTransformGroup().getTransformGroup(0);
>      BranchGroup scene = createSceneGraph(c, su);
>      BranchGroup universeBG = new BranchGroup();
>
>      su.getViewingPlatform().setNominalViewingTransform();
>      BoundingSphere behaveBounds = new BoundingSphere(new Point3d(0.0, 0.0,
>0.0), 100000.0);
>
>      PickingCallback myPickingCallback = new myPickingCallbackClass();
>      PickSelectionBehavior pickSelection = new
>PickSelectionBehavior(universeBG,c, behaveBounds,VPTG,true);
>      universeBG.addChild(pickSelection);
>     universeBG.compile();
>
>      su.addBranchGraph(universeBG);
>       pickSelection.setupCallback(myPickingCallback);
>      su.addBranchGraph(scene);
>}
>
>public static void main(String argv[])
>   {new MainFrame(new maps(), 750, 550);
>   }
>---------------------------------------
>static class myPickingCallbackClass extends Object implements
>PickingCallback{
>
>  public void transformChanged(int type, TransformGroup tg)
>  {  System.out.println("first method");              }
>
>  public void transformClicked(int type, TransformGroup tg)
>         {  System.out.println("second method");          }
>
>  public void transformDoubleClicked(int type,TransformGroup tg)
>         {System.out.println("third method");}
>}
>
>}

***********************************************************************
Eric Reiss
Manager MEMS Lab
Swanson New Product Incubator
School of Engineering  - University of Pittsburgh

3700 O'Hara Street
647 Benedum Hall
Pittsburgh, PA 15261
Phone: 412-624-9696
Email: [EMAIL PROTECTED]
http://www.sigda.acm.org/Eric/
***********************************************************************

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to