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 Roll in here
34 *
35 * @version $Revision: 1.3 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see Manipulator
38 */
39
40 public class Roll extends Manipulator {
41 private Transform3D transformZ;
42 private double z_angle;
43 private Vector2d vec_zero;
44 private Vector2d vec;
45 private Vector2d vec_last;
46 private AxisAngle4d aa4d;
47 private Vector3d axis;
48 private Vector3d z_axis;
49 private Vector3d tmpTrans;
50
51 public Roll() {
52 super(false);
53 }
54
55 public Roll(boolean invert) {
56 super(invert);
57 }
58
59 public Roll(TransformGroup transformgroup) {
60 super(transformgroup);
61 }
62
63 public void initialize() {
64 super.initialize();
65 this.z_angle = 0.0D;
66 this.vec_zero = new Vector2d(1, 0);
67 this.vec = new Vector2d();
68 this.vec_last = new Vector2d();
69 this.aa4d = new AxisAngle4d();
70 this.axis = new Vector3d(0, 0, 1);
71 this.z_axis = new Vector3d();
72 this.tmpTrans = new Vector3d();
73 this.transformZ = new Transform3D();
74 }
75
76 public void processStimulus(Stimulus stimulus) {
77 super.processStimulus(stimulus);
78 int x = stimulus.getX();
79 int x_last = stimulus.getLastX();
80 int x_center = stimulus.getCenterX();
81 int y = stimulus.getY();
82 int y_last = stimulus.getLastY();
83 int y_center = stimulus.getCenterY();
84 this.vec.x = x - x_center;
85 this.vec.y = y - y_center;
86 this.vec_last.x = x_last - x_center;
87 this.vec_last.y = y_last - y_center;
88 this.vec.normalize();
89 this.vec_last.normalize();
90 this.z_angle = Math.acos(this.vec.dot(this.vec_zero)) -
91 Math.acos(this.vec_last.dot(this.vec_zero));
92 if (y - y_center > 0 || this.invert) {
93 this.z_angle = -this.z_angle;
94 }
95 if (!this.reset) {
96 if (this.useL2U) {
97 this.l2u.transform(this.axis, this.z_axis);
98 } else {
99 this.z_axis.set(this.axis);
100 }
101 this.aa4d.set(this.z_axis, this.z_angle);
102 this.transformZ.set(this.aa4d);
103 this.transformGroup.getTransform(this.currXform);
104 Matrix4d matrix4d = new Matrix4d();
105 this.currXform.get(matrix4d);
106 this.tmpTrans.set(matrix4d.m03 - this.localcenter.x,
107 matrix4d.m13 - this.localcenter.y,
108 matrix4d.m23 - this.localcenter.z);
109 this.currXform.setTranslation(this.tmpTrans);
110 if (this.invert) {
111 this.currXform.mul(this.currXform, this.transformZ);
112 } else {
113 this.currXform.mul(this.transformZ, this.currXform);
114 }
115 this.currXform.get(matrix4d);
116 this.tmpTrans.set(matrix4d.m03 + this.localcenter.x,
117 matrix4d.m13 + this.localcenter.y,
118 matrix4d.m23 + this.localcenter.z);
119 this.currXform.setTranslation(this.tmpTrans);
120 this.transformGroup.setTransform(this.currXform);
121 transformChanged(this.currXform);
122 if (this.callback != null) {
123 this.callback.transformChanged(ManipulatorCallback.ROLL,
124 this.currXform,
125 null);
126 }
127 } else {
128 this.reset = false;
129 }
130 }
131
132 public void transformChanged(Transform3D transform3d) {
133 }
134 }