1 package edu
.mit
.ezyang
.gravity
.j3d
.utils
.picking
.behaviors
;
3 import edu
.mit
.ezyang
.gravity
.j3d
.utils
.behaviors
.mouse
.SmartMouseTranslate
;
4 import edu
.mit
.ezyang
.gravity
.j3d
.*;
5 import com
.sun
.j3d
.utils
.picking
.behaviors
.*;
6 import com
.sun
.j3d
.utils
.picking
.*;
7 import com
.sun
.j3d
.utils
.behaviors
.mouse
.*;
8 import javax
.media
.j3d
.*;
11 * Reimplemented PickTranslateBehavior, but uses SmartMouseTranslate, which
12 * has been customized to take into account rotations relative to the surface
13 * display. Modifications are solely in constructor and new setRotateTransformGroup
15 * @warning Convenience constructor with pick mode parameter not implemented.
16 * @author Edward Z. Yang <ezyang@mit.edu>
18 public class SmartPickTranslateBehavior
extends PickMouseBehavior
implements MouseBehaviorCallback
{
20 private SmartMouseTranslate translate
;
21 private PickingCallback callback
= null;
22 private TransformGroup currentTG
;
25 * Propagates rotation transform group to SmartMouseTranslate in order
26 * to provide appropriate information to transform.
27 * @note We only support one rotation transform group; this should be
28 * enough for people with shallow object graphs.
29 * @param group TransformGroup with rotation we need to adjust to
31 public void setRotateTransformGroup(TransformGroup group
) {
32 translate
.setRotateTransformGroup(group
);
36 * Creates a pick/translate behavior that waits for user mouse events for
38 * @param root Root of your scene graph.
39 * @param canvas Java 3D drawing canvas.
40 * @param bounds Bounds of your scene.
42 public SmartPickTranslateBehavior(BranchGroup root
, Canvas3D canvas
, Bounds bounds
) {
43 super(canvas
, root
, bounds
);
44 translate
= new SmartMouseTranslate(MouseBehavior
.MANUAL_WAKEUP
);
45 translate
.setTransformGroup(currGrp
);
46 currGrp
.addChild(translate
);
47 translate
.setSchedulingBounds(bounds
);
48 this.setSchedulingBounds(bounds
);
51 // below code is copied verbatim from com.sun.j3d.utils.picking.behaviors
54 * Update the scene to manipulate any nodes. This is not meant to be
55 * called by users. Behavior automatically calls this. You can call
56 * this only if you know what you are doing.
58 * @param xpos Current mouse X pos.
59 * @param ypos Current mouse Y pos.
61 public void updateScene(int xpos
, int ypos
) {
62 TransformGroup tg
= null;
64 if (!mevent
.isAltDown() && mevent
.isMetaDown()) {
66 pickCanvas
.setShapeLocation(xpos
, ypos
);
67 PickResult pr
= pickCanvas
.pickClosest();
69 ((tg
= (TransformGroup
) pr
.getNode(PickResult
.TRANSFORM_GROUP
)) != null) &&
70 (tg
.getCapability(TransformGroup
.ALLOW_TRANSFORM_READ
)) &&
71 (tg
.getCapability(TransformGroup
.ALLOW_TRANSFORM_WRITE
))) {
73 translate
.setTransformGroup(tg
);
76 // Need to clean up Issue 123 --- Chien
77 // freePickResult(pr);
78 } else if (callback
!= null) {
79 callback
.transformChanged(PickingCallback
.NO_PICK
, null);
86 * Callback method from MouseTranslate
87 * This is used when the Picking callback is enabled
89 public void transformChanged(int type
, Transform3D transform
) {
90 callback
.transformChanged(PickingCallback
.TRANSLATE
, currentTG
);
94 * Register the class @param callback to be called each
95 * time the picked object moves
97 public void setupCallback(PickingCallback callback
) {
98 this.callback
= callback
;
99 if (callback
== null) {
100 translate
.setupCallback(null);
102 translate
.setupCallback(this);