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
29
30
31
32 /***
33 * generally describe Translate in here
34 *
35 * @version $Revision: 1.3 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see Manipulator
38 */
39
40 public class Translate extends Manipulator {
41 private Transform3D transformT;
42 private double x_factor;
43 private double y_factor;
44 private Vector3d translation;
45 private BoundingSphere tmpBounds = new BoundingSphere();
46
47 public Translate() {
48 super(false);
49 this.x_factor = 0.02D;
50 this.y_factor = 0.02D;
51 }
52
53 public Translate(boolean invert) {
54 super(invert);
55 this.x_factor = 0.02D;
56 this.y_factor = 0.02D;
57 }
58
59 public Translate(TransformGroup transformgroup) {
60 super(transformgroup);
61 this.x_factor = 0.02D;
62 this.y_factor = 0.02D;
63 }
64
65 public double getXFactor() {
66 return this.x_factor;
67 }
68
69 public double getYFactor() {
70 return this.y_factor;
71 }
72
73 public void initialize() {
74 super.initialize();
75 if (this.invert) {
76 this.x_factor *= -1D;
77 this.y_factor *= -1D;
78 }
79 this.translation = new Vector3d();
80 this.transformT = new Transform3D();
81 }
82
83 public void processStimulus(Stimulus stimulus) {
84 super.processStimulus(stimulus);
85
86
87 tmpBounds.set(this.transformGroup.getBounds());
88 double diameter = tmpBounds.getRadius() * 2;
89
90 int j = stimulus.getX() - stimulus.getLastX();
91 int k = stimulus.getY() - stimulus.getLastY();
92 if (this.invert) {
93 j = -j;
94 k = -k;
95 }
96 if (!this.reset && Math.abs(k) < 50 && Math.abs(j) < 50) {
97 this.transformGroup.getTransform(this.currXform);
98 this.translation.x = (double)j * this.x_factor * diameter;
99 this.translation.y = (double)(-k) * this.y_factor * diameter;
100 this.translation.z = 0;
101 if (this.useL2U) {
102 this.l2u.transform(this.translation);
103 }
104 this.transformT.set(this.translation);
105 if (this.invert) {
106 this.currXform.mul(this.currXform, this.transformT);
107 } else {
108 this.currXform.mul(this.transformT, this.currXform);
109 }
110 this.transformGroup.setTransform(this.currXform);
111 this.transformChanged(this.currXform);
112 if (this.callback != null) {
113 this.callback.transformChanged(ManipulatorCallback.TRANSLATE,
114 this.currXform,
115 null);
116 }
117 } else {
118 this.reset = false;
119 }
120 }
121
122 public void setFactor(double d) {
123 this.x_factor = this.y_factor = d;
124 }
125
126 public void setFactor(double d, double d1) {
127 this.x_factor = d;
128 this.y_factor = d1;
129 }
130
131 public void transformChanged(Transform3D transform3d) {
132 }
133 }