📄 floor.java
字号:
import java.awt.*;
// a static black-white floor model
public class floor implements model{
private vector centre;
private vector iDirection, jDirection, kDirection;
private vector[][] vertix;
private paste[] pastes;
private vector[] polygonNormals;
private paste[] boundary;
private int NoOfPolygons;
private vector[][] bound;
private vector realCentre;
public floor(vector centre){
this.centre = centre;
NoOfPolygons = 49;
iDirection = new vector(1,0,0);
jDirection = new vector(0,1,0);
kDirection = new vector(0,0,1);
vertix = new vector[NoOfPolygons][];
pastes = new paste[NoOfPolygons];
createVertix();
makePaste();
}
public void update(vector change, double xzRotate, double yzRotate){
// update the vertix accroding to the camera position and direction
vector[][] tempVertix = new vector[NoOfPolygons][];
for(int i = 0; i < tempVertix.length; i++){
tempVertix[i] = new vector[vertix[i].length];
for(int j = 0; j < tempVertix[i].length; j++){
tempVertix[i][j] = vertix[i][j].add(change).rotate_XZ(xzRotate).rotate_YZ(yzRotate);
}
}
for(int i = 0; i < 49; i++)
pastes[i].update(tempVertix[i]);
}
private void createVertix(){
// must add vertix in a clockwise manner
int polygonIndex = 0;
for(int i = 0; i < 7; i++){
for(int j = 0; j < 7; j++){
vertix[polygonIndex] = new vector[]{put(j*8, 0, 56 - i*8),
put(j*8+8, 0, 56 - i*8),
put(j*8+8, 0, 48 - i*8),
put(j*8, 0, 48 - i*8)};
polygonIndex++;
}
}
}
private vector put(double x, double y, double z){
return centre.add(iDirection.scale(x)).add(jDirection.scale(y)).add(kDirection.scale(z));
}
private void makePaste(){
for(int i = 0; i < 49; i++){
if(i%2 == 0)
pastes[i] = new paste(vertix[i], new Color(70,70,70),3);
else
pastes[i] = new paste(vertix[i], Color.white,3);
}
}
public paste[] getBoundary(){
return boundary;
}
public vector getCentre(){
return realCentre;
}
public paste[] getPolygon(){
return pastes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -