📄 ssmbody.java
字号:
import java.awt.*;
public class SSMbody{
public double x, y, z;
public int width, length, height, distanceToGround, distanceToCentre;
public vector centre, normal, gradient, direction2D, direction3D, direction3DCrossNor;
public surface Surface;
public vector[] points;
public paste[] Paste;
public int x_shift, y_shift;
public SSMbody(surface Surface, int xPos, int yPos, int distanceToGround, int distanceToCentre, vector direction2D, int x_shift, int y_shift){
x = xPos;
y = yPos;
width = 16; length = 38; height = 5;
this.distanceToGround = distanceToGround;
this.distanceToCentre = distanceToCentre;
this.direction2D = direction2D;
this.Surface = Surface;
this.x_shift = x_shift;
this.y_shift = y_shift;
direction2D = direction2D.unit();
points = new vector[18];
defindStatus();
}
public void defindStatus(){
double fx = Surface.fx(x,y), fy = Surface.fy(x, y);
z = Surface.evaluate(x,y);
normal = new vector(fx, fy, -1);
normal = normal.unit();
gradient = new vector(fx, fy);
centre = new vector(x, y, z);
direction3D = new vector(direction2D.get_x(), direction2D.get_y(), gradient.dot(direction2D));
direction3D = direction3D.unit();
direction3DCrossNor = direction3D.cross(normal);
direction3DCrossNor = direction3DCrossNor.unit();
addPoints();
}
public void addPoints(){
centre = centre.add(normal.scale(-distanceToGround)).add(direction3D.scale(-distanceToCentre));
points[0] = createPoint(width, length, height);
points[1] = createPoint(width, -length, height);
points[2] = createPoint(-width, length, height);
points[3] = createPoint(-width, -length, height);
points[4] = createPoint(width, length - 8, 0);
points[5] = createPoint(width, -length + 6, 0);
points[6] = createPoint(-width, length - 8, 0);
points[7] = createPoint(-width, -length + 6, 0);
points[8] = createPoint(width, length - 4, height*2 - 1);
points[9] = createPoint(-width, length - 4, height*2 - 1);
points[10] = createPoint(width, length - 20, height*2 - 1);
points[11] = createPoint(-width, length - 20, height*2 - 1);
points[12] = createPoint(width, length - 20, height);
points[13] = createPoint(-width, length - 20, height);
points[14] = createPoint(0, length - 4, height*2 - 1);
points[15] = createPoint(0, length, height);
points[16] = createPoint(width, length - 20, 0);
points[17] = createPoint(-width, length - 20, 0);
paintSurface();
}
public vector createPoint(int w, int l, int h){
return centre.add(direction3DCrossNor.scale(w/2)).add(direction3D.scale(l/2)).add(normal.scale(-h)).subtract(new vector(x_shift, y_shift));
}
public void paintSurface(){
vector[] no1 = new vector[]{points[0], points[2], points[9], points[8]};
paste NO1 = new paste(no1, findCentre(no1), new Color(3, 174, 255), "window");
vector[] no2 = new vector[]{points[10], points[11], points[13], points[12]};
paste NO2 = new paste(no2, findCentre(no2), Color.orange);
vector[] no3 = new vector[]{points[8], points[10], points[16], points[4], points[0]};
paste NO3 = new paste(no3, findCentre(no3), new Color(251, 239, 13));
vector[] no4 = new vector[]{points[16], points[12], points[1], points[5]};
paste NO4 = new paste(no4, findCentre(no4), new Color(251, 239, 13));
vector[] no5 = new vector[]{points[9], points[11], points[17], points[6], points[2]};
paste NO5 = new paste(no5, findCentre(no5), new Color(251, 239, 13));
vector[] no6 = new vector[]{points[17], points[13], points[3], points[7]};
paste NO6 = new paste(no6, findCentre(no6), new Color(251, 239, 13));
vector[] no7 = new vector[]{points[8], points[9], points[11], points[10]};
paste NO7 = new paste(no7, findCentre(no7), new Color(251, 239, 13));
vector[] no8 = new vector[]{points[12], points[13], points[3], points[1]};
paste NO8 = new paste(no8, findCentre(no8), new Color(225,225, 0));
vector[] no9 = new vector[]{points[0], points[2], points[6], points[4]};
paste NO9 = new paste(no9, findCentre(no9), new Color(218, 175, 7));
vector[] no10 = new vector[]{points[1], points[3], points[7], points[5]};
paste NO10 = new paste(no10, findCentre(no10), new Color(218, 175, 7));
Paste = new paste[]{NO1, NO2, NO3, NO4, NO5, NO6, NO7, NO8, NO9, NO10};
}
public void rotate(double angle){
direction2D = direction2D.rotate2D(angle);
direction2D = direction2D.unit();
defindStatus();
}
public void move(double distance){
direction2D = direction2D.unit();
x = x + direction2D.scale(distance).get_x();
y = y + direction2D.scale(distance).get_y();
defindStatus();
}
public vector findCentre(vector[] v){
return v[0].add(v[1]).scale(0.5).add(v[2].add(v[3]).scale(0.5)).scale(0.5);
}
public void shift(int x_shift, int y_shift){
this.x_shift = x_shift;
this.y_shift = y_shift;
addPoints();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -