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 Rotate in here
34 *
35 * @version $Revision: 1.3 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see Manipulator
38 */
39
40 public class Rotate extends Manipulator {
41 private Transform3D transformX;
42 private Transform3D transformY;
43 private double x_angle;
44 private double y_angle;
45 private double x_factor;
46 private double y_factor;
47 private AxisAngle4d aa4d;
48 private Vector3d axis;
49 private Vector3d x_axis;
50 private Vector3d y_axis;
51 private Vector3d tmpTrans;
52
53 public Rotate() {
54 super(false);
55 this.x_factor = 0.03D;
56 this.y_factor = 0.03D;
57 }
58
59 public Rotate(boolean invert) {
60 super(invert);
61 this.x_factor = 0.03D;
62 this.y_factor = 0.03D;
63 }
64
65 public Rotate(TransformGroup transformgroup) {
66 super(transformgroup);
67 this.x_factor = 0.03D;
68 this.y_factor = 0.03D;
69 }
70
71 public double getXFactor() {
72 return this.x_factor;
73 }
74
75 public double getYFactor() {
76 return this.y_factor;
77 }
78
79 public void initialize() {
80 super.initialize();
81 this.x_angle = 0.0D;
82 this.y_angle = 0.0D;
83 if (this.invert) {
84 this.x_factor *= -1D;
85 this.y_factor *= -1D;
86 }
87 this.aa4d = new AxisAngle4d();
88 this.axis = new Vector3d(1, 0, 0);
89 this.x_axis = new Vector3d();
90 this.y_axis = new Vector3d();
91 this.tmpTrans = new Vector3d();
92 this.transformX = new Transform3D();
93 this.transformY = new Transform3D();
94 }
95
96 public void processStimulus(Stimulus stimulus) {
97 super.processStimulus(stimulus);
98 int j = stimulus.getX() - stimulus.getLastX();
99 int k = stimulus.getY() - stimulus.getLastY();
100 if (this.invert) {
101 j = -j;
102 k = -k;
103 }
104 if (!this.reset) {
105 this.x_angle = (double)k * this.y_factor;
106 this.y_angle = (double)j * this.x_factor;
107 if (this.useL2U) {
108 this.axis.set(1, 0, 0);
109 this.l2u.transform(this.axis, this.x_axis);
110 this.axis.set(0, 1, 0);
111 this.l2u.transform(this.axis, this.y_axis);
112 } else {
113 this.axis.set(1, 0, 0);
114 this.x_axis.set(this.axis);
115 this.axis.set(0, 1, 0);
116 this.y_axis.set(this.axis);
117 }
118 this.aa4d.set(this.x_axis, this.x_angle);
119 this.transformX.set(this.aa4d);
120 this.aa4d.set(this.y_axis, this.y_angle);
121 this.transformY.set(this.aa4d);
122 this.transformGroup.getTransform(this.currXform);
123 Matrix4d matrix4d = new Matrix4d();
124 this.currXform.get(matrix4d);
125 this.tmpTrans.set(matrix4d.m03 - this.localcenter.x,
126 matrix4d.m13 - this.localcenter.y,
127 matrix4d.m23 - this.localcenter.z);
128 this.currXform.setTranslation(this.tmpTrans);
129 if (this.invert) {
130 this.currXform.mul(this.currXform, this.transformX);
131 this.currXform.mul(this.currXform, this.transformY);
132 } else {
133 this.currXform.mul(this.transformX, this.currXform);
134 this.currXform.mul(this.transformY, this.currXform);
135 }
136 this.currXform.get(matrix4d);
137 this.tmpTrans.set(matrix4d.m03 + this.localcenter.x,
138 matrix4d.m13 + this.localcenter.y,
139 matrix4d.m23 + this.localcenter.z);
140 this.currXform.setTranslation(this.tmpTrans);
141 this.transformGroup.setTransform(this.currXform);
142 transformChanged(this.currXform);
143 if (this.callback != null) {
144 this.callback.transformChanged(ManipulatorCallback.ROTATE,
145 this.currXform,
146 null);
147 }
148 } else {
149 this.reset = false;
150 }
151 }
152
153 public void setFactor(double d) {
154 this.x_factor = this.y_factor = d;
155 }
156
157 public void setFactor(double d, double d1) {
158 this.x_factor = d;
159 this.y_factor = d1;
160 }
161
162 public void transformChanged(Transform3D transform3d) {
163 }
164 }