改め Objective Technician

はぐれ技術者のやりたい放題

ソース前半

2007-10-30 16:20:54 | プログラミング
//**********************************************************************
//PMSimulator                         *
//**********************************************************************
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.applet.*; 
import java.applet.*;
import saiga.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;


class CulcBox{
	Vector<Dpf> dpf = null;
	Vector<Pm> pm = null;
	int ix, iy, iz;

	public CulcBox(int i, int j, int k){
		this.pm = new Vector<Pm>(0);
		this.dpf = new Vector<Dpf>(0);

		this.ix = i;
		this.iy = j;
		this.iz = k;
	}


	boolean pm_comp(Pm pm){

		boolean did_move = true;

		for(int i = -1; i <2 & did_move; i++)
					pm.pos.sub(pm.vector);
					did_move = false;
				}
		}

		return did_move;

	}



	void move(){

		Enumeration e = this.pm.elements();
		while(e.hasMoreElements()){
			Pm tmp = (Pm)e.nextElement();

			tmp.set_vector();
			if(tmp.pm_boundary()) {

				if(this.can_burn(tmp)){
					tmp.radius -= Parameters.s_pm_burn;

					float scale = tmp.radius/(tmp.radius + Parameters.s_pm_burn);
					if(scale > 0.0f)
						tmp.sg.mulScale(new Vector3f(scale, scale, scale));

					if(tmp.radius <= 0.0f){
this.pm.removeElement(tmp); BranchGroup bg = (BranchGroup)tmp.tg.getParent(); bg.detach(); Parameters.pm_num --; } } else{ tmp.pos.add(tmp.vector); tmp.tg.mulTranslation(tmp.vector); if(this.pm_comp(tmp)) this.swap(tmp); } } } } static float distance(Pm pm, Dpf dpf){ return pm.pos.distance(dpf.vertex0) + pm.pos.distance(dpf.vertex1) + pm.pos.distance(dpf.vertex2); } void swap(Pm pm){ int cur_index[] = Parameters.get_index(pm.pos); if(cur_index[0] != this.ix | cur_index[1] != this.iy | cur_index[2] != this.iz){ PMSimulator.culcarray[cur_index[0]][cur_index[1]][cur_index[2]].pm.addElement(pm); this.pm.removeElement(pm); } } boolean can_burn(Pm pm){ boolean touch = false; for(int i = -1; i <2 & !touch; i++) CulcBox.distance(pm, tmp)) touch = true; } return touch; } } class Pm extends MySphere{ static MyTransformGroup pm_tg = null; static Random generator = null; MyTransformGroup tg = null; MyTransformGroup sg = null; float radius; Point3f pos = null; Vector3f vector = null; boolean destination = true; static void pm_init(){ Pm.pm_tg = new MyTransformGroup(); Pm.generator = new Random(); Pm.pm_tg.setCapability(Pm.pm_tg.ALLOW_CHILDREN_EXTEND); Pm.pm_tg.setCapability(Pm.pm_tg.ALLOW_CHILDREN_READ); Pm.pm_tg.setCapability(Pm.pm_tg.ALLOW_CHILDREN_WRITE); } public static void generate_pm(){ float r; Material mat = new Material(); mat.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); for(int i = 0; i <Parameters.s_pm_generate_num; i++){ new Pm(r, mat); } } public Pm(float radius, Material mat){ super(radius, mat, null); this.tg = new MyTransformGroup(); this.sg = new MyTransformGroup(); this.tg.setCapability(MySphere.ALLOW_TRANSFORM_WRITE); this.tg.setCapability(MySphere.ALLOW_TRANSFORM_READ); this.sg.setCapability(MySphere.ALLOW_TRANSFORM_WRITE); this.sg.setCapability(MySphere.ALLOW_TRANSFORM_READ); int index[] = null; do{ this.radius = radius; this.pos = new Point3f((float)Math.random()*Parameters.size_x, 0.0f, (float)Math.random()*Parameters.size_z); index = Parameters.get_index(this.pos); } while(!(PMSimulator.culcarray[index[0]][index[1]][index[2]].pm_comp(this))); this.vector = new Vector3f(); PMSimulator.culcarray[index[0]][index[1]][index[2]].pm.addElement(this); Parameters.pm_num ++; this.sg.addChild(this); this.tg.addChild(this.sg); this.tg.mulTranslation(new Vector3f(this.pos)); BranchGroup newGroup = new BranchGroup(); newGroup.setCapability(MySphere.ALLOW_TRANSFORM_WRITE); newGroup.setCapability(MySphere.ALLOW_TRANSFORM_READ); newGroup.setCapability(BranchGroup.ALLOW_DETACH); newGroup.addChild(tg); Pm.pm_tg.addChild(newGroup); // 追加できる } boolean pm_boundary(){ boolean can_move = true; float destination_x = this.pos.x + this.vector.x; float destination_y = this.pos.y + this.vector.y; float destination_z = this.pos.z + this.vector.z; if(destination_x <= 0.0f | destination_y <= 0.0f | destination_z <= 0.0f | destination_x >= Parameters.size_x | destination_y >= Parameters.size_y | destination_z >= Parameters.size_z) can_move = false; return can_move; } void set_vector(){ double theta = Math.random()*2.0*Math.PI; double phi = Math.random()*2.0*Math.PI; double dx = Parameters.s_pm_diffuse*Math.sin(theta)*Math.cos(phi); double dy = Parameters.s_pm_diffuse*Math.sin(theta)*Math.sin(phi) + Parameters.s_pm_flow; double dz = Parameters.s_pm_diffuse*Math.cos(theta); this.vector.set((float)dx, (float)dy, (float)dz); } }


最新の画像もっと見る

コメントを投稿