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 java.util.*;
27 import javax.media.j3d.*;
28 import javax.vecmath.*;
29
30
31
32
33 /***
34 * generally describe Scale in here
35 *
36 * @version $Revision: 1.3 $
37 * @author Masahiro Takatsuka (masa@jbeans.net)
38 * @see Manipulator
39 */
40
41 public class Scale extends Manipulator {
42 private Transform3D transformS;
43 private double s_factor;
44 private double scale;
45 private BoundingSphere tmpBounds = new BoundingSphere();
46
47 public Scale() {
48 super(false);
49 this.s_factor = 0.02D;
50 this.scale = 1;
51 }
52
53 public Scale(boolean invert) {
54 super(invert);
55 this.s_factor = 0.02D;
56 this.scale = 1;
57 }
58
59 public Scale(TransformGroup transformgroup) {
60 super(transformgroup);
61 this.s_factor = 0.02D;
62 this.scale = 1;
63 }
64
65 public void setScale(double d) {
66 this.s_factor = d;
67 }
68
69 public double getScale() {
70 return this.s_factor;
71 }
72
73 public void initialize() {
74 super.initialize();
75 if (this.invert) {
76 this.s_factor *= -1D;
77 }
78 this.transformS = new Transform3D();
79 }
80
81 public void processStimulus(Stimulus stimulus) {
82
83 tmpBounds.set(this.transformGroup.getBounds());
84 double diameter = tmpBounds.getRadius() * 2;
85
86 int j = stimulus.getX() - stimulus.getLastX();
87 int k = stimulus.getY() - stimulus.getLastY();
88 if (this.invert) {
89 j = -j;
90 k = -k;
91 }
92 if (!this.reset) {
93 this.scale = Math.exp((double)k * this.s_factor);
94 this.transformS.set(this.scale);
95 this.transformGroup.getTransform(this.currXform);
96 Matrix4d matrix4d = new Matrix4d();
97 this.currXform.get(matrix4d);
98 this.currXform.setTranslation(new Vector3d(0.0D, 0.0D, 0.0D));
99 if (this.invert) {
100 this.currXform.mul(this.currXform, this.transformS);
101 } else {
102 this.currXform.mul(this.transformS, this.currXform);
103 }
104 Vector3d vector3d = new Vector3d(matrix4d.m03, matrix4d.m13, matrix4d.m23);
105 this.currXform.setTranslation(vector3d);
106 this.transformGroup.setTransform(this.currXform);
107 transformChanged(this.currXform);
108 if (this.callback != null) {
109 this.callback.transformChanged(ManipulatorCallback.SCALE,
110 this.currXform,
111 null);
112 }
113
114 this.transformGroup.setBoundsAutoCompute(true);
115 } else {
116 this.reset = false;
117 }
118 }
119
120 public void transformChanged(Transform3D transform3d) {
121 }
122 }