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
.picking
.behaviors
.PickZoomBehavior
;
8 import edu
.mit
.ezyang
.gravity
.j3d
.SmartPickTranslateBehavior
;
9 import javax
.media
.j3d
.BoundingSphere
;
10 import javax
.media
.j3d
.Bounds
;
11 import javax
.media
.j3d
.BranchGroup
;
12 import javax
.media
.j3d
.Canvas3D
;
13 import javax
.media
.j3d
.Node
;
14 import javax
.media
.j3d
.Transform3D
;
15 import javax
.media
.j3d
.TransformGroup
;
16 import javax
.vecmath
.Point3d
;
17 import javax
.vecmath
.Vector3f
;
20 * Convenience group for adding elements that need to be editable.
21 * @warning Actual object should be added using addTransformChild(), NOT
23 * @author Edward Z. Yang <ezyang@mit.edu>
25 public class EditableGroup
extends BranchGroup
{
27 private TransformGroup transformGroup
;
29 public EditableGroup(Canvas3D canvas
, TransformGroup rotateGroup
, Vector3f location
) {
30 setCapability(BranchGroup
.ALLOW_DETACH
);
32 Bounds bounds
= new BoundingSphere(new Point3d(0f
, 0f
, 0f
), 1000f
);
34 SmartPickTranslateBehavior translate
= new SmartPickTranslateBehavior(this, canvas
, bounds
);
35 translate
.setRotateTransformGroup(rotateGroup
);
38 // :TODO: this needs to be modified to be smart
39 SmartPickZoomBehavior zoom
= new SmartPickZoomBehavior(this, canvas
, bounds
);
40 zoom
.setRotateTransformGroup(rotateGroup
);
43 transformGroup
= new TransformGroup();
44 transformGroup
.setCapability(TransformGroup
.ALLOW_TRANSFORM_WRITE
);
45 transformGroup
.setCapability(TransformGroup
.ALLOW_TRANSFORM_READ
);
46 transformGroup
.setCapability(TransformGroup
.ENABLE_PICK_REPORTING
);
48 Transform3D transform
= new Transform3D();
49 transform
.setTranslation(location
);
50 transformGroup
.setTransform(transform
);
52 addChild(transformGroup
);
55 public void addTransformChild(Node child
) {
56 transformGroup
.addChild(child
);