📄 web3d.java
字号:
import java.applet.*;
import java.awt.*;
class Web3D extends Object3D
{
static final int MAX_AXES = 14;
static final int Z_SPACING = 160;
static final int XROT_SPEED = 8;
static final int YROT_SPEED = 8;
static final int ZROT_SPEED = 8;
static double Object[] = new double[3*7*MAX_AXES];
static int Lines[] = new int[2*6*MAX_AXES + (2*4*(MAX_AXES-1))];
/*static double Object[] = { 120, 0, 0,
60, 0, 0,
0, 0, 0,
-60, 0, 0,
-120, 0, 0};
static int Lines[] = { 0,1, 1,2, 2,3, 3,4};*/
int ScrollPos;
public Web3D(double x, double y, double z, int xr, int yr, int zr)
{
Name = "Web3D";
XPos = x;
YPos = y;
ZPos = z;
XRot = xr;
YRot = yr;
ZRot = zr;
ScrollPos = 0;
InitWeb();
VertNum = Object.length / 3;
LineNum = Lines.length / 2;
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];
}
Visible = true;
}
public void Draw(Graphics g, Matrix3D CameraMatrix)
{
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+ScrollPos);
MyMatrix.Merge(CameraMatrix.GetMatrix());
for (int i=0; i<VertNum; i++)
{
MyMatrix.Transform(Vertices[i]);
Points[i] = Point2D.Projection(Vertices[i]);
}
for (int i=0; i<LineNum; i++)
{
g.setColor(new Color(32,32,210));
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 boolean Handler()
{
ScrollPos -= 8;
if (ScrollPos <= -Z_SPACING)
ScrollPos += Z_SPACING;
/*XRot += XROT_SPEED;
if (XRot >= 360) XRot -= 360;
YRot += YROT_SPEED;
if (YRot >= 360) YRot -= 360;
ZRot += ZROT_SPEED;
if (ZRot >= 360) ZRot -= 360;*/
return true;
}
private void InitWeb()
{
int i = 0;
int j = 0;
int k = 0;
double z = 0;
double y = 0;
for (int l=0; l<MAX_AXES; l++)
{
Object[i++] = 300;
Object[i++] = y-250;
Object[i++] = z;
Object[i++] = 240;
Object[i++] = y;
Object[i++] = z;
Object[i++] = 120;
Object[i++] = y;
Object[i++] = z;
Object[i++] = 0;
Object[i++] = y;
Object[i++] = z;
Object[i++] = -120;
Object[i++] = y;
Object[i++] = z;
Object[i++] = -240;
Object[i++] = y;
Object[i++] = z;
Object[i++] = -300;
Object[i++] = y-250;
Object[i++] = z;
Lines[j++] = k+0;
Lines[j++] = k+1;
Lines[j++] = k+1;
Lines[j++] = k+2;
Lines[j++] = k+2;
Lines[j++] = k+3;
Lines[j++] = k+3;
Lines[j++] = k+4;
Lines[j++] = k+4;
Lines[j++] = k+5;
Lines[j++] = k+5;
Lines[j++] = k+6;
k += 7;
//y -= 0;
z += Z_SPACING;
}
k = 0;
for (int l=0; l<MAX_AXES-1; l++)
{
Lines[j++] = k+0;
Lines[j++] = k+7;
Lines[j++] = k+6;
Lines[j++] = k+13;
Lines[j++] = k+1;
Lines[j++] = k+8;
Lines[j++] = k+5;
Lines[j++] = k+12;
k += 7;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -