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 Zoom in here
34 *
35 * @version $Revision: 1.3 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see Manipulator
38 */
39
40 public class Zoom extends Manipulator {
41 private Transform3D transformZ;
42 private double z_factor;
43 private Vector3d translation;
44 private BoundingSphere tmpBounds = new BoundingSphere();
45
46 public Zoom() {
47 super(false);
48 this.z_factor = 0.04D;
49 this.translation = new Vector3d();
50 }
51
52 public Zoom(boolean invert) {
53 super(invert);
54 this.z_factor = 0.04D;
55 this.translation = new Vector3d();
56 }
57
58 public Zoom(TransformGroup transformgroup) {
59 super(transformgroup);
60 this.z_factor = 0.04D;
61 this.translation = new Vector3d();
62 }
63
64 public void setFactor(double d) {
65 this.z_factor = d;
66 }
67
68 public double getFactor() {
69 return this.z_factor;
70 }
71
72 public void initialize() {
73 super.initialize();
74 if (this.invert) {
75 this.z_factor *= -1D;
76 }
77 this.transformZ = new Transform3D();
78 }
79
80 public void processStimulus(Stimulus stimulus) {
81 super.processStimulus(stimulus);
82
83
84 tmpBounds.set(this.transformGroup.getBounds());
85 double diameter = tmpBounds.getRadius() * 2;
86
87 int j = stimulus.getX() - stimulus.getLastX();
88 int k = stimulus.getY() - stimulus.getLastY();
89 if (this.invert) {
90 j = -j;
91 k = -k;
92 }
93 if (!this.reset) {
94 this.transformGroup.getTransform(this.currXform);
95 this.translation.z = (double)k * this.z_factor * diameter;
96 this.translation.x = 0;
97 this.translation.y = 0;
98 if (this.useL2U) {
99 this.l2u.transform(this.translation);
100 }
101 this.transformZ.set(this.translation);
102 if (this.invert) {
103 this.currXform.mul(this.currXform, this.transformZ);
104 } else {
105 this.currXform.mul(this.transformZ, this.currXform);
106 }
107 this.transformGroup.setTransform(this.currXform);
108 this.transformChanged(this.currXform);
109 if (this.callback != null) {
110 this.callback.transformChanged(ManipulatorCallback.ZOOM,
111 this.currXform,
112 null);
113 }
114 } else {
115 this.reset = false;
116 }
117 }
118
119 public void transformChanged(Transform3D transform3d) {
120 }
121 }