1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.util.manipulator;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import javax.media.j3d.*;
27 import javax.vecmath.*;
28 import com.sun.j3d.utils.picking.*;
29
30 import net.jbeans.j3d.universe.*;
31
32
33
34
35 /***
36 * generally describe Seek in here
37 *
38 * @version $Revision: 1.3 $
39 * @author Masahiro Takatsuka (masa@jbeans.net)
40 * @see Manipulator
41 */
42
43 public class Seek extends Manipulator {
44 private ViewingPlatform viewingplatform = null;
45 private PickCanvas pickCanvas = null;
46
47 public Seek() {
48 super(false);
49 }
50
51 public Seek(boolean invert) {
52 super(invert);
53 }
54
55 public Seek(TransformGroup transformgroup) {
56 super(transformgroup);
57 }
58
59 public void initialize() {
60 super.initialize();
61 }
62
63 public void initForSeek(Canvas3D canvas3d, BranchGroup branchgroup, ViewingPlatform viewingplatform) {
64 this.pickCanvas = new PickCanvas(canvas3d, branchgroup);
65 this.pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
66
67 this.viewingplatform = viewingplatform;
68 }
69
70 private Vector4d tmpcenter;
71 public void processStimulus(Stimulus stimulus) {
72 int i = stimulus.getX();
73 int j = stimulus.getY();
74 this.pickCanvas.setShapeLocation(i, j);
75 PickResult result = this.pickCanvas.pickClosest();
76 if (result == null) {
77 return;
78 }
79 Point3d eye = this.viewingplatform.getEyePosition();
80 Vector3d up = this.viewingplatform.getUpPosition();
81 PickIntersection intersection = result.getClosestIntersection(eye);
82 Point3d seekPoint = intersection.getPointCoordinatesVW();
83 if (seekPoint != null) {
84 this.currXform.lookAt(eye, seekPoint, up);
85 this.currXform.invert();
86 this.transformGroup.setTransform(this.currXform);
87 this.transformChanged(this.currXform);
88 if (this.callback != null) {
89 this.callback.transformChanged(ManipulatorCallback.SEEK,
90 this.currXform,
91 seekPoint);
92 }
93 }
94 }
95
96 public void transformChanged(Transform3D transform3d) {
97 }
98 }