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

📄 camera_follow.java

📁 一个java3D的动画程序
💻 JAVA
字号:
/*
 * Created on 2005-7-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package Move;

import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.RotPosPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Quat4f;

import com.sun.j3d.utils.geometry.ColorCube;

/**
 * @author carso
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Camera_follow {
	/*
	 * Camera_follow by Carso
	 * */
	
	
	public BranchGroup create_Camera_follow(TransformGroup obj_transG){
		
		BranchGroup objRoot=new BranchGroup();
		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
			
		/*设置好position[]和knots[]*/
		float j=-50.0f;
		for(int i=0;i<=sections;i++)
		{
			positions[i]=new Point3f(
			j+i,
			2.0f,
			5.0f
			);
			quats[i]=new Quat4f(0.0f,i,0.0f,0.0f);
			knots[i]=i*(1.0f/sections);
		}
		
		Transform3D trans3D=new Transform3D();
		TransformGroup trans1=new TransformGroup();
		trans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		trans3D.rotY(1.57);
		trans1.setTransform(trans3D);
		
		
		//Define PositionPathInterpolator
		//orbitTG is the TransformGroup to which the ViewPlatform is attached
		//PositionPathInterpolator rotOrbitInt = new PositionPathInterpolator(
		RotPosPathInterpolator rotOrbitInt = new RotPosPathInterpolator(
		new Alpha(-1, period),
		trans1, // target
		//obj_transG,
		trans3D, // identity
		knots,
		quats,
		positions);
		rotOrbitInt.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 400.0));
		
		

		//Add the two interpolators to the BranchGroup
		objRoot.addChild(trans1);
		objRoot.addChild(rotOrbitInt);
		trans1.addChild(new ColorCube(0.5));
		trans1.addChild(obj_transG);
		return objRoot;
		}
	
		public Camera_follow(){
				System.out.println("Camera_follow :");
		}
}

⌨️ 快捷键说明

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