changeset 82:5cf20458b9e0 working

paste texture on the object
author sugi
date Thu, 24 May 2012 16:57:52 +0900
parents 02dfb6c72632
children 909e1c9bc6fc
files src/alice/test/topology/movement/FishMovement.java src/alice/test/topology/movement/SendLocation.java
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/test/topology/movement/FishMovement.java	Thu May 24 00:20:16 2012 +0900
+++ b/src/alice/test/topology/movement/FishMovement.java	Thu May 24 16:57:52 2012 +0900
@@ -1,12 +1,16 @@
 package alice.test.topology.movement;
 
 import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.Toolkit;
 
 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.Texture;
 import javax.media.j3d.Transform3D;
 import javax.media.j3d.TransformGroup;
 import javax.swing.JFrame;
@@ -15,6 +19,7 @@
 import javax.vecmath.Vector3f;
 
 import com.sun.j3d.utils.geometry.Box;
+import com.sun.j3d.utils.image.TextureLoader;
 import com.sun.j3d.utils.universe.SimpleUniverse;
 import com.sun.j3d.utils.universe.ViewingPlatform;
 
@@ -23,6 +28,7 @@
 	private Vector3f vector = null;
 	private Transform3D transform1 = null;
 	private TransformGroup transform_group = null;
+	private Canvas3D canvas = null;
 	
 	private static class instanceHolder{
 		private static final FishMovement instance = new FishMovement();
@@ -42,12 +48,12 @@
 		
 		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
 		
-		Canvas3D canvas = new Canvas3D(config);
+		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);
 		
@@ -56,6 +62,7 @@
 		
 		ViewingPlatform camera = universe.getViewingPlatform();
 		camera.setNominalViewingTransform();
+		frame.setVisible(true);
 	}
 	
 	private BranchGroup createBranch(){
@@ -63,7 +70,8 @@
 		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());
+		Box box = new Box(0.4f,0.4f,0.8f,
+				Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
 		transform_group.addChild(box);
 		setLocation(0.0f,0.0f);
 		return scene;
@@ -71,12 +79,11 @@
 	
 	private Appearance createAppearance() {
 		Appearance app = new Appearance();
-		/*
 		Image image = null; 	
 		Toolkit toolkit = Toolkit.getDefaultToolkit();
-		image = toolkit.getImage("fish1.jpg");
+		image = toolkit.getImage("../image/fish.jpg");
 		
-		MediaTracker mt = new MediaTracker();
+		MediaTracker mt = new MediaTracker(canvas);
 		mt.addImage(image, 0);
 		mt.checkAll(true);
 		try {
@@ -86,9 +93,10 @@
 			e.printStackTrace();
 			
 		}
-		Texture texture = new TextureLoader(image,this).getTexture();
+		Texture texture = new TextureLoader(image,canvas).getTexture();
 		app.setTexture(texture);
-		*/
+		
+		
 		return app;
 	}
 	
--- a/src/alice/test/topology/movement/SendLocation.java	Thu May 24 00:20:16 2012 +0900
+++ b/src/alice/test/topology/movement/SendLocation.java	Thu May 24 16:57:52 2012 +0900
@@ -18,7 +18,7 @@
 		System.out.println("setX : " +x/100);
 		
 		FishMovement fm = FishMovement.getInstance();
-		fm.setLocation((float)x/100, (float)y/100);
+		fm.setLocation((float)x/1000, (float)y/1000);
 		x++;
 		y++;