RoomViewHandler.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.view.tdview;
18 
19 import java.awt.*;
20 import java.awt.event.*;
21 import javax.media.j3d.*;
22 import javax.vecmath.*;
23 import com.sun.j3d.utils.picking.*;
24 
25 class RoomViewHandler extends ViewHandler {
26  //--------------------------------------------------------------------
27  // 定数
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;
31 
32  //--------------------------------------------------------------------
33  // インスタンス変数
34  private Point3f pickPoint_;
35  private Point prevPoint_;
36  private boolean parallelMode_;
37  //private double x_angle;
38  //private double y_angle;
39 
40  //--------------------------------------------------------------------
41  // コンストラクタ
42  RoomViewHandler() {
43  pickPoint_ = new Point3f();
44  }
45 
46  //--------------------------------------------------------------------
47  // 公開メソッド
48  public void setParallelMode(boolean mode) {
49  parallelMode_ = mode;
50  }
51 
52  //--------------------------------------------------------------------
53  // BehaviorHandlerの実装
54  public void processPicking(MouseEvent evt, BehaviorInfo info) {
55  prevPoint_ = new Point(evt.getPoint());
56 
57  info.pickCanvas.setShapeLocation(prevPoint_.x, prevPoint_.y);
58  try {
59  PickResult pickResult = info.pickCanvas.pickClosest();
60  if (pickResult != null) {
61  Point3d startPoint = info.pickCanvas.getStartPosition();
62  PickIntersection intersection =
63  pickResult.getClosestIntersection(startPoint);
64  pickPoint_ = new Point3f(intersection.getPointCoordinatesVW());
65  }
66  } catch (CapabilityNotSetException ex) {
67  return;
68  }
69  }
70 
71  public void processDragOperation(MouseEvent evt, BehaviorInfo info) {
72  switch (mode_[getMouseButtonMode(evt)]) {
73  case ROTATION_MODE:
74  if (!parallelMode_) {
75  _rotation(evt, info);
76  }
77  break;
78  case TRANSLATION_MODE:
79  _translation(evt, info);
80  break;
81  case ZOOM_MODE:
82  _zoom(evt, info);
83  break;
84  }
85 
86  prevPoint_ = new Point(evt.getPoint());
87  }
88 
89  public void processStartDrag(MouseEvent evt, BehaviorInfo info) {}
90  public void processReleased(MouseEvent evt, BehaviorInfo info) {}
91  public boolean processTimerOperation(BehaviorInfo info) {
92  return true;
93  }
94 
95  //--------------------------------------------------------------------
96  // プライベートメソッド
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());
100 
101  // グローバル座標から視点座標への変換をもとめる。
102  TransformGroup tgView = info.drawable.getTransformGroupRoot();
103  Transform3D trView = new Transform3D(); // 視点の変換
104  tgView.getTransform(trView);
105 
106  // グローバル座標系から視点座標系への変換
107  Transform3D vw2view = new Transform3D();
108  tgView.getLocalToVworld(vw2view);
109  vw2view.mul(trView);
110  vw2view.invert();
111 
112  // 視点から見たターゲットポイント
113  Point3d pointTarget = new Point3d(pickPoint_);
114  vw2view.transform(pointTarget);
115 
116  // 視点座標系をターゲットポイントまで移動
117  Vector3d ray = new Vector3d(pointTarget); // 視線ベクトル
118  Transform3D trMove = new Transform3D();
119  trMove.set(ray);
120  trView.mul(trMove);
121 
122  // 視点座標系を回転
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));
127  trView.mul(tr);
128 
129  Vector3d xAxis = new Vector3d(1.0, 0.0, 0.0);
130  tr.set(new AxisAngle4d(xAxis, dy));
131  trView.mul(tr);
132 
133  // 視点座標系をターゲットポイントから離す
134  trView.mulInverse(trMove);
135 
136  info.drawable.setTransform(trView);
137  }
138 
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());
142 
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.0f));
148  trView.mul(tr);
149  info.drawable.setTransform(trView);
150  }
151 
152  private void _zoom(MouseEvent evt, BehaviorInfo info) {
153  if (parallelMode_){
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);
157  }else{
158  double dy = - ZOOM_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
159 
160  Transform3D tr = new Transform3D();
161  Transform3D trView = new Transform3D();
162 
163  TransformGroup tgView = info.drawable.getTransformGroupRoot();
164  tgView.getTransform(trView);
165  tr.set(new Vector3d(0.0f, 0.0f, -dy));
166  trView.mul(tr);
167  info.drawable.setTransform(trView);
168  }
169  }
170 }
int intersection(const fLineVec &lv1, const fLineVec &lv2, fVec3 &c1, fVec3 &c2, double &d, double eps)
Definition: fLineVec.cpp:36
#define null
our own NULL pointer
Definition: IceTypes.h:57
backing_store_ptr info
Definition: jmemsys.h:181


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:25