# HG changeset patch
# User axmo
# Date 1218460803 -32400
# Node ID 0652ac3c8b5f63aaa32ee9db5261032e2c5dda81
# Parent 34821c03b2064918ebf78e14d1ce6db8a339b602
add two_obj
diff -r 34821c03b206 -r 0652ac3c8b5f tools/java3d-test/src/HelloUniverse.java
--- a/tools/java3d-test/src/HelloUniverse.java Mon Aug 11 01:53:54 2008 +0900
+++ b/tools/java3d-test/src/HelloUniverse.java Mon Aug 11 22:20:03 2008 +0900
@@ -82,8 +82,13 @@
// desired operation on the specified transform and add
// it into the scene graph.
Transform3D yAxis = new Transform3D();
+ TransformGroup transRoot = new TransformGroup();
+ Transform3D transform = new Transform3D();
Alpha rotationAlpha = alpha;
+ transform.set(new Vector3d(1.0, 1.0, 1.0));
+ transRoot.setTransform(transform);
+
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objTrans, yAxis,
0.0f, (float) Math.PI*2.0f);
diff -r 34821c03b206 -r 0652ac3c8b5f tools/java3d-test/src/Java3DProgram.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/java3d-test/src/Java3DProgram.java Mon Aug 11 22:20:03 2008 +0900
@@ -0,0 +1,77 @@
+// Java3DProgram.java
+
+import java.applet.Applet;
+import com.sun.j3d.utils.applet.MainFrame;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+import java.awt.*;
+
+import com.sun.j3d.utils.universe.*;
+import com.sun.j3d.utils.geometry.ColorCube;
+import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
+
+/*
+
+*/
+
+public class Java3DProgram extends Applet {
+
+ public SimpleUniverse universe = null;
+ public Canvas3D canvas = null;
+
+ public BranchGroup createObjects() {
+
+ BranchGroup root = new BranchGroup();
+
+ // 平行移動を定義
+ TransformGroup transRoot = new TransformGroup();
+ Transform3D transform = new Transform3D();
+
+ // x方向に1.0m移動
+ transform.set(new Vector3d(1.0, 0, 0));
+ transRoot.setTransform(transform);
+
+ // 色つき立方体の作成
+ transRoot.addChild(new ColorCube(0.4));
+ root.addChild(transRoot);
+ root.compile();
+
+ return root;
+ }
+
+ public void setOrbitBehavior() {
+
+ // マウスでぐりぐりするための処理
+ OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
+ orbit.setSchedulingBounds(
+ new BoundingSphere(new Point3d(0, 0, 0), 100.0));
+ universe.getViewingPlatform().setViewPlatformBehavior(orbit);
+ }
+
+ public void init() {
+
+ setLayout(new BorderLayout());
+
+ // キャンバスの作成
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+ Canvas3D canvas = new Canvas3D(config);
+ add("Center", canvas);
+
+ // SimpleUniverse の作成
+ universe = new SimpleUniverse(canvas);
+
+ // カメラの移動(原点から少しだけ後ろにずれる)
+ universe.getViewingPlatform().setNominalViewingTransform();
+
+ // マウスでぐりぐり動かすための処理
+ setOrbitBehavior();
+
+ // オブジェクトの追加
+ universe.addBranchGraph(createObjects());
+ }
+
+ public static void main(String[] args) {
+ new MainFrame(new Java3DProgram(), 200, 200);
+ }
+}
\ No newline at end of file
diff -r 34821c03b206 -r 0652ac3c8b5f tools/java3d-test/src/graff3d.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/java3d-test/src/graff3d.java Mon Aug 11 22:20:03 2008 +0900
@@ -0,0 +1,529 @@
+// Draw the graph of a function
+// version 1.0 (c) K.Sasano
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.awt.Font;
+import java.awt.GraphicsConfiguration;
+import java.util.Enumeration;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+import com.sun.j3d.utils.universe.*;
+import com.sun.j3d.utils.applet.MainFrame;
+import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
+import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
+import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
+import com.sun.j3d.utils.geometry.Text2D;
+
+public class graff3d extends Applet {
+
+ // global variables
+ float xwidth;
+ float x0;
+ float ywidth;
+ float y0;
+ float xdelta;
+ float ydelta;
+ float z0;
+ float zwidth;
+ float zvalue[][];
+ float zcenter[][];
+ Shape3D surfaceGraph;
+ Shape3D meshGraph;
+ Shape3D xyPlane;
+ Shape3D xyzAxes;
+ Shape3D xyzArrowHead;
+ TransformGroup xyzAxesLabels;
+
+ //key behavior
+ public class KeyBehavior extends Behavior{
+
+ private BranchGroup bg;
+ private WakeupOnAWTEvent wue;
+
+ KeyBehavior(BranchGroup bg){
+ this.bg=bg;
+ }
+
+ public void initialize(){
+ this.wakeupOn(wue = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
+ }
+
+ public void processStimulus(Enumeration criteria){
+ AWTEvent ae = (wue.getAWTEvent())[0];
+ char c=((KeyEvent)ae).getKeyChar();
+ TransparencyAttributes
+ surftr = (surfaceGraph.getAppearance()).getTransparencyAttributes();
+ TransparencyAttributes
+ meshtr = (meshGraph.getAppearance()).getTransparencyAttributes();
+ TransparencyAttributes
+ xytr = (xyPlane.getAppearance()).getTransparencyAttributes();
+
+ if(c=='s'){ //Show/Erase surfacegraph
+ addSurface=!addSurface;
+ if(addSurface){
+ surftr = new TransparencyAttributes(TransparencyAttributes.NONE,0.0f);
+ }else{
+ surftr = new TransparencyAttributes(TransparencyAttributes.NICEST,1.0f);
+ }
+ }
+ if(c=='m'){ //Show/Erase meshgraph
+ float tr;
+ addMesh=!addMesh;
+ if(addMesh){ tr= 0.0f; } else { tr=1.0f; }
+ meshtr = new TransparencyAttributes(TransparencyAttributes.NICEST,tr);
+ }
+ if(c=='z'){ //Show/Erase xyplane
+ float tr;
+ addXYPlane=!addXYPlane;
+ if(addXYPlane){ tr= 0.6f; } else { tr=1.0f; }
+ xytr = new TransparencyAttributes(TransparencyAttributes.NICEST,tr);
+ }
+ (xyPlane.getAppearance()).setTransparencyAttributes(xytr);
+ (meshGraph.getAppearance()).setTransparencyAttributes(meshtr);
+ (surfaceGraph.getAppearance()).setTransparencyAttributes(surftr);
+
+ this.wakeupOn(wue = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
+ }
+ }
+
+ //create scene
+ public BranchGroup createSceneGraph() {
+ BranchGroup objRoot = new BranchGroup();
+ BoundingSphere bounds = new BoundingSphere();
+ bounds.setRadius( 1000.0 );
+
+ //prepare for movement
+ TransformGroup objTrans = new TransformGroup();
+ objRoot.addChild(objTrans);
+
+ objTrans.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
+ objTrans.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
+
+ MouseRotate rotat = new MouseRotate( objTrans );
+ MouseTranslate trans = new MouseTranslate( objTrans );
+ MouseZoom zoom = new MouseZoom( objTrans );
+
+ rotat.setSchedulingBounds( bounds );
+ trans.setSchedulingBounds( bounds );
+ zoom.setSchedulingBounds( bounds );
+
+ objTrans.addChild(rotat);
+ objTrans.addChild(trans);
+ objTrans.addChild(zoom);
+
+ //add xy-plane
+ objTrans.addChild(xyPlane);
+
+ //add graphs
+ objTrans.addChild(surfaceGraph);
+ objTrans.addChild(meshGraph);
+
+ //add axes
+ objTrans.addChild(xyzAxes); //axis
+ objTrans.addChild(xyzArrowHead); //arrowhead
+ objTrans.addChild(xyzAxesLabels); //label
+
+ //add key behavior
+ KeyBehavior myKeyBehav=new KeyBehavior(objRoot);
+ myKeyBehav.setSchedulingBounds( bounds );
+ objRoot.addChild(myKeyBehav);
+
+ //compile the object
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ //surface graph
+ private Shape3D graph(){
+ int totalN=6*n*n;
+
+ Point3f coord[] = new Point3f[totalN];
+ Color3f color[] = new Color3f[totalN];
+
+ for(int i=0; i1){ r=1.0f; g=0.5f; b=0.0f; }
+ else if(h>0){ r=h*1.0f; g=0.75f-h*0.25f; b=0.0f; }
+ else if(h>-1){ r=0.0f; g=(1+h)*0.75f; b= -h*0.75f; }
+ else{ r=0.0f; g=0.0f; b=0.75f;}
+ return new Color3f(r,g,b);
+ }
+
+ //mesh graph
+ private Shape3D meshgraph(){
+ //construct coordinat data
+ int totalN=2*(nmesh+1)*(nmesh+1);
+
+ Point3f coord[] = new Point3f[totalN];
+ Color3f color[] = new Color3f[totalN];
+ Color3f lcolor = new Color3f(1.0f, 1.0f, 1.0f);
+
+ for(int i=0; i<=nmesh; i++){
+ float xi=xmin+i*(xmax-xmin)/nmesh;
+
+ for(int j=0; j<=nmesh; j++){
+ int tmp=i*(nmesh+1)+j;
+ int tmp1=j*(nmesh+1)+i+(nmesh+1)*(nmesh+1);
+ float yj=ymin+j*(ymax-ymin)/nmesh;
+
+ coord[tmp]=new Point3f(xn(xi),yn(yj),zn(f(xi,yj)));
+ color[tmp]=lcolor;
+
+ coord[tmp1]=coord[tmp];
+ color[tmp1]=color[tmp];
+ }
+ }
+
+ int stripCounts[];
+ stripCounts= new int[2*(nmesh+1)];
+ for(int i=0; i<=2*nmesh+1; i++){stripCounts[i]=nmesh+1;}
+
+ LineStripArray lsa =
+ new LineStripArray(
+ totalN,
+ LineStripArray.COORDINATES|LineStripArray.COLOR_3,
+ stripCounts
+ );
+ lsa.setCoordinates(0,coord);
+ lsa.setColors(0,color);
+
+ //construct appearence
+ LineAttributes attr = new LineAttributes();
+ attr.setLineWidth(meshLineWidth);
+
+ float tr;
+ if(addMesh){ tr= 0.0f; } else { tr=1.0f; }
+ TransparencyAttributes transAttrib;
+ transAttrib = new TransparencyAttributes(TransparencyAttributes.NICEST,tr);
+
+ Appearance appear = new Appearance();
+ appear.setLineAttributes(attr);
+ appear.setTransparencyAttributes(transAttrib);
+ appear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
+ appear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
+
+ //construct Shape3D for meshgraph
+ Shape3D graphshape=new Shape3D();
+ graphshape.removeGeometry(0);
+ graphshape.addGeometry(lsa);
+ graphshape.setAppearance(appear);
+ graphshape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
+ graphshape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
+
+ return graphshape;
+ }
+
+ //xy-plane
+ private Shape3D xyplane(){
+ QuadArray xyp= new QuadArray(4,QuadArray.COORDINATES|QuadArray.COLOR_3);
+ xyp.setCoordinate(0,new Point3f(0.5f,0.5f,zn(0.0f)));
+ xyp.setCoordinate(1,new Point3f(-0.5f,0.5f,zn(0.0f)));
+ xyp.setCoordinate(2,new Point3f(-0.5f,-0.5f,zn(0.0f)));
+ xyp.setCoordinate(3,new Point3f(0.5f,-0.5f,zn(0.0f)));
+ for(int i=0; i<4; i++){xyp.setColor(i, new Color3f(1.0f,1.0f,1.0f));}
+
+ PolygonAttributes attrib = new PolygonAttributes();
+ attrib.setCullFace(PolygonAttributes.CULL_NONE);
+ attrib.setPolygonMode(PolygonAttributes.POLYGON_FILL);
+
+ TransparencyAttributes transAttrib;
+ float tr;
+ if(addXYPlane){ tr= 0.6f; } else { tr=1.0f; }
+ transAttrib = new TransparencyAttributes(TransparencyAttributes.NICEST,tr);
+
+ Appearance appear = new Appearance();
+ appear.setPolygonAttributes(attrib);
+ appear.setTransparencyAttributes(transAttrib);
+ appear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
+ appear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
+
+ Shape3D xyplaneshape=new Shape3D();
+ xyplaneshape.removeGeometry(0);
+ xyplaneshape.addGeometry(xyp);
+ xyplaneshape.setAppearance(appear);
+ xyplaneshape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
+ xyplaneshape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
+
+ return xyplaneshape;
+ }
+
+ //axes
+ private Shape3D axes(){
+ LineArray a=new LineArray(6,LineArray.COORDINATES|LineArray.COLOR_3);
+ a.setCoordinate(0,new Point3f(0.6f,yn(0.0f),zn(0.0f)));
+ a.setCoordinate(1,new Point3f(-0.6f,yn(0.0f),zn(0.0f)));
+ a.setCoordinate(2,new Point3f(xn(0.0f),0.6f,zn(0.0f)));
+ a.setCoordinate(3,new Point3f(xn(0.0f),-0.6f,zn(0.0f)));
+ a.setCoordinate(4,new Point3f(xn(0.0f),yn(0.0f),0.6f));
+ a.setCoordinate(5,new Point3f(xn(0.0f),yn(0.0f),-0.6f));
+ for(int i=0; i<6; i++){ a.setColor(i,new Color3f(1.0f,1.0f,0.0f));}
+
+ LineAttributes att=new LineAttributes();
+ att.setLineWidth(2.0f);
+ Appearance appear = new Appearance();
+ appear.setLineAttributes(att);
+
+ Shape3D ax=new Shape3D();
+ ax.removeGeometry(0);
+ ax.addGeometry(a);
+ ax.setAppearance(appear);
+
+ return ax;
+ }
+
+ //arrowhead
+ private Shape3D arrowhead(){
+ int scounts[]= new int[3];
+ for(int i=0; i<3; i++){scounts[i]=10;}
+
+ TriangleFanArray ah=new TriangleFanArray(30,
+ TriangleFanArray.COORDINATES|TriangleFanArray.COLOR_3,
+ scounts);
+ ah.setCoordinate(0,new Point3f(0.6f, yn(0.0f), zn(0.0f)));
+ ah.setCoordinate(10,new Point3f(xn(0.0f),0.6f, zn(0.0f)));
+ ah.setCoordinate(20,new Point3f(xn(0.0f), yn(0.0f), 0.6f));
+ float d=(float)Math.PI/4;
+ for(int i=0 ; i<=8; i++){
+ ah.setCoordinate(i+1,
+ new Point3f(0.55f, yn(0.0f)+0.02f * (float)Math.cos(d*i), zn(0.0f)+0.02f *(float)Math.sin(d*i)));
+ ah.setCoordinate(i+11,
+ new Point3f(xn(0.0f)+0.02f * (float)Math.cos(d*i), 0.55f, zn(0.0f)+0.02f *(float)Math.sin(d*i)));
+ ah.setCoordinate(i+21,
+ new Point3f(xn(0.0f)+0.02f * (float)Math.cos(d*i), yn(0.0f)+0.02f *(float)Math.sin(d*i), 0.55f));
+ }
+ Color3f color[]=new Color3f[30];
+ for(int i=0; i<30; i++){ color[i]=new Color3f(1.0f, 1.0f, 0.0f);}
+ ah.setColors(0,color);
+
+ return new Shape3D(ah);
+ }
+
+ //axes labels
+ TransformGroup axeslabels(){
+ TransformGroup tmp = new TransformGroup();
+
+ PolygonAttributes polyAttrib = new PolygonAttributes();
+ polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
+ polyAttrib.setBackFaceNormalFlip(true);
+
+ Transform3D xmov= (new Transform3D());
+ xmov.set(new Vector3f(0.63f,yn(0.0f)-0.05f,zn(0.0f)));
+ Text2D xlbl=new Text2D("x",new Color3f(1.0f,1.0f,0.0f),"Helvetica",24,Font.BOLD);
+ (xlbl.getAppearance()).setPolygonAttributes(polyAttrib);
+ TransformGroup xmovg=new TransformGroup(xmov);
+ xmovg.addChild(xlbl);
+
+ Transform3D ymov= new Transform3D();
+ Transform3D tmpymov=new Transform3D();
+ tmpymov.rotZ(Math.PI/2.0d);
+ ymov.set(new Vector3f(xn(0.0f)+0.05f,0.63f,zn(0.0f)));
+ ymov.mul(tmpymov);
+ Text2D ylbl=new Text2D("y",new Color3f(1.0f,1.0f,0.0f),"Helvetica",24,Font.BOLD);
+ (ylbl.getAppearance()).setPolygonAttributes(polyAttrib);
+ TransformGroup ymovg=new TransformGroup(ymov);
+ ymovg.addChild(ylbl);
+
+ Transform3D zmov= new Transform3D();
+ Transform3D tmpzmov=new Transform3D();
+ tmpzmov.rotX(Math.PI/2.0d);
+ zmov.set(new Vector3f(xn(0.0f)-0.02f,yn(0.0f),0.63f));
+ zmov.mul(tmpzmov);
+ Text2D zlbl=new Text2D("z",new Color3f(1.0f,1.0f,0.0f),"Helvetica",24,Font.BOLD);
+ (zlbl.getAppearance()).setPolygonAttributes(polyAttrib);
+ TransformGroup zmovg=new TransformGroup(zmov);
+ zmovg.addChild(zlbl);
+
+ tmp.addChild(xmovg);
+ tmp.addChild(ymovg);
+ tmp.addChild(zmovg);
+
+ return tmp;
+ }
+
+ //get normalized coordinate
+ float xn(float x){ return (x-x0)/xwidth;}
+ float yn(float y){ return (y-y0)/ywidth;}
+ float zn(float z){ return (z-z0)/zwidth;}
+
+ //////////// main class ///////////////
+ public graph3d() {
+ // preparation for numeric data
+ xwidth=xmax-xmin;
+ x0=(xmax+xmin)/2;
+ ywidth=ymax-ymin;
+ y0=(ymax+ymin)/2;
+ xdelta=xwidth/n;
+ ydelta=ywidth/n;
+
+ zvalue = new float[n+1][n+1];
+ zcenter = new float[n][n];
+
+ int i; int j;
+
+ for(i=0; i<=n; i++){
+ for(j=0; j<=n; j++){
+ zvalue[i][j]=f(xmin+i*xdelta, ymin+j*ydelta);
+ }
+ }
+ for(i=0; i