17 package com.generalrobotix.ui.view.tdview;
20 import java.awt.event.*;
21 import javax.media.j3d.*;
22 import javax.vecmath.*;
28 import com.sun.j3d.utils.picking.*;
30 class ObjectTranslationHandler
extends OperationHandler {
31 private static final float TRANSLATION_FACTOR = 0.002f;
33 private TransformGroup tgTarget_;
34 private Vector3f norm_;
35 private Point prevPoint_ =
new Point();
36 private boolean isPicked_;
38 public void processPicking(MouseEvent evt, BehaviorInfo
info) {
39 prevPoint_.x = evt.getPoint().x;
40 prevPoint_.y = evt.getPoint().y;
46 info.pickCanvas.setShapeLocation(prevPoint_.x, prevPoint_.y);
47 PickResult pickResult = info.pickCanvas.pickClosest();
48 if (pickResult ==
null)
51 (TransformGroup)pickResult.getNode(PickResult.TRANSFORM_GROUP);
52 GrxModelItem model = SceneGraphModifier.getModelFromTG(tg);
56 tg = model.getTransformGroupRoot();
59 if (_enableBoundingBox(tg, info)) {
61 Point3d startPoint = info.pickCanvas.getStartPosition();
62 PickIntersection
intersection = pickResult.getClosestIntersection(startPoint);
63 norm_ =
new Vector3f(intersection.getPointNormal());
66 }
catch (CapabilityNotSetException ex) {
70 _disableBoundingBox();
74 public void processStartDrag(MouseEvent evt, BehaviorInfo info) {
80 public void processDragOperation(MouseEvent evt, BehaviorInfo info) {
86 Transform3D tr =
new Transform3D();
87 Transform3D l2vw =
new Transform3D();
88 Transform3D trTarget2View =
new Transform3D();
90 tgTarget_.getLocalToVworld(l2vw);
91 tgTarget_.getTransform(tr);
92 trTarget2View.mul(l2vw, tr);
94 TransformGroup tgView = info.drawable.getTransformGroupRoot();
95 tgView.getLocalToVworld(l2vw);
96 tgView.getTransform(tr);
100 l2vw.mul(trTarget2View);
101 trTarget2View.set(l2vw);
106 (float)(evt.getPoint().getX() - prevPoint_.getX());
108 - TRANSLATION_FACTOR *
109 (float)(evt.getPoint().getY() - prevPoint_.getY());
110 Vector3f mouse =
new Vector3f(fdx, fdy, 0.0
f);
111 Vector3f normal =
new Vector3f();
113 trTarget2View.transform(norm_, normal);
115 float inner = normal.dot(mouse);
119 trTarget2View.invert();
120 trTarget2View.transform(mouse);
123 tgTarget_.getTransform(l2vw);
125 GrxLinkItem link = SceneGraphModifier.getLinkFromTG(tgTarget_);
126 link.setTransform(l2vw);
127 _transformChanged(info);
129 prevPoint_.x = evt.getPoint().x;
130 prevPoint_.y = evt.getPoint().y;
132 ((Grx3DView)info.drawable).showOption();
137 public void processReleased(MouseEvent evt, BehaviorInfo info) {
143 public boolean processTimerOperation(BehaviorInfo info) {
149 public void disableHandler() {
150 _disableBoundingBox();
153 public void setPickTarget(TransformGroup tg, BehaviorInfo info) {
154 if (tg != tgTarget_) {
155 _enableBoundingBox(tg, info);
161 private void _disableBoundingBox() {
162 if (tgTarget_ !=
null) {
168 private boolean _enableBoundingBox(TransformGroup tg, BehaviorInfo info) {
169 GrxModelItem model = SceneGraphModifier.getModelFromTG(tg);
174 info.manager_.focusedItem(model);
178 private void _transformChanged(BehaviorInfo info) {
179 GrxModelItem model = SceneGraphModifier.getModelFromTG(tgTarget_);
181 System.out.println(
"no manipulatable.");
184 model.calcForwardKinematics();
185 model.updateInitialTransformRoot();
int intersection(const fLineVec &lv1, const fLineVec &lv2, fVec3 &c1, fVec3 &c2, double &d, double eps)
#define null
our own NULL pointer
item corresponds to a robot model