345
|
1 package alice.test.topology.aquarium;
|
|
2
|
613
|
3 import com.sun.j3d.utils.universe.SimpleUniverse;
|
|
4 import com.sun.j3d.utils.universe.ViewingPlatform;
|
|
5
|
|
6 import javax.media.j3d.Canvas3D;
|
|
7 import javax.media.j3d.Transform3D;
|
|
8 import javax.media.j3d.TransformGroup;
|
|
9 import javax.vecmath.Vector3f;
|
345
|
10 import java.awt.*;
|
|
11
|
613
|
12 import static com.sun.java.accessibility.util.AWTEventMonitor.addMouseMotionListener;
|
345
|
13
|
|
14 public class ViewChange extends Canvas3D {
|
|
15
|
419
|
16 private static final long serialVersionUID = 1L;
|
|
17 float sensitivity;
|
|
18 float distance = 2.5f;
|
|
19 float camera_x, camera_y, camera_z, camera_xz, camera_xy, camera_yz = 0;
|
|
20 float phi = 0; // flow
|
|
21 float theta = 0;
|
|
22
|
|
23 SimpleUniverse universe;
|
|
24 TransformGroup Camera;
|
|
25 Transform3D Transform_camera_pos;
|
|
26 Transform3D Transform_camera_phi;
|
|
27 Transform3D Transform_camera_theta;
|
|
28 Vector3f Vector_camera_pos;
|
|
29
|
|
30 public ViewChange(float x, float Sensitivity, GraphicsConfiguration config){
|
|
31 super(config);
|
|
32
|
|
33 sensitivity = Sensitivity;
|
|
34 universe = new SimpleUniverse(this);
|
|
35 ViewingPlatform vp = universe.getViewingPlatform();
|
|
36 Camera = vp.getViewPlatformTransform();
|
345
|
37
|
419
|
38 camera_y = distance * (float)Math.sin(theta);
|
|
39 camera_xz = distance * (float)Math.cos(theta);
|
|
40 System.out.println(x);
|
|
41 camera_x = x;
|
|
42 camera_z = camera_xz * (float)Math.cos(phi);
|
345
|
43
|
419
|
44 Vector_camera_pos = new Vector3f(camera_x, camera_y, camera_z);
|
|
45 Transform_camera_pos = new Transform3D();
|
|
46 Transform_camera_pos.setTranslation(Vector_camera_pos);
|
|
47 Transform_camera_phi = new Transform3D();
|
|
48 Transform_camera_theta = new Transform3D();
|
|
49 Transform_camera_theta.rotX(-theta);
|
|
50 Transform_camera_phi.rotY(phi);
|
|
51 Transform_camera_theta.mul(Transform_camera_phi);
|
|
52 Transform_camera_pos.mul(Transform_camera_theta);
|
345
|
53
|
419
|
54 Camera.setTransform(Transform_camera_pos);
|
|
55
|
|
56 addMouseMotionListener(new MouseViewEvent(this));
|
|
57
|
|
58 }
|
|
59
|
|
60
|
|
61
|
345
|
62 }
|
|
63
|