Mercurial > hg > Members > tatsuki > Alice
changeset 141:4c71bbfe557d working
add mouse event
author | sugi |
---|---|
date | Thu, 20 Sep 2012 21:35:23 +0900 |
parents | b51d3bf971e7 |
children | 287aae21e7d8 |
files | src/alice/test/topology/aquarium/MakeFrame.java src/alice/test/topology/aquarium/MakeObject.java src/alice/test/topology/aquarium/MouseViewEvent.java src/alice/test/topology/aquarium/ViewChange.java |
diffstat | 4 files changed, 143 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/topology/aquarium/MakeFrame.java Thu Sep 20 01:32:46 2012 +0900 +++ b/src/alice/test/topology/aquarium/MakeFrame.java Thu Sep 20 21:35:23 2012 +0900 @@ -26,7 +26,8 @@ private int fSizeX = 800; private int fSizeY = 800; - private Canvas3D canvas; + //private Canvas3D canvas; + private ViewChange canvas; private SimpleUniverse universe; private JFrame frame; private ObjectList list = new ObjectList(); @@ -41,19 +42,20 @@ frame.add(cp); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - canvas = new Canvas3D(config); + //canvas = new Canvas3D(config); + canvas = new ViewChange(3.0f,0.01f,config); canvas.setBounds(0,0,fSizeX,fSizeY); cp.add(canvas); - universe = new SimpleUniverse(canvas); - universe.addBranchGraph(createLight()); - universe.addBranchGraph(setBackground()); + + canvas.universe.addBranchGraph(createLight()); + canvas.universe.addBranchGraph(setBackground()); canvas.addKeyListener(new KeyInputCodeSegment(this)); frame.setVisible(true); - ViewingPlatform camera = universe.getViewingPlatform(); - camera.setNominalViewingTransform(); + //ViewingPlatform camera = universe.getViewingPlatform(); + //camera.setNominalViewingTransform(); } private BranchGroup setBackground(){ @@ -89,7 +91,7 @@ public void register(MakeObject obj){ list.table.add(obj); BranchGroup group = obj.createBranch(); - this.universe.addBranchGraph(group); + this.canvas.universe.addBranchGraph(group); } @@ -97,7 +99,7 @@ return this.universe; } - public Canvas3D getCanvas(){ + public ViewChange getCanvas(){ return this.canvas; }
--- a/src/alice/test/topology/aquarium/MakeObject.java Thu Sep 20 01:32:46 2012 +0900 +++ b/src/alice/test/topology/aquarium/MakeObject.java Thu Sep 20 21:35:23 2012 +0900 @@ -24,7 +24,8 @@ private Transform3D transform; private TransformGroup transform_group; - private Canvas3D canvas; + //private Canvas3D canvas; + private ViewChange canvas; private Matrix4d matrix; private double s;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/topology/aquarium/MouseViewEvent.java Thu Sep 20 21:35:23 2012 +0900 @@ -0,0 +1,69 @@ +package alice.test.topology.aquarium; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; + +import javax.media.j3d.Transform3D; +import javax.vecmath.Vector3f; + +public class MouseViewEvent implements MouseMotionListener { + /* + float sensitivity; + + float distance; + int new_x, new_y; + int pre_x, pre_y; + float camera_x, camera_y, camera_z, camera_xz, camera_xy, camera_yz = 0; + float phi = 0;//(float)Math.PI; + float theta = (float)Math.PI/3; + + Transform3D Transform_camera_pos; + Transform3D Transform_camera_phi; + Transform3D Transform_camera_theta; + Vector3f Vector_camera_pos; + */ + ViewChange v; + public MouseViewEvent(ViewChange v) { + this.v = v; + //this.distance = d; + //this.sensitivity = s; + } + + @Override + public void mouseDragged(MouseEvent event) { + v.new_x = event.getX(); + v.new_y = event.getY(); + + v.theta -= v.sensitivity * (v.new_y - v.pre_y); + v.phi += v.sensitivity * (v.new_x - v.pre_x); + v.camera_y = v.distance * (float)Math.sin(v.theta); + v.camera_xz = v.distance * (float)Math.cos(v.theta); + + v.camera_x = v.camera_xz * (float)Math.sin(v.phi); + v.camera_z = v.camera_xz * (float)Math.cos(v.phi); + + v.Vector_camera_pos.x = v.camera_x; + v.Vector_camera_pos.y = v.camera_y; + v.Vector_camera_pos.z = v.camera_z; + + v.Transform_camera_pos.setIdentity(); + v.Transform_camera_pos.setTranslation(v.Vector_camera_pos); + + v.Transform_camera_theta.rotX(-v.theta); + v.Transform_camera_phi.rotY(v.phi); + + v.Transform_camera_phi.mul(v.Transform_camera_theta); + v.Transform_camera_pos.mul(v.Transform_camera_phi); + v.Camera.setTransform(v.Transform_camera_pos); + v.pre_x = event.getX(); + v.pre_y = event.getY(); + + } + + @Override + public void mouseMoved(MouseEvent event) { + v.pre_x = event.getX(); + v.pre_y = event.getY(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/topology/aquarium/ViewChange.java Thu Sep 20 21:35:23 2012 +0900 @@ -0,0 +1,61 @@ +package alice.test.topology.aquarium; + +import java.awt.*; + +import javax.media.j3d.*; +import javax.vecmath.*; +import com.sun.j3d.utils.universe.*; + +public class ViewChange extends Canvas3D { + + private static final long serialVersionUID = 1L; + float sensitivity; + float distance; + int new_x, new_y; + int pre_x, pre_y; + SimpleUniverse universe; + TransformGroup Camera; + float camera_x, camera_y, camera_z, camera_xz, camera_xy, camera_yz = 0; + float phi = 0;//(float)Math.PI; + float theta = (float)Math.PI/3; + + Transform3D Transform_camera_pos; + Transform3D Transform_camera_phi; + Transform3D Transform_camera_theta; + Vector3f Vector_camera_pos; + + public ViewChange(float Distance, float Sensitivity, GraphicsConfiguration config){ + super(config); + distance = Distance; + sensitivity = Sensitivity; + universe = new SimpleUniverse(this); + ViewingPlatform vp = universe.getViewingPlatform(); + Camera = vp.getViewPlatformTransform(); + + camera_y = distance * (float)Math.sin(theta); + camera_xz = distance * (float)Math.cos(theta); + camera_x = camera_xz * (float)Math.sin(phi); + camera_z = camera_xz * (float)Math.cos(phi); + + Vector_camera_pos = new Vector3f(camera_x, camera_y, camera_z); + Transform_camera_pos = new Transform3D(); + Transform_camera_pos.setTranslation(Vector_camera_pos); + + Transform_camera_phi = new Transform3D(); + Transform_camera_theta = new Transform3D(); + Transform_camera_theta.rotX(-theta); + Transform_camera_phi.rotY(phi); + Transform_camera_theta.mul(Transform_camera_phi); + Transform_camera_pos.mul(Transform_camera_theta); + + Camera.setTransform(Transform_camera_pos); + + MouseViewEvent mouse = new MouseViewEvent(this); + addMouseMotionListener(mouse); + + } + + + +} +