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.transform;
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.event.*;
27 import java.beans.*;
28 import java.io.*;
29 import java.util.*;
30 import javax.swing.event.*;
31
32 import javax.media.j3d.Node;
33 import javax.media.j3d.Transform3D;
34 import javax.vecmath.*;
35 import com.sun.j3d.utils.behaviors.mouse.*;
36
37 import net.jbeans.j3d.event.*;
38 import net.jbeans.j3d.util.*;
39 import net.jbeans.j3d.vecmath.*;
40 import net.jbeans.util.debug.*;
41
42
43
44
45 /***
46 * generally describe TransformGroup in here
47 *
48 * @version $Revision: 1.3 $
49 * @author Masahiro Takatsuka (masa@jbeans.net)
50 * @see ResettableTransformGroup
51 * @see Serializable
52 */
53
54 public class TransformGroup extends ResettableTransformGroup implements Serializable {
55 private static final boolean DEBUG = Debug.getDebugFlag(TransformGroup.class);
56
57
58 transient private EventListenerList listenerList = new EventListenerList();
59 transient private EventObject myEvent = new EventObject(this);
60 transient private Transform3D tmp = new Transform3D();
61
62
63 private Vector3d translation;
64 private Vector3d scale;
65 private double rotXAngle;
66 private double rotYAngle;
67 private double rotZAngle;
68
69 public TransformGroup() {
70 this(new Transform3D());
71 }
72
73 public TransformGroup(Transform3D transform3d) {
74 super(transform3d);
75
76
77
78 this.translation = new Vector3d();
79 this.scale = new Vector3d(1.0, 1.0, 1.0);
80 this.rotXAngle = 0.0;
81 this.rotYAngle = 0.0;
82 this.rotZAngle = 0.0;
83 }
84
85 public Vector3d getTranslation() {
86 if (DEBUG) {
87 System.out.println("getTranslation(" + this + "): " + this.translation);
88 }
89 return this.translation;
90 }
91
92 public void setTranslation(Vector3d trans) {
93 setTranslation(trans.x, trans.y, trans.z);
94 }
95
96 public void setTranslation(double tx, double ty, double tz) {
97 this.translation.set(tx, ty, tz);
98 if (DEBUG) {
99 System.out.println("setTranslation(" + this + "): " + this.translation);
100 }
101 get(this.tmp);
102 this.tmp.setIdentity();
103 this.tmp.setTranslation(this.translation);
104 set(this.tmp);
105 }
106
107 public Vector3d getScale() {
108 if (DEBUG) {
109 System.out.println("getScale(" + this + "): " + this.scale);
110 }
111 return this.scale;
112 }
113
114 public void setScale(Vector3d scale) {
115 setScale(scale.x, scale.y, scale.z);
116 }
117
118 public void setScale(double scale) {
119 setScale(scale, scale, scale);
120 }
121
122 public void setScale(double sx, double sy, double sz) {
123 this.scale.set(sx, sy, sz);
124 if (DEBUG) {
125 System.out.println("setScale(" + this + "): " + this.scale);
126 }
127 get(this.tmp);
128 this.tmp.setIdentity();
129 this.tmp.setScale(this.scale);
130 set(this.tmp);
131 }
132
133 public double getRotXAngle() {
134 if (DEBUG) {
135 System.out.println("getRotXAngle(" + this + "): " + this.rotXAngle);
136 }
137 return this.rotXAngle;
138 }
139
140 public void setRotXAngle(double angle) {
141 this.rotXAngle = angle;
142 if (DEBUG) {
143 System.out.println("setRotXAngle(" + this + "): " + this.rotXAngle);
144 }
145 get(this.tmp);
146 this.tmp.setIdentity();
147 this.tmp.rotX(this.rotXAngle);
148 set(this.tmp);
149 }
150
151 public double getRotYAngle() {
152 return this.rotYAngle;
153 }
154
155 public void setRotYAngle(double angle) {
156 this.rotYAngle = angle;
157 get(this.tmp);
158 this.tmp.setIdentity();
159 this.tmp.rotY(this.rotYAngle);
160 set(this.tmp);
161 }
162
163 public double getRotZAngle() {
164 return this.rotZAngle;
165 }
166
167 public void setRotZAngle(double angle) {
168 this.rotZAngle = angle;
169 get(this.tmp);
170 this.tmp.setIdentity();
171 this.tmp.rotZ(this.rotZAngle);
172 set(this.tmp);
173 }
174
175 /***
176 * in order to call this method the top BranchGroup object needs to be
177 * detached.
178 */
179 public void removeChild(Node child) {
180
181
182
183
184 int allCnt = numChildren();
185 int i = -1;
186 for (i = 0; i < allCnt; i++) {
187 if (child.equals(getChild(i))) {
188
189 try {
190 removeChild(i);
191 } catch (javax.media.j3d.RestrictedAccessException e) {
192 System.out.println("The top BranchGroup object needs to be detached in order to call this method.");
193 if (DEBUG) {
194 e.printStackTrace();
195 }
196 }
197 return;
198 }
199 }
200 }
201
202 /***
203 * adds an SceneGraphObjectListener to the shape
204 */
205 public void addSceneGraphObjectListener(SceneGraphObjectListener l) {
206 this.listenerList.add(SceneGraphObjectListener.class, l);
207 }
208
209 /***
210 * removes an GeometryListener from the shape.
211 */
212 public void removeSceneGraphObjectListener(SceneGraphObjectListener l) {
213 this.listenerList.remove(SceneGraphObjectListener.class, l);
214 }
215
216 /***
217 * Notify all listeners that have registered interest for
218 * notification on this event type.
219 */
220 public void fireSceneGraphObjectChanged() {
221 Object[] listeners = this.listenerList.getListenerList();
222
223
224 for (int i = listeners.length - 2; i >= 0; i -= 2) {
225 if (listeners[i] == SceneGraphObjectListener.class) {
226
227 ((SceneGraphObjectListener)listeners[i+1]).objectChanged(this.myEvent);
228 }
229 }
230 }
231 }