2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package edu
.mit
.ezyang
.gravity
.j3d
;
7 import com
.sun
.j3d
.utils
.behaviors
.mouse
.MouseBehavior
;
8 import com
.sun
.j3d
.utils
.behaviors
.mouse
.MouseBehaviorCallback
;
9 import com
.sun
.j3d
.utils
.behaviors
.mouse
.MouseZoom
;
10 import com
.sun
.j3d
.utils
.picking
.PickResult
;
11 import com
.sun
.j3d
.utils
.picking
.behaviors
.PickMouseBehavior
;
12 import com
.sun
.j3d
.utils
.picking
.behaviors
.PickingCallback
;
13 import javax
.media
.j3d
.Bounds
;
14 import javax
.media
.j3d
.BranchGroup
;
15 import javax
.media
.j3d
.Canvas3D
;
16 import javax
.media
.j3d
.Transform3D
;
17 import javax
.media
.j3d
.TransformGroup
;
20 * Reimplemented PickZoomBehavior, but uses SmartMouseWheelZoom, which
21 * has been customized to take into account rotations relative to the surface
22 * display. Modifications are solely in constructor and new setRotateTransformGroup
24 * @author Edward Z. Yang <ezyang@mit.edu>
26 public class SmartPickZoomBehavior
extends PickMouseBehavior
implements MouseBehaviorCallback
{
28 private SmartMouseZoom zoom
;
29 private PickingCallback callback
= null;
30 private TransformGroup currentTG
;
33 * Propagates rotation transform group to SmartMouseTranslate in order
34 * to provide appropriate information to transform.
35 * @note We only support one rotation transform group; this should be
36 * enough for people with shallow object graphs.
37 * @param group TransformGroup with rotation we need to adjust to
39 public void setRotateTransformGroup(TransformGroup group
) {
40 zoom
.setRotateTransformGroup(group
);
44 * Creates a pick/zoom behavior that waits for user mouse events for
46 * @param root Root of your scene graph.
47 * @param canvas Java 3D drawing canvas.
48 * @param bounds Bounds of your scene.
50 public SmartPickZoomBehavior(BranchGroup root
, Canvas3D canvas
, Bounds bounds
) {
51 super(canvas
, root
, bounds
);
52 zoom
= new SmartMouseZoom(MouseBehavior
.MANUAL_WAKEUP
);
53 zoom
.setTransformGroup(currGrp
);
54 currGrp
.addChild(zoom
);
55 zoom
.setSchedulingBounds(bounds
);
56 this.setSchedulingBounds(bounds
);
60 * Update the scene to manipulate any nodes. This is not meant to be
61 * called by users. Behavior automatically calls this. You can call
62 * this only if you know what you are doing.
64 * @param xpos Current mouse X pos.
65 * @param ypos Current mouse Y pos.
67 public void updateScene(int xpos
, int ypos
) {
68 TransformGroup tg
= null;
70 if (mevent
.isAltDown() && !mevent
.isMetaDown()) {
72 pickCanvas
.setShapeLocation(xpos
, ypos
);
73 PickResult pr
= pickCanvas
.pickClosest();
75 ((tg
= (TransformGroup
) pr
.getNode(PickResult
.TRANSFORM_GROUP
)) != null) &&
76 (tg
.getCapability(TransformGroup
.ALLOW_TRANSFORM_READ
)) &&
77 (tg
.getCapability(TransformGroup
.ALLOW_TRANSFORM_WRITE
))) {
78 zoom
.setTransformGroup(tg
);
81 // Need to clean up Issue 123 --- Chien
82 // freePickResult(pr);
83 } else if (callback
!= null) {
84 callback
.transformChanged(PickingCallback
.NO_PICK
, null);
90 * Callback method from MouseZoom
91 * This is used when the Picking callback is enabled
93 public void transformChanged(int type
, Transform3D transform
) {
94 callback
.transformChanged(PickingCallback
.ZOOM
, currentTG
);
98 * Register the class @param callback to be called each
99 * time the picked object moves
101 public void setupCallback(PickingCallback callback
) {
102 this.callback
= callback
;
103 if (callback
== null) {
104 zoom
.setupCallback(null);
106 zoom
.setupCallback(this);