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

📄 solidobject.java

📁 一个java 3D程序的源代码
💻 JAVA
字号:
public class solidObject implements model{
	public polygon3D[] boundary;
	public polygon3D[] polygons;
	public boolean visible;
	public vector centre;
	public vector tempCentre;
	public boolean sortedPolygons;
	public String moveCode = "";

	/*public solidObject(polygon3D[] boundary){
		this.boundary = boundary;
		visible = testVisibility();
		findCentre();
	}*/

	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 polygons;
	}

	public void update(){
		if(moveCode.equals("cube")){
			cube temp = (cube)this;
			temp.move();
		}else if(moveCode.equals("lamp")){
			tableLamp temp = (tableLamp)this;
			temp.move();
		}else if(moveCode.equals("circle")){
			circle temp = (circle)this;
			temp.move();
		}else if(moveCode.equals("sphere")){
			sphere temp = (sphere)this;
			temp.move();
		}

		for(int i = 0; i < boundary.length; i++){
			boundary[i].update();
		}

		visible = testVisibility();


		if(!visible)
			return;

		tempCentre.set(centre);
		tempCentre.subtract(camera.position);
		tempCentre.rotate_XZ();
		tempCentre.rotate_YZ();

		for(int i = 0; i < polygons.length; i++)
			polygons[i].update();
	}

	public polygon3D[] getBoundary(){
		return boundary;
	}

	public vector getCentre(){
		return tempCentre;
	}

	public void draw(){
		if(!visible)
			return;
		for(int i = 0; i < polygons.length; i++){
			if(polygons[i].visible){
				gallery.visiblePolygon++;
				polygons[i].draw();
			}
		}
	}

	public void sort(){
		if(!visible || sortedPolygons)
			return;

		for(int i = 1; i < polygons.length; i++){
			for(int j = 0; j <polygons.length - i; j++){
				if(geometry.comparePolygons(polygons[j+1],polygons[j])){
					polygon3D temp = polygons[j+1];
					polygons[j+1] = polygons[j];
					polygons[j] = temp;
				}
			}
		}
	}

	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 + -