|
Implementing picking with Picking Utility Classes |
|
|
There are two basic approaches to using the picking features of Java 3D: use
objects of picking classes,or create custom picking classes and use instances
of these custom classes.
The next list shows the simple recipe for using the mouse picking utility
classes:
- Create your scene graph.
- Create a picking behavior object with root, canvas, and bounds specification.
- Add the behavior object to the scene graph.
- Enable the appropriate capabilities for scene graph objects.
public BranchGroup createSceneGraph(Canvas3D canvas) {
BranchGroup objRoot = new BranchGroup();
TransformGroup objRotate = null;
PickRotateBehavior pickRotate = null;
Transform3D transform = new Transform3D();
BoundingSphere behaveBounds = new BoundingSphere();
// create ColorCube and PickRotateBehavior objects
transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f));
objRotate = new TransformGroup(transform);
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
objRoot.addChild(objRotate);
objRotate.addChild(new ColorCube(0.4));
pickRotate = new PickRotateBehavior(objRoot, canvas, behaveBounds);
objRoot.addChild(pickRotate);
// add a second ColorCube object to the scene graph
transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f));
objRotate = new TransformGroup(transform);
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
objRoot.addChild(objRotate);
objRotate.addChild(new ColorCube(0.4));
objRoot.compile();
return objRoot;
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.