WalkViewHandler.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 WalkViewHandler 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.0005f;
31  private static final float PAN_FACTOR = 0.0001f;
32 
33  //--------------------------------------------------------------------
34  // インスタンス変数
35  private Point3f pickPoint_;
36  private Point prevPoint_;
37  private float zoom_;
38  private float pan_;
39 
40  WalkViewHandler() {
41  pickPoint_ = new Point3f();
42  }
43 
44  //--------------------------------------------------------------------
45  // BehaviorHandlerの実装
46  public void processPicking(MouseEvent evt, BehaviorInfo info) {
47  prevPoint_ = new Point(evt.getPoint());
48 
49  info.pickCanvas.setShapeLocation(prevPoint_.x, prevPoint_.y);
50  try {
51  PickResult pickResult = info.pickCanvas.pickClosest();
52  if (pickResult != null) {
53  Point3d startPoint = info.pickCanvas.getStartPosition();
54  PickIntersection intersection =
55  pickResult.getClosestIntersection(startPoint);
56  pickPoint_ = new Point3f(intersection.getPointCoordinatesVW());
57  }
58  } catch (CapabilityNotSetException ex) {
59  return;
60  }
61  }
62 
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");
67  }
68  }
69 
70  public void processDragOperation(MouseEvent evt, BehaviorInfo info) {
71  switch (mode_[getMouseButtonMode(evt)]) {
72  case ROTATION_MODE:
73  _rotation(evt, info);
74  prevPoint_ = new Point(evt.getPoint());
75  break;
76  case TRANSLATION_MODE:
77  _translation(evt, info);
78  prevPoint_ = new Point(evt.getPoint());
79  break;
80  case ZOOM_MODE:
81  _zoom(evt, info);
82  break;
83  }
84  }
85 
86  public void processReleased(MouseEvent evt, BehaviorInfo info) {}
87 
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);
93 
94  tr.setRotation(
95  new AxisAngle4f(
96  new Vector3f(0.0f, 1.0f, 0.0f),
97  pan_
98  )
99  );
100  tr.setTranslation(new Vector3f(0.0f, 0.0f, zoom_));
101 
102  trView.mul(tr);
103  info.drawable.setTransform(trView);
104  return true;
105  }
106 
107  //--------------------------------------------------------------------
108  // プライベートメソッド
109  private void _rotation(MouseEvent evt, BehaviorInfo info) {
110  double dx =
111  ROTATION_FACTOR * (prevPoint_.getX() - evt.getPoint().getX());
112  double dy =
113  ROTATION_FACTOR * (prevPoint_.getY() - evt.getPoint().getY());
114 
115  // グローバル座標から視点座標への変換をもとめる。
116  TransformGroup tgView = info.drawable.getTransformGroupRoot();
117  Transform3D trView = new Transform3D(); // 視点の変換
118  tgView.getTransform(trView);
119 
120  // グローバル座標系から視点座標系への変換
121  Transform3D vw2view = new Transform3D();
122  tgView.getLocalToVworld(vw2view);
123  vw2view.mul(trView);
124  vw2view.invert();
125 
126  // 視点から見たターゲットポイント
127  Point3d pointTarget = new Point3d(pickPoint_);
128  vw2view.transform(pointTarget);
129 
130  // 視点座標系をターゲットポイントまで移動
131  Vector3d ray = new Vector3d(pointTarget); // 視線ベクトル
132  Transform3D trMove = new Transform3D();
133  trMove.set(ray);
134  trView.mul(trMove);
135 
136  // 視点座標系を回転
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));
141  trView.mul(tr);
142 
143  Vector3d xAxis = new Vector3d(1.0, 0.0, 0.0);
144  tr.set(new AxisAngle4d(xAxis, dy));
145  trView.mul(tr);
146 
147  // 視点座標系をターゲットポイントから離す
148  trView.mulInverse(trMove);
149 
150  info.drawable.setTransform(trView);
151  }
152 
153  private void _translation(MouseEvent evt, BehaviorInfo info) {
154  float fdx =
155  TRANSLATION_FACTOR *
156  (float)(evt.getPoint().getX() - prevPoint_.getX());
157  float fdy =
158  - TRANSLATION_FACTOR *
159  (float)(evt.getPoint().getY() - prevPoint_.getY());
160 
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.0f));
166  trView.mul(tr);
167  info.drawable.setTransform(trView);
168  }
169 
170  private void _zoom(MouseEvent evt, BehaviorInfo info) {
171  pan_ =
172  - PAN_FACTOR * (float)(evt.getPoint().getX() - prevPoint_.getX());
173  zoom_ =
174  - ZOOM_FACTOR * (float)(evt.getPoint().getY() - prevPoint_.getY());
175  }
176 }
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:26