📄 container.java
字号:
public class container implements model{
public model[] models;
public polygon3D[] boundary;
public vector centre;
public vector tempCentre;
public boolean visible;
public boolean containBackGround;
public polygon3D[] transparentPolygons;
public container(polygon3D[] boundary, int modelCount){
this.boundary = boundary;
visible = testVisibility();
transparentPolygons = new polygon3D[100];
findCentre();
tempCentre = new vector(0,0,0);
tempCentre.set(centre);
models = new model[modelCount];
}
public void findCentre(){
centre = new vector(0,0,0);
for(int i = 0; i < 6; i++)
centre.add(boundary[i].centre);
centre.scale(1.0/6);
}
public polygon3D[] getPolygon(){
return null;
}
public void update(){
//update centre
tempCentre.set(centre);
tempCentre.subtract(camera.position);
tempCentre.rotate_XZ();
tempCentre.rotate_YZ();
//update boundary
for(int i = 0; i < boundary.length; i++){
boundary[i].update();
}
visible = testVisibility();
if(!visible)
return;
//update inclosed models
for(int i = 0; i < models.length; i++)
models[i].update();
}
public polygon3D[] getBoundary(){
return boundary;
}
public vector getCentre(){
return tempCentre;
}
public void draw(){
if(!visible)
return;
for(int i = 0; i < models.length; i++)
models[i].draw();
for(int i = 0; i < transparentPolygons.length; i++){
if(transparentPolygons[i] == null)
return;
transparentPolygons[i].drawTransparent();
transparentPolygons[i].Texture = gameData.currentWave;
}
}
public void addTransparentPolygon(polygon3D p){
for(int i = 0; i < transparentPolygons.length; i++){
if(transparentPolygons[i] == null){
transparentPolygons[i] = p;
return;
}
}
}
public void sort(){
if(!visible)
return;
int length = models.length;
if(containBackGround) //if the container has a background then dont compare it with the other models
length--; //since it will alwasy be the last one to draw
//sort models according to their postion to the view point
for(int i = 1; i < length; i++){
for(int j = 0; j <length - i; j++){
if(geometry.compareModels(models[j+1],models[j])){
model temp = models[j+1];
models[j+1] = models[j];
models[j] = temp;
}
}
}
for(int i = 0; i < models.length; i++)
models[i].sort();
}
public void addModel(model m){
for(int i = 0; i < models.length; i ++){
if(models[i] == null){
models[i] = m;
return;
}
}
}
public boolean testVisibility(){
boolean inside = true;
vector origin = new vector(0,0,0);
for(int i = 0; i < 6; i++){
if(boundary[i].visible)
return true;
origin.reset();
origin.subtract(boundary[i].centre);
if(origin.dot(boundary[i].normal) > 0)
inside = false;
}
return inside;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -