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