⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleinterpolator.java

📁 包括了JAVA3D(全世界都能看到的网络三维动画)的源代码部分! 很多基础但是却很精彩的例子!有什么不明白的也可以和我交流MSN:guorui0728@hotmail.com
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        objRoot.addChild(objTranspPos);
        
        Box myBox=new Box(0.4f, 0.4f, 0.4f,								  Box.GENERATE_NORMALS , transpAppear);
        objTranspPos.addChild(myBox);
        objRoot.addChild(traInt);
		
		DirectionalLight lightD1 = new DirectionalLight();
		lightD1.setDirection(new Vector3f(0.0f,-1.0f,-1.0f));
		lightD1.setColor(white);
		lightD1.setInfluencingBounds(bounds);
		objRoot.addChild(lightD1);

*/
  /*     TransformGroup objMove = new TransformGroup();
        objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		float knots[]={0.0f,0.2f,0.4f,0.8f,1.0f};
		Point3f positions[]={
			new Point3f(0.0f,0.0f,0.0f),
			new Point3f(1.0f,1.0f,0.0f),
			new Point3f(2.0f,0.0f,-2.0f),
			new Point3f(1.0f,-1.0f,2.0f),
			new Point3f(0.0f,0.0f,0.0f)
		};
		
		t3d.setTranslation(new Vector3f(0.0f,1.0f,0.0f));
		Alpha alpha = new Alpha (-1,
                                 Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                                 0, 0, 2000, 0, 1000, 2000, 0, 1000);

        // create position interpolator
        PositionPathInterpolator posPathInt = new PositionPathInterpolator(alpha, objMove,t3d,knots,positions);
        posPathInt.setSchedulingBounds(bounds);
//        posPathInt.setStartPosition(-1.0f);
		
		 t3d.setTranslation(new Vector3f(-1.0f, 0.0f, -1.0f));
        TransformGroup objMovePos = new TransformGroup(t3d);
        objRoot.addChild(objMovePos);
        objMovePos.addChild(objMove);
		objMove.addChild(new ColorCube(0.2f));
        objRoot.addChild(posPathInt);
*/		
/*		TransformGroup objMove = new TransformGroup();
        objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		float knots[]={0.0f,0.2f,0.4f,0.8f,1.0f};
		Point3f positions[]={
			new Point3f(0.0f,0.0f,0.0f),
			new Point3f(1.0f,1.0f,0.0f),
			new Point3f(2.0f,0.0f,-2.0f),
			new Point3f(1.0f,-1.0f,2.0f),
			new Point3f(0.0f,0.0f,0.0f)
		};
		Quat4f quats[]={
			new Quat4f(0.0f,1.0f,0.0f,0.0f),
			new Quat4f(0.0f,1.0f,0.0f,0.78f),
			new Quat4f(0.0f,1.0f,0.0f,1.57f),
			new Quat4f(0.0f,1.0f,0.0f,2.35f),
			new Quat4f(0.0f,1.0f,0.0f,3.14f)
		};
  		
		t3d.setTranslation(new Vector3f(0.0f,1.0f,0.0f));
		Alpha alpha = new Alpha (-1,
                                 Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                                 0, 0, 2000, 0, 1000, 2000, 0, 1000);

        // create position interpolator
        RotPosPathInterpolator rotposPathInt = new RotPosPathInterpolator(alpha, objMove,t3d,knots,quats,positions);
        rotposPathInt.setSchedulingBounds(bounds);
//        posPathInt.setStartPosition(-1.0f);
		
		 t3d.setTranslation(new Vector3f(-1.0f, 0.0f, -1.0f));
        TransformGroup objMovePos = new TransformGroup(t3d);
        objRoot.addChild(objMovePos);
        objMovePos.addChild(objMove);
		objMove.addChild(new ColorCube(0.2f));
        objRoot.addChild(rotposPathInt);
*/
/*		TransformGroup objMove = new TransformGroup();
        objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		float knots[]={0.0f,0.2f,0.4f,0.8f,1.0f};
		Point3f positions[]={
			new Point3f(0.0f,0.0f,0.0f),
			new Point3f(1.0f,1.0f,0.0f),
			new Point3f(2.0f,0.0f,-2.0f),
			new Point3f(1.0f,-1.0f,2.0f),
			new Point3f(0.0f,0.0f,0.0f)
		};
		Quat4f quats[]={
			new Quat4f(0.0f,1.0f,0.0f,0.0f),
			new Quat4f(0.0f,1.0f,0.0f,0.78f),
			new Quat4f(0.0f,1.0f,0.0f,1.57f),
			new Quat4f(0.0f,1.0f,0.0f,2.35f),
			new Quat4f(0.0f,1.0f,0.0f,3.14f)
		};
		float[] scales={0.2f,0.4f,0.6f,0.4f,0.2f};		
		t3d.setTranslation(new Vector3f(0.0f,1.0f,0.0f));
		Alpha alpha = new Alpha (-1,
                                 Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                                 0, 0, 2000, 0, 1000, 2000, 0, 1000);

        // create position interpolator
        RotPosScalePathInterpolator rotposscalePathInt = new RotPosScalePathInterpolator(alpha, objMove,t3d,knots,quats,positions,scales);
        rotposscalePathInt.setSchedulingBounds(bounds);
//        posPathInt.setStartPosition(-1.0f);
		
		t3d.setTranslation(new Vector3f(-1.0f, 0.0f, -1.0f));
        TransformGroup objMovePos = new TransformGroup(t3d);
        objRoot.addChild(objMovePos);
        objMovePos.addChild(objMove);
		objMove.addChild(new ColorCube(0.2f));
        objRoot.addChild(rotposscalePathInt);
*/
				// create target TransformGroup with Capabilities
/*		TransformGroup objRotate = new TransformGroup();
		objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		// create rotation interpolator
		Alpha alpha = new Alpha (-1,
                                 Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                                 0, 0, 2000, 0, 1000, 2000, 0, 1000);
		float knots[]={0.0f,0.2f,0.4f,0.8f,1.0f};
		
		Quat4f quats[]={
			new Quat4f(0.0f,1.0f,0.0f,0.0f),
			new Quat4f(0.0f,1.0f,0.0f,0.78f),
			new Quat4f(0.0f,1.0f,0.0f,1.57f),
			new Quat4f(0.0f,1.0f,0.0f,2.35f),
			new Quat4f(0.0f,1.0f,0.0f,3.14f)
		};
        RotationPathInterpolator rotInt = new RotationPathInterpolator(alpha, objRotate,t3d,knots,quats);
        rotInt.setSchedulingBounds(bounds);
		objRoot.addChild(rotInt);
		
		t3d.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
		TransformGroup objRotPos = new TransformGroup(t3d);
	    objRoot.addChild(objRotPos);
		objRotPos.addChild(objRotate);
		objRotate.addChild(new ColorCube(0.1));
		
		t3d.setTranslation(new Vector3f(0.5f, 0.0f, 0.0f));
		TransformGroup objRotPosOut = new TransformGroup(t3d);
		objRotPosOut.addChild(new ColorCube(0.1));
		objRotate.addChild(objRotPosOut);
	  
*/
/*     TransformGroup objMove = new TransformGroup();
        objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		float knots[]={0.0f,0.2f,0.4f,0.8f,1.0f};
		Point3f positions[]={
			new Point3f(0.0f,0.0f,0.0f),
			new Point3f(1.0f,1.0f,0.0f),
			new Point3f(2.0f,0.0f,-2.0f),
			new Point3f(1.0f,-1.0f,2.0f),
			new Point3f(0.0f,0.0f,0.0f)
		};
		
		t3d.setTranslation(new Vector3f(0.0f,1.0f,0.0f));
		Alpha alpha = new Alpha (-1,
                                 Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                                 0, 0, 2000, 0, 1000, 2000, 0, 1000);

        // create position interpolator
        PositionPathInterpolator posPathInt = new PositionPathInterpolator(alpha, objMove,t3d,knots,positions);
        posPathInt.setSchedulingBounds(bounds);
//        posPathInt.setStartPosition(-1.0f);
		
		 t3d.setTranslation(new Vector3f(-1.0f, 0.0f, -1.0f));
        TransformGroup objMovePos = new TransformGroup(t3d);
        objRoot.addChild(objMovePos);
        objMovePos.addChild(objMove);
		objMove.addChild(new ColorCube(0.2f));
        objRoot.addChild(posPathInt);
*/		
  

  

  

        Background background = new Background();
        background.setColor(1.0f, 1.0f, 1.0f);
        background.setApplicationBounds(new BoundingSphere());
        objRoot.addChild(background);

	// Let Java 3D perform optimizations on this scene graph.
        objRoot.compile();

	return objRoot;
    }

    // Create a simple scene and attach it to the virtual universe

    public SimpleInterpolator() {
        setLayout(new BorderLayout());
        Canvas3D canvas3D = new Canvas3D(null);
        add("Center", canvas3D);

        BranchGroup scene = createSceneGraph();

        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

	// This will move the ViewPlatform back a bit so the
	// objects in the scene can be viewed.
        simpleU.getViewingPlatform().setNominalViewingTransform();

        simpleU.addBranchGraph(scene);
    }

    //  The following allows this to be run as an application
    //  as well as an applet

    public static void main(String[] args) {
        Frame frame = new MainFrame(new SimpleInterpolator(), 256, 256);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -