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.behavior.mouse;
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 java.awt.*;
27 import java.awt.event.*;
28 import java.util.*;
29 import javax.media.j3d.*;
30 import javax.vecmath.*;
31
32
33
34
35 /***
36 * MouseRotate is a behavior object which rotates a 3D object
37 * according to a mouse event.
38 *
39 * @version $Revision: 1.3 $
40 * @author Masahiro Takatsuka (masa@jbeans.net)
41 * @see com.sun.j3d.utils.behaviors.mouse.MouseRotate
42 */
43
44 public class MouseRotate extends com.sun.j3d.utils.behaviors.mouse.MouseRotate {
45 private double x_angle;
46 private double y_angle;
47 private double x_factor;
48 private double y_factor;
49 private com.sun.j3d.utils.behaviors.mouse.MouseBehaviorCallback callback;
50 private boolean useL2U;
51 private boolean invertMouseInput;
52
53 public MouseRotate() {
54 super(0);
55 this.x_factor = 0.029999999999999999D;
56 this.y_factor = 0.029999999999999999D;
57 this.callback = null;
58 this.useL2U = false;
59 this.invertMouseInput = false;
60 }
61
62 public MouseRotate(int i) {
63 super(i);
64 this.x_factor = 0.029999999999999999D;
65 this.y_factor = 0.029999999999999999D;
66 this.callback = null;
67 this.useL2U = false;
68 this.invertMouseInput = false;
69 }
70
71 public MouseRotate(TransformGroup transformgroup) {
72 super(transformgroup);
73 this.x_factor = 0.029999999999999999D;
74 this.y_factor = 0.029999999999999999D;
75 this.callback = null;
76 this.useL2U = false;
77 this.invertMouseInput = false;
78 }
79
80 public void invertMouseInput(boolean invert) {
81 this.invertMouseInput = invert;
82 }
83
84 public boolean doesInvertMouseInput() {
85 return this.invertMouseInput;
86 }
87
88 public void setTransformGroup(TransformGroup transformgroup) {
89 super.setTransformGroup(transformgroup);
90 this.useL2U = false;
91 }
92
93 public void useLocalToUniverseTransform(boolean use) {
94 this.useL2U = false;
95 }
96
97 public boolean isLocalToUniverseTransformUsed() {
98 return this.useL2U;
99 }
100
101 public double getXFactor() {
102 return this.x_factor;
103 }
104
105 public double getYFactor() {
106 return this.y_factor;
107 }
108
109 public void initialize() {
110 super.initialize();
111 this.x_angle = 0.0D;
112 this.y_angle = 0.0D;
113 if ((flags & 0x2) == com.sun.j3d.utils.behaviors.mouse.MouseBehavior.INVERT_INPUT) {
114 invert = true;
115 this.x_factor *= -1D;
116 this.y_factor *= -1D;
117 }
118 }
119
120 public void processStimulus(Enumeration enumeration) {
121 while (enumeration.hasMoreElements()) {
122 WakeupCriterion wakeupcriterion = (WakeupCriterion)enumeration.nextElement();
123 if (wakeupcriterion instanceof WakeupOnAWTEvent) {
124 AWTEvent aawtevent[] = ((WakeupOnAWTEvent)wakeupcriterion).getAWTEvent();
125 for (int l = 0; l < aawtevent.length; l++) {
126 processMouseEvent((MouseEvent)aawtevent[l]);
127 if (buttonPress && (flags & 0x1) == 0 || wakeUp && (flags & 0x1) != 0) {
128 int i = aawtevent[l].getID();
129 if (i == MouseEvent.MOUSE_DRAGGED && !((MouseEvent)aawtevent[l]).isMetaDown() && !((MouseEvent)aawtevent[l]).isAltDown()) {
130 x = ((MouseEvent)aawtevent[l]).getX();
131 y = ((MouseEvent)aawtevent[l]).getY();
132 int j = x - x_last;
133 int k = y - y_last;
134 if (this.invertMouseInput) {
135 j = -j;
136 k = -k;
137 }
138 if (!reset) {
139 this.x_angle = (double)k * this.y_factor;
140 this.y_angle = (double)j * this.x_factor;
141 transformX.rotX(this.x_angle);
142 transformY.rotY(this.y_angle);
143 transformGroup.getTransform(currXform);
144 Matrix4d matrix4d = new Matrix4d();
145 currXform.get(matrix4d);
146 currXform.setTranslation(new Vector3d(0.0D, 0.0D, 0.0D));
147 if (invert) {
148 currXform.mul(currXform, transformX);
149 currXform.mul(currXform, transformY);
150 } else {
151 currXform.mul(transformX, currXform);
152 currXform.mul(transformY, currXform);
153 }
154 Vector3d vector3d = new Vector3d(matrix4d.m03, matrix4d.m13, matrix4d.m23);
155 currXform.setTranslation(vector3d);
156 transformGroup.setTransform(currXform);
157 transformChanged(currXform);
158 if (this.callback != null) {
159 this.callback.transformChanged(1, currXform);
160 }
161 } else {
162 reset = false;
163 }
164 x_last = x;
165 y_last = y;
166 } else if (i == MouseEvent.MOUSE_PRESSED) {
167 x_last = ((MouseEvent)aawtevent[l]).getX();
168 y_last = ((MouseEvent)aawtevent[l]).getY();
169 }
170 }
171 }
172 }
173 }
174
175 wakeupOn(mouseCriterion);
176 }
177
178 public void setFactor(double d) {
179 this.x_factor = this.y_factor = d;
180 }
181
182 public void setFactor(double d, double d1) {
183 this.x_factor = d;
184 this.y_factor = d1;
185 }
186
187 public void setupCallback(com.sun.j3d.utils.behaviors.mouse.MouseBehaviorCallback mousebehaviorcallback) {
188 this.callback = mousebehaviorcallback;
189 }
190
191 public void transformChanged(Transform3D transform3d) {
192 }
193 }