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

📄 bakcreateviewgraphand.java

📁 一个java3D的动画程序
💻 JAVA
字号:
/*			
	public BranchGroup createViewGraph(Canvas3D canvas,TransformGroup tg) {
			// All according to cookbook recipe
			BranchGroup objRoot = new BranchGroup();
			View view = new View();
			ViewPlatform viewPlatform = new ViewPlatform();
			//view.setViewPolicy();
			PhysicalBody physicalBody = new PhysicalBody();
			PhysicalEnvironment physicalEnvironment = new PhysicalEnvironment();
			view.addCanvas3D(canvas);
			view.setPhysicalBody(physicalBody);
			view.setPhysicalEnvironment(physicalEnvironment);
			view.attachViewPlatform(viewPlatform);
			
			//The TransformGroup must be inserted into the BranchGraph
			objRoot.addChild(tg);
			
			// Here, the interpolators are defined, that modify tg. tgRot becomes
			// the TransformGroup to which the ViewPlatform is attached.
			
			TransformGroup tgRot = createDynamicTransform(tg, objRoot);
			tgRot.addChild(viewPlatform);
			objRoot.compile();
			return objRoot;
			
	}
	
	public TransformGroup createDynamicTransform (TransformGroup orbitTG, BranchGroup objRoot) {
			
			float radius = 5.0f;
			int sections = 90;
			int period = 10000;
			
			//Array to store the coordinates along the circumpherence
			Point3f[] positions = new Point3f[sections + 1];
			
			//Array containing relative time stamps in the range 0.0..1.0
			//Constant velocity if the scale is linear
			float[] knots = new float[sections + 1];
			Quat4f[] quats = new Quat4f[sections + 1];
			
			//Computing positions and their time stamps. To close the circle, the
			//last point equals the first
			/*以下代码设置是作为围绕一个特定物体(点)旋转的坐标
			for (int i = 0; i <= sections; i++) {
			positions[i] = new Point3f(
					(float)Math.sin(i * 2 * Math.PI / sections) * radius,
					 0.0f,
					(float)Math.cos(i * 2 * Math.PI / sections) * radius
					);
			
			knots[i] = i * (1.0f / sections);
			}
			*/
		
			/*设置好position[]和knots[]*/
	/*
			float j=-52.0f;
			for(int i=0;i<=sections;i++)
			{
				positions[i]=new Point3f(
				j+i,
				3.0f,
				5.0f
				);
				quats[i]=new Quat4f(0.0f,i,0.0f,0.0f);
				knots[i]=i*(1.0f/sections);
			}
			Transform3D orbit_temp=new Transform3D();
			//orbitTG.setTransform(orbit_temp);
			orbit_temp.rotY(1.57);
			//Define PositionPathInterpolator
			//orbitTG is the TransformGroup to which the ViewPlatform is attached
			
			//用PositionPathInterpolator也能实现跟随效果
			//此处实现的是摄象头的移动,要实现物体跟随的效果,物体运动的诡计需要与此处摄象头移动的
			//轨迹吻合
			PositionPathInterpolator rotOrbitInt = new PositionPathInterpolator(
			
			//RotPosPathInterpolator rotOrbitInt = new RotPosPathInterpolator(
			new Alpha(-1, period),
			orbitTG, // target
			orbit_temp, // identity
			knots,
			//quats,
			positions);
			rotOrbitInt.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 400.0));
			
			//Define new TransformGroup and RotationInterpolator
			TransformGroup tgRot = new TransformGroup();
			tgRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
			
			/*
			RotationInterpolator rotYInt = new RotationInterpolator(
			new Alpha(-1, period),
			tgRot
			);
			rotYInt.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0));
			*/
			//Add the two interpolators to the BranchGroup
	/*
			objRoot.addChild(rotOrbitInt);
			//objRoot.addChild(rotYInt);
			//objRoot.addChild(rotYInt);
			
			
			orbitTG.addChild(tgRot);
			
			return tgRot;
			}
		*/	

⌨️ 快捷键说明

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