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

📄 text3d.java

📁 空战游戏,来自java2 编程第五版源码
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;

class Text3D
{
	private static final int X = 0;
	private static final int Y = 1;
	private static final int Z = 2;

	static double abc[] = {	-20,	-20,	0,
							0,		-20,	0,
							20,		-20,	0,
	
							-20,	0,		0,
							0,		0,		0,
							20,		0,		0,
	
							-20,	20,		0,
							0,		20,		0,
							20,		20,		0,

							20,		-10,	0,
							20,		10,		0};
	
	static int a[] = {	0,2,	3,5,	0,6,	2,8};
	static int b[] = {	0,6,	0,1,	6,7,	4,9,	4,10,	1,9,	7,10,	3,4};
	static int c[] = {	0,6,	0,2,	6,8};
	static int d[] = {	0,6,	0,1,	1,9,	9,10,	10,7,	7,6};
	static int e[] = {	0,6,	0,2,	3,4,	6,8};
	static int f[] = {	0,6,	0,2,	3,4};
	static int g[] = {	0,6,	0,2,	6,8,	8,5,	5,4};
	static int h[] = {	0,6,	2,8,	3,5};
	static int i[] = {	1,7};
	static int j[] = {	2,8,	8,6,	6,3};
	static int k[] = {	0,6,	3,2,	3,8};
	static int l[] = {	0,6,	6,8};
	static int m[] = {	0,6,	2,8,	0,4,	4,2};
	static int n[] = {	0,6,	2,8,	0,8};
	static int o[] = {	0,6,	0,2,	2,8,	6,8};
	static int p[] = {	0,6,	0,2,	2,5,	5,3};
	static int q[] = {	0,6,	0,2,	2,8,	6,8,	8,4};
	static int r[] = {	0,6,	0,2,	2,5,	5,3,	3,8};
	static int s[] = {	2,0,	0,3,	3,5,	5,3,	5,8,	8,6};
	static int t[] = {	1,7,	0,2};
	static int u[] = {	0,6,	6,8,	8,2};
	static int v[] = {	0,3,	3,7,	7,5,	5,2};
	static int w[] = {	0,6,	6,4,	4,8,	8,2};
	static int x[] = {	0,8,	2,6};
	static int y[] = {	0,4,	2,4,	4,7};
	static int z[] = {	0,2,	2,6,	6,8};
		
	double[] Object;
	int[] Lines;

	Vector3D Vertices[];
	Point2D  Points[];

	int VertNum;
	int LineNum;

	double XPos;
	double YPos;
	double ZPos;

	int XRot = 0;
	int YRot = 0;
	int ZRot = 0;

	double XScale;
	double YScale;
	double ZScale;

	double XShear = 0;
	double YShear = 0;
	
	int XRotAdd;
	int YRotAdd;
	int ZRotAdd;

	public Text3D(String string, double xpos, double ypos, double xscale, double yscale, double zscale, int xrot, int yrot, int zrot)
	{
		if (string.equals("a")) Lines = a;
		if (string.equals("b")) Lines = b;
		if (string.equals("c")) Lines = c;
		if (string.equals("d")) Lines = d;
		if (string.equals("e")) Lines = e;
		if (string.equals("f")) Lines = f;
		if (string.equals("g")) Lines = g;
		if (string.equals("h")) Lines = h;
		if (string.equals("i")) Lines = i;
		if (string.equals("j")) Lines = j;
		if (string.equals("k")) Lines = k;
		if (string.equals("l")) Lines = l;
		if (string.equals("m")) Lines = m;
		if (string.equals("n")) Lines = n;
		if (string.equals("o")) Lines = o;
		if (string.equals("p")) Lines = p;
		if (string.equals("q")) Lines = q;
		if (string.equals("r")) Lines = r;
		if (string.equals("s")) Lines = s;
		if (string.equals("t")) Lines = t;
		if (string.equals("u")) Lines = u;
		if (string.equals("v")) Lines = v;
		if (string.equals("w")) Lines = w;
		if (string.equals("x")) Lines = x;
		if (string.equals("y")) Lines = y;
		if (string.equals("z")) Lines = z;

		Object = abc;

		VertNum = Object.length / 3;
		LineNum = Lines.length / 2;

		XPos = xpos;
		YPos = ypos;
		ZPos = 200;
		
		XScale = xscale;
		YScale = yscale;
		ZScale = zscale;
		
		XRotAdd = xrot;
		YRotAdd = yrot;
		ZRotAdd = zrot;
		
		Vertices = new Vector3D[VertNum];
		Points = new Point2D[VertNum];
		
		for (int i=0; i<VertNum; i++)
		{
			Points[i]   = new Point2D();
			Vertices[i] = new Vector3D();
			
			Vertices[i].x = Object[i*3+X];
			Vertices[i].y = Object[i*3+Y];
			Vertices[i].z = Object[i*3+Z];
		}
	}

	public void Draw(Graphics g, int xadd, int yadd)
	{
		Matrix3D MyMatrix = new Matrix3D();
		
		MyMatrix.RotateZ(ZRot);
		MyMatrix.RotateX(XRot);
		MyMatrix.RotateY(YRot);
		MyMatrix.Scale(XScale,YScale,ZScale);
		MyMatrix.Shear(XShear,YShear);
		MyMatrix.Translate(XPos,YPos,ZPos);
		
		for (int i=0; i<VertNum; i++)
		{
			MyMatrix.Transform(Vertices[i]);
			Points[i] = Point2D.Projection(Vertices[i]);
			Points[i].x += xadd;
			Points[i].y += yadd;
		}
		
		for (int i=0; i<LineNum; i++)
		{
			g.drawLine(Points[Lines[i*2]].x,Points[Lines[i*2]].y,Points[Lines[i*2+1]].x,Points[Lines[i*2+1]].y);
		}
	}

	public void Handler()
	{
		XRot += XRotAdd;
		YRot += YRotAdd;
		ZRot += ZRotAdd;
		if (XRot >= 360) XRot -= 360;
		if (YRot >= 360) YRot -= 360;
		if (ZRot >= 360) ZRot -= 360;
	}
}

⌨️ 快捷键说明

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