changeset 81:02dfb6c72632 working

This is movement test
author sugi
date Thu, 24 May 2012 00:20:16 +0900
parents 54f5b5496bfe
children 5cf20458b9e0
files .classpath src/alice/test/topology/movement/CheckMyName.java src/alice/test/topology/movement/FishMovement.java src/alice/test/topology/movement/FishMovementConfig.java src/alice/test/topology/movement/FishMovementTopology.java src/alice/test/topology/movement/SendLocation.java src/alice/test/topology/movement/StartFishMovement.java
diffstat 7 files changed, 239 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Fri Mar 02 16:12:45 2012 +0900
+++ b/.classpath	Thu May 24 00:20:16 2012 +0900
@@ -8,5 +8,8 @@
 	<classpathentry kind="lib" path="lib/slf4j-log4j12-1.6.1.jar"/>
 	<classpathentry kind="lib" path="lib/com.alexmerz.graphviz.jar"/>
 	<classpathentry kind="lib" path="lib/msgpack-0.6.6-SNAPSHOT.jar" sourcepath="lib/msgpack-0.6.6-SNAPSHOT-sources.jar"/>
+	<classpathentry kind="lib" path="/Users/YuSUGIMOTO/src/jar/j3dcore.jar"/>
+	<classpathentry kind="lib" path="/Users/YuSUGIMOTO/src/jar/j3dutils.jar"/>
+	<classpathentry kind="lib" path="/Users/YuSUGIMOTO/src/jar/vecmath.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/CheckMyName.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,39 @@
+package alice.test.topology.movement;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckMyName extends CodeSegment {
+	Receiver host = ids.create(CommandType.PEEK);
+	@Override
+	public void run(){
+		
+		String name = host.asString();
+		Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
+		Matcher matcher = pattern.matcher(name);
+		
+		matcher.find();
+		String type = matcher.group(1);
+		int cliNum = new Integer(matcher.group(2));
+		
+		if (type.equals("cli")){
+			System.out.println("cli"+cliNum);
+			
+			FishMovement.getInstance();
+			
+			SendLocation cs = new SendLocation();
+			cs.nowX.setKey("parent","fishX");
+			cs.nowY.setKey("parent","fishY");
+					
+		}else if(type.equals("node")){
+			System.out.println("node0");
+			ods.update("local", "fishX", 10);
+			ods.update("local", "fishY", 10);
+			
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/FishMovement.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,123 @@
+package alice.test.topology.movement;
+
+import java.awt.GraphicsConfiguration;
+
+import javax.media.j3d.Appearance;
+import javax.media.j3d.BoundingSphere;
+import javax.media.j3d.BranchGroup;
+import javax.media.j3d.Canvas3D;
+import javax.media.j3d.DirectionalLight;
+import javax.media.j3d.Transform3D;
+import javax.media.j3d.TransformGroup;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import com.sun.j3d.utils.geometry.Box;
+import com.sun.j3d.utils.universe.SimpleUniverse;
+import com.sun.j3d.utils.universe.ViewingPlatform;
+
+public final class FishMovement {
+	
+	private Vector3f vector = null;
+	private Transform3D transform1 = null;
+	private TransformGroup transform_group = null;
+	
+	private static class instanceHolder{
+		private static final FishMovement instance = new FishMovement();
+	}
+	public static FishMovement getInstance() {
+		return instanceHolder.instance;
+		
+	}
+	
+	private FishMovement(){
+		JFrame frame = new JFrame();
+		frame.setSize(1000,1000);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		JPanel cp = new JPanel();
+		frame.add(cp);
+		
+		
+		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+		
+		Canvas3D canvas = new Canvas3D(config);
+		canvas.setBounds(0,0,1000,1000);//set canvas size 
+		cp.add(canvas);//register canvas with ContentPane
+				
+		SimpleUniverse universe = new SimpleUniverse(canvas);
+		frame.setVisible(true);
+		BranchGroup group1 = createBranch();
+		universe.addBranchGraph(group1);
+		
+		BranchGroup group2 = createLight();
+		universe.addBranchGraph(group2);
+		
+		ViewingPlatform camera = universe.getViewingPlatform();
+		camera.setNominalViewingTransform();
+	}
+	
+	private BranchGroup createBranch(){
+		BranchGroup scene = new BranchGroup();
+		transform_group = new TransformGroup();
+		scene.addChild(transform_group);
+		transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+		Box box = new Box(0.4f,0.4f,0.8f,Box.GENERATE_TEXTURE_COORDS,createAppearance());
+		transform_group.addChild(box);
+		setLocation(0.0f,0.0f);
+		return scene;
+	}
+	
+	private Appearance createAppearance() {
+		Appearance app = new Appearance();
+		/*
+		Image image = null; 	
+		Toolkit toolkit = Toolkit.getDefaultToolkit();
+		image = toolkit.getImage("fish1.jpg");
+		
+		MediaTracker mt = new MediaTracker();
+		mt.addImage(image, 0);
+		mt.checkAll(true);
+		try {
+			mt.waitForID(0);
+			
+		}catch (InterruptedException e){
+			e.printStackTrace();
+			
+		}
+		Texture texture = new TextureLoader(image,this).getTexture();
+		app.setTexture(texture);
+		*/
+		return app;
+	}
+	
+	private BranchGroup createLight(){
+		BranchGroup scene = new BranchGroup();
+		Color3f light_color  = new Color3f(1.7f,1.7f,1.7f);
+		Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
+		DirectionalLight light = new DirectionalLight(light_color,light_direction);
+		BoundingSphere bounds = new BoundingSphere();
+		light.setInfluencingBounds(bounds);
+		scene.addChild(light);
+		return scene;
+	}
+	
+	public void setLocation(float x,float y){
+		transform1 = new Transform3D();
+		vector = new Vector3f(x,y,0.0f);
+		transform1.setTranslation(vector);
+		transform_group.setTransform(transform1);
+	}
+	
+	public void setLocation(float x,float y,float z){
+		transform1 = new Transform3D();
+		vector = new Vector3f(x,y,z);
+		transform1.setTranslation(vector);
+		transform_group.setTransform(transform1);
+	}
+
+	
+	
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/FishMovementConfig.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,12 @@
+package alice.test.topology.movement;
+
+import alice.topology.node.TopologyNodeConfig;;
+
+public class FishMovementConfig extends TopologyNodeConfig {
+	
+	public FishMovementConfig(String[] args){
+		super(args);
+	} 
+	
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/FishMovementTopology.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,11 @@
+package alice.test.topology.movement;
+import alice.topology.node.TopologyNode;
+
+public class FishMovementTopology {
+	public static void main(String[] args){
+		FishMovementConfig conf = new FishMovementConfig(args);
+		new TopologyNode(conf, new StartFishMovement());
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/SendLocation.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,38 @@
+package alice.test.topology.movement;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+
+public class SendLocation extends CodeSegment{
+	
+	public Receiver nowX = ids.create(CommandType.TAKE);
+	public Receiver nowY = ids.create(CommandType.TAKE);
+	
+	@Override
+	public void run(){
+		System.out.println("run SendLocation");
+		int x = this.nowX.asInteger();
+		int y = this.nowY.asInteger();
+		System.out.println("setX : " +x/100);
+		
+		FishMovement fm = FishMovement.getInstance();
+		fm.setLocation((float)x/100, (float)y/100);
+		x++;
+		y++;
+
+		
+		SendLocation cs = new SendLocation();
+		cs.nowX.setKey("parent","fishX");
+		cs.nowY.setKey("parent","fishY");
+		
+		ods.update("parent", "fishX", x);
+		ods.update("parent", "fishY", y);
+		
+		
+				
+	}
+	
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/movement/StartFishMovement.java	Thu May 24 00:20:16 2012 +0900
@@ -0,0 +1,13 @@
+package alice.test.topology.movement;
+
+import alice.codesegment.CodeSegment;
+
+public class StartFishMovement extends CodeSegment{
+	@Override
+	public void run(){
+		CheckMyName cs = new CheckMyName();
+		cs.host.setKey("local","host");
+	}
+	
+
+}