diff examples/java3d/hello5.java @ 1:5df24c91468d

Oh my what a mess.
author samer
date Fri, 05 Apr 2019 16:26:00 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/java3d/hello5.java	Fri Apr 05 16:26:00 2019 +0100
@@ -0,0 +1,81 @@
+/*
+		hello5.java
+
+		Construct universe without using SimpleUniverse 
+		utility class - this puts together the view
+		group explicitly.
+		
+ */
+
+import samer.core.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+public class hello5 extends util implements Agent
+{
+	Canvas3D canvas;
+
+	public static void main(String[] args) { init(); new hello5(); }
+
+	public hello5()
+	{		
+		// create universe
+		LocalUniverse	U=new LocalUniverse();
+		BranchGroup		root=new BranchGroup();
+
+		// create scene
+		root.addChild(createSceneGraph());
+		// addBackground(root,new Background(0.1f,0.2f,0.15f));
+		// addLights(root);
+
+		// create view bits
+		canvas=new Canvas3D(getGraphicsConfiguration());
+		
+		TransformGroup	VT=new TransformGroup();
+		ViewPlatform	VP=new ViewPlatform();
+		View			V=new View();
+
+		{
+			Transform3D		t=new Transform3D();
+			t.set(new Vector3d(0.0,0.0,8.0));
+			VT.setTransform(t);
+		}
+		
+		addKeyNavigator(VT,readwrite(VT));
+		VT.addChild(VP);
+		V.addCanvas3D(canvas);
+		V.attachViewPlatform(VP);
+		V.setPhysicalBody(new PhysicalBody());
+		V.setPhysicalEnvironment(new PhysicalEnvironment());
+
+		root.addChild(VT);
+		root.compile();
+
+		Shell.registerAgent(this);
+		Shell.exposeCommands(this);
+
+		// setViewPolicy(canvas.getView());
+		expose(canvas,"hello");
+		U.addGroup(root);
+	}
+
+	private static TransformGroup createSceneGraph()
+	{
+		Transform3D		r=new Transform3D();
+		r.rotX(Math.PI/2);
+		TransformGroup  t2=new TransformGroup(r);
+		t2.addChild(yoyoGroup());
+
+		TransformGroup	tg = new TransformGroup();
+		addRotator(tg);
+		tg.addChild(t2);
+		return tg;
+	}
+
+	public void getCommands(Agent.Registry r) { r.add("start").add("stop"); }
+	public void execute(String cmd, Environment env) {
+		if (cmd.equals("start")) { canvas.startRenderer(); }
+		else if (cmd.equals("stop")) { canvas.stopRenderer(); }
+	}
+
+}
\ No newline at end of file