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 RoomViewHandler
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.02f;
34 private Point3f pickPoint_;
35 private Point prevPoint_;
36 private boolean parallelMode_;
43 pickPoint_ =
new Point3f();
48 public void setParallelMode(
boolean mode) {
54 public void processPicking(MouseEvent evt, BehaviorInfo
info) {
55 prevPoint_ =
new Point(evt.getPoint());
57 info.pickCanvas.setShapeLocation(prevPoint_.x, prevPoint_.y);
59 PickResult pickResult = info.pickCanvas.pickClosest();
60 if (pickResult !=
null) {
61 Point3d startPoint = info.pickCanvas.getStartPosition();
63 pickResult.getClosestIntersection(startPoint);
64 pickPoint_ =
new Point3f(intersection.getPointCoordinatesVW());
66 }
catch (CapabilityNotSetException ex) {
71 public void processDragOperation(MouseEvent evt, BehaviorInfo info) {
72 switch (mode_[getMouseButtonMode(evt)]) {
78 case TRANSLATION_MODE:
79 _translation(evt, info);
86 prevPoint_ =
new Point(evt.getPoint());
89 public void processStartDrag(MouseEvent evt, BehaviorInfo info) {}
90 public void processReleased(MouseEvent evt, BehaviorInfo info) {}
91 public boolean processTimerOperation(BehaviorInfo info) {
97 private void _rotation(MouseEvent evt, BehaviorInfo info) {
98 double dx = ROTATION_FACTOR * (prevPoint_.getX() - evt.getPoint().getX());
99 double dy = ROTATION_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
102 TransformGroup tgView = info.drawable.getTransformGroupRoot();
103 Transform3D trView =
new Transform3D();
104 tgView.getTransform(trView);
107 Transform3D vw2view =
new Transform3D();
108 tgView.getLocalToVworld(vw2view);
113 Point3d pointTarget =
new Point3d(pickPoint_);
114 vw2view.transform(pointTarget);
117 Vector3d ray =
new Vector3d(pointTarget);
118 Transform3D trMove =
new Transform3D();
123 Transform3D tr =
new Transform3D();
124 Vector3d zAxis =
new Vector3d(0.0, 0.0, 1.0);
125 vw2view.transform(zAxis);
126 tr.set(
new AxisAngle4d(zAxis, dx));
129 Vector3d xAxis =
new Vector3d(1.0, 0.0, 0.0);
130 tr.set(
new AxisAngle4d(xAxis, dy));
134 trView.mulInverse(trMove);
136 info.drawable.setTransform(trView);
139 private void _translation(MouseEvent evt, BehaviorInfo info) {
140 double dx = TRANSLATION_FACTOR * (prevPoint_.getX() - evt.getPoint().getX());
141 double dy = TRANSLATION_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
143 Transform3D tr =
new Transform3D();
144 Transform3D trView =
new Transform3D();
145 TransformGroup tgView = info.drawable.getTransformGroupRoot();
146 tgView.getTransform(trView);
147 tr.set(
new Vector3d(dx, -dy, 0.0
f));
149 info.drawable.setTransform(trView);
152 private void _zoom(MouseEvent evt, BehaviorInfo info) {
154 View v = info.drawable.getView();
155 double s = v.getScreenScale()-ZOOM_FACTOR*0.05*(prevPoint_.getY() - evt.getPoint().getY());
156 if (s > 0) v.setScreenScale(s);
158 double dy = - ZOOM_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
160 Transform3D tr =
new Transform3D();
161 Transform3D trView =
new Transform3D();
163 TransformGroup tgView = info.drawable.getTransformGroupRoot();
164 tgView.getTransform(trView);
165 tr.set(
new Vector3d(0.0
f, 0.0
f, -dy));
167 info.drawable.setTransform(trView);
int intersection(const fLineVec &lv1, const fLineVec &lv2, fVec3 &c1, fVec3 &c2, double &d, double eps)
#define null
our own NULL pointer