17 package com.generalrobotix.ui.view.tdview;
20 import java.awt.event.*;
21 import javax.media.j3d.*;
22 import javax.vecmath.*;
23 import com.sun.j3d.utils.picking.*;
25 class WalkViewHandler
extends ViewHandler {
28 private static final float ROTATION_FACTOR = 0.02f;
29 private static final float TRANSLATION_FACTOR = 0.005f;
30 private static final float ZOOM_FACTOR = 0.0005f;
31 private static final float PAN_FACTOR = 0.0001f;
35 private Point3f pickPoint_;
36 private Point prevPoint_;
41 pickPoint_ =
new Point3f();
46 public void processPicking(MouseEvent evt, BehaviorInfo
info) {
47 prevPoint_ =
new Point(evt.getPoint());
49 info.pickCanvas.setShapeLocation(prevPoint_.x, prevPoint_.y);
51 PickResult pickResult = info.pickCanvas.pickClosest();
52 if (pickResult !=
null) {
53 Point3d startPoint = info.pickCanvas.getStartPosition();
55 pickResult.getClosestIntersection(startPoint);
56 pickPoint_ =
new Point3f(intersection.getPointCoordinatesVW());
58 }
catch (CapabilityNotSetException ex) {
63 public void processStartDrag(MouseEvent evt, BehaviorInfo info) {
64 if (mode_[getMouseButtonMode(evt)] == ZOOM_MODE) {
65 info.setTimerEnabled(
true);
66 System.out.println(
"timer start");
70 public void processDragOperation(MouseEvent evt, BehaviorInfo info) {
71 switch (mode_[getMouseButtonMode(evt)]) {
74 prevPoint_ =
new Point(evt.getPoint());
76 case TRANSLATION_MODE:
77 _translation(evt, info);
78 prevPoint_ =
new Point(evt.getPoint());
86 public void processReleased(MouseEvent evt, BehaviorInfo info) {}
88 public boolean processTimerOperation(BehaviorInfo info) {
89 Transform3D tr =
new Transform3D();
90 Transform3D trView =
new Transform3D();
91 TransformGroup tgView = info.drawable.getTransformGroupRoot();
92 tgView.getTransform(trView);
96 new Vector3f(0.0
f, 1.0
f, 0.0
f),
100 tr.setTranslation(
new Vector3f(0.0
f, 0.0
f, zoom_));
103 info.drawable.setTransform(trView);
109 private void _rotation(MouseEvent evt, BehaviorInfo info) {
111 ROTATION_FACTOR * (prevPoint_.getX() - evt.getPoint().getX());
113 ROTATION_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
116 TransformGroup tgView = info.drawable.getTransformGroupRoot();
117 Transform3D trView =
new Transform3D();
118 tgView.getTransform(trView);
121 Transform3D vw2view =
new Transform3D();
122 tgView.getLocalToVworld(vw2view);
127 Point3d pointTarget =
new Point3d(pickPoint_);
128 vw2view.transform(pointTarget);
131 Vector3d ray =
new Vector3d(pointTarget);
132 Transform3D trMove =
new Transform3D();
137 Transform3D tr =
new Transform3D();
138 Vector3d zAxis =
new Vector3d(0.0, 0.0, 1.0);
139 vw2view.transform(zAxis);
140 tr.set(
new AxisAngle4d(zAxis, dx));
143 Vector3d xAxis =
new Vector3d(1.0, 0.0, 0.0);
144 tr.set(
new AxisAngle4d(xAxis, dy));
148 trView.mulInverse(trMove);
150 info.drawable.setTransform(trView);
153 private void _translation(MouseEvent evt, BehaviorInfo info) {
156 (float)(evt.getPoint().getX() - prevPoint_.getX());
158 - TRANSLATION_FACTOR *
159 (float)(evt.getPoint().getY() - prevPoint_.getY());
161 Transform3D tr =
new Transform3D();
162 Transform3D trView =
new Transform3D();
163 TransformGroup tgView = info.drawable.getTransformGroupRoot();
164 tgView.getTransform(trView);
165 tr.set(
new Vector3f(fdx, fdy, 0.0
f));
167 info.drawable.setTransform(trView);
170 private void _zoom(MouseEvent evt, BehaviorInfo info) {
172 - PAN_FACTOR * (float)(evt.getPoint().getX() - prevPoint_.getX());
174 - ZOOM_FACTOR * (float)(evt.getPoint().getY() - prevPoint_.getY());
int intersection(const fLineVec &lv1, const fLineVec &lv2, fVec3 &c1, fVec3 &c2, double &d, double eps)
#define null
our own NULL pointer