// Diffuse1.java Billowing Smoke // Water simulation , Fireworks simulation // Programed by H.Tasaka 1997/10/29/Wed import java.applet.Applet; import java.applet.AudioClip; import java.awt.*; import java.io.*; import java.net.URL; import java.util.StringTokenizer; public class diffuse1 extends Applet { final double RD=0.0174533; /* 3.1415927/180 */ final double RD2=57.295779; /* 180/3.1415927 */ final double PAI=3.1415927; final double PAI2=6.2831854; final int SIZE_X=300; final int SIZE_Y=225; /* --- ball_pram --- */ double srad_r0,srad_r0s,sdens_v0,sdens_v0s; Point3 source0; /* ^^^ time_parm ^^^ */ /* --- time_parm --- */ double start_t,play_t,t_div; int mb_n_max; /* ^^^ time_parm ^^^ */ /* --- velocity_parm --- */ Vec3 Kaze,Jousho,V0,V0_r; /* ^^^ velocity_parm ^^^ */ double v_inc_r=0.0,v_inc_the=0.0,v_inc_phi=0.0,wind_x,wind_y,wind_z, joush_x,joush_y,joush_z,v0_x,v0_y,v0_z,v0r_x,v0r_y,v0r_z, rand_vel,v0_rand,watr_bc,mass=0.0; Smoke_Simulate1 smk_sim; Button b_sus,b_res,b_rstart,b_vrp,b_vrm,b_vpp,b_vtp,b_vpm,b_vtm, b_vst,b_contflm,b_reset; Label lsim_sw,lauto_v,lwind_sped,lwind_x,lwind_y,lwind_z, lobj_sw,l_contflm,l_simtype; Scrollbar swind_x,swind_y,swind_z; TextField tfwind_x,tfwind_y,tfwind_z; Choice c_poly,c_simtype; Point prev; String datafile; Polygon poly; byte poly_sw = 0; byte sim_type=2; AudioClip exp_sound; AudioClip exp_sound2; AudioClip go_sound; AudioClip go_sound2; public void init(){ resize(330,450); setBackground(Color.gray); exp_sound = getAudioClip(getDocumentBase(),"explod.au"); exp_sound2 = getAudioClip(getDocumentBase(),"explod.au"); go_sound = getAudioClip(getDocumentBase(),"go.au"); go_sound2 = getAudioClip(getDocumentBase(),"go.au"); setLayout(null); smk_sim = new Smoke_Simulate1(exp_sound,exp_sound2,go_sound,go_sound2); smk_sim.resize(SIZE_X,SIZE_Y); smk_sim.setBackground(Color.black); add(smk_sim); smk_sim.reshape(15,10,SIZE_X,SIZE_Y); lsim_sw = new Label("Sim SW",Label.CENTER); b_sus = new Button("Halt"); b_res = new Button("Continue"); b_rstart = new Button("Restart"); b_reset = new Button("Reset"); add(lsim_sw); add(b_sus);add(b_res);add(b_rstart);add(b_reset); lsim_sw.reshape(15,SIZE_Y+10,60,17); b_sus.reshape(15,SIZE_Y+25,60,20); b_res.reshape(15,SIZE_Y+48,60,20); b_rstart.reshape(15,SIZE_Y+71,60,20); b_reset.reshape(15,SIZE_Y+94,60,20); lauto_v = new Label("Auto view point move"); b_vrp = new Button("R+");b_vrm = new Button("R-"); b_vpp = new Button("Phi+");b_vpm = new Button("Phi-"); b_vtp = new Button("Th+");b_vtm = new Button("Th-"); b_vst = new Button("Stop"); add(lauto_v);add(b_vrp);add(b_vrm); add(b_vpp);add(b_vpm);add(b_vtp);add(b_vtm);add(b_vst); lauto_v.reshape(80,SIZE_Y+10,125,20); b_vrp.reshape(80,SIZE_Y+30,22,20); b_vrm.reshape(80,SIZE_Y+55,22,20); b_vpp.reshape(145,SIZE_Y+30,32,20); b_vpm.reshape(145,SIZE_Y+55,32,20); b_vtp.reshape(180,SIZE_Y+40,32,20); b_vtm.reshape(108,SIZE_Y+40,32,20); b_vst.reshape(80,SIZE_Y+80,130,20); if(sim_type == 0) lwind_sped = new Label("Velocity of Wind (-2.0~2.0) [m/s]"); else if(sim_type == 1) lwind_sped = new Label("Velocity of Wind(-40.0~40.0)[m/s]"); else if(sim_type == 2) lwind_sped = new Label("Velocity of Wind(-40.0~40.0)[m/s]"); lwind_x = new Label("x");lwind_y = new Label("y"); lwind_z = new Label("z"); swind_x = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); swind_y = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); swind_z = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); tfwind_x = new TextField("",Label.CENTER); tfwind_y = new TextField("",Label.CENTER); tfwind_z = new TextField("",Label.CENTER); add(lwind_sped);add(lwind_x);add(lwind_y);add(lwind_z); add(swind_x);add(swind_y);add(swind_z); add(tfwind_x);add(tfwind_y);add(tfwind_z); lwind_sped.reshape( 15,SIZE_Y+115,200,20); lwind_x.reshape ( 15,SIZE_Y+135, 20, 20); swind_x.reshape ( 35,SIZE_Y+135,180, 17); tfwind_x.reshape(220,SIZE_Y+130, 90, 28); lwind_y.reshape ( 15,SIZE_Y+165, 20, 20); swind_y.reshape ( 35,SIZE_Y+165,180, 17); tfwind_y.reshape(220,SIZE_Y+160, 90, 28); lwind_z.reshape ( 15,SIZE_Y+195, 20, 20); swind_z.reshape ( 35,SIZE_Y+195,180, 17); tfwind_z.reshape(220,SIZE_Y+190, 90, 28); l_contflm = new Label ("Control Panel"); b_contflm = new Button("ConPane"); add(l_contflm);add(b_contflm); l_contflm.reshape(220,SIZE_Y+10,100,17); b_contflm.reshape(220,SIZE_Y+25, 80,20); poly = new Polygon(); lobj_sw = new Label("Object"); c_poly = new Choice(); c_poly.addItem("no obj"); c_poly.addItem("pole"); add(lobj_sw);add(c_poly); lobj_sw.reshape(220,SIZE_Y+47,45,15); c_poly.reshape(220,SIZE_Y+63,100,17); l_simtype = new Label("Sim_type"); c_simtype = new Choice(); c_simtype.addItem("smoke"); c_simtype.addItem("water"); c_simtype.addItem("fireworks"); add(l_simtype);add(c_simtype); l_simtype.reshape(220,SIZE_Y+85, 50,15); c_simtype.reshape(220,SIZE_Y+102,100,17); if (poly_sw == 1){ read_poly(); smk_sim.setPoly(poly_sw,poly); } setNew_smoke(); //setNew_water(); //setNew_fireworks(); smk_sim.start(); } public void stop(){ smk_sim.stop(); } public void setNew_smoke(){ sim_type=0; wind_x=0.04;wind_y=0.40;wind_z=0.0; joush_x=0.0;joush_y=0.0;joush_z=0.0;//joush_z=0.3; v0_x=0.40;v0_y=0.0;v0_z=90.0; v0r_x=0.0;v0r_y=0.0;v0r_z=0.0; rand_vel=1.5;v0_rand = 0.0;watr_bc=0.0;mass=0.5; mb_n_max = 200; tfwind_x.setText(""+(float)wind_x);tfwind_y.setText(""+(float)wind_y); tfwind_z.setText(""+(float)wind_z); int ikaze=(int)((wind_x+2.0)*63.75); //(wind_x+2.0)*255.0/4.0 swind_x.setValue(ikaze); ikaze=(int)((wind_y+2.0)*63.75);swind_y.setValue(ikaze); ikaze=(int)((wind_z+2.0)*63.75);swind_z.setValue(ikaze); smk_sim.setMark(-120.0,120.0,40.0, -120.0,120.0,40.0, -120.0,120.0,40.0); smk_sim.setView(0.0,0.0,0.0,550.0,45.0,10.0, 40.0,30.6,SIZE_X,SIZE_Y); Kaze = new Vec3(wind_x,wind_y,wind_z); Jousho = new Vec3(joush_x,joush_y,joush_z); V0 = new Vec3(v0_x,v0_y,v0_z); V0_r = new Vec3(v0r_x,v0r_y,v0r_z); srad_r0=2.00;srad_r0s=0.090;sdens_v0=1.50;sdens_v0s=-0.008; source0 = new Point3(0.0,0.0,0.0); start_t=0.0;play_t = 240.0;t_div=125; // for smoke smk_sim.setParm(srad_r0,srad_r0s,sdens_v0,sdens_v0s, mb_n_max,start_t,play_t,t_div,source0,v0_rand,watr_bc,sim_type, Kaze,Jousho,V0,V0_r,rand_vel,mass); } public void setNew_water(){ sim_type=1; wind_x=0.0;wind_y=0.0;wind_z=0.0; joush_x=0.0;joush_y=0.0;joush_z=0.0;//joush_z=0.3; v0_x=40.0;v0_y=0.0;v0_z=90.0; v0r_x=0.0;v0r_y=0.0;v0r_z=0.0; rand_vel=0.0;v0_rand = 20.0; watr_bc=0.40;mass=0.0; mb_n_max = 500; tfwind_x.setText(""+(float)wind_x);tfwind_y.setText(""+(float)wind_y); tfwind_z.setText(""+(float)wind_z); int ikaze=(int)((wind_x+2.0)*63.75); //(wind_x+2.0)*255.0/4.0 swind_x.setValue(ikaze); ikaze=(int)((wind_y+2.0)*63.75);swind_y.setValue(ikaze); ikaze=(int)((wind_z+2.0)*63.75);swind_z.setValue(ikaze); smk_sim.setMark(-150.0,150.0,50.0, -150.0,150.0,50.0, -120.0,120.0,50.0); smk_sim.setView(0.0,0.0,0.0,550.0,45.0,10.0, 40.0,30.6,SIZE_X,SIZE_Y); Kaze = new Vec3(wind_x,wind_y,wind_z); Jousho = new Vec3(joush_x,joush_y,joush_z); V0 = new Vec3(v0_x,v0_y,v0_z); V0_r = new Vec3(v0r_x,v0r_y,v0r_z); srad_r0=2.00;srad_r0s=0.090;sdens_v0=1.50;sdens_v0s=-0.008; source0 = new Point3(0.0,0.0,0.0); start_t=0.0;play_t = 30.0;t_div=250; // for water smk_sim.setParm(srad_r0,srad_r0s,sdens_v0,sdens_v0s, mb_n_max,start_t,play_t,t_div,source0,v0_rand,watr_bc,sim_type, Kaze,Jousho,V0,V0_r,rand_vel,mass); } public void setNew_fireworks(){ sim_type=2; wind_x=0.0;wind_y=0.0;wind_z=0.0; joush_x=0.0;joush_y=0.0;joush_z=0.0;//joush_z=0.3; v0_x=60.0;v0_y=0.0;v0_z=90.0; v0r_x=0.0;v0r_y=0.0;v0r_z=0.0; rand_vel=0.0;v0_rand = 20.0; watr_bc=0.0;mass=0.0; mb_n_max = 50; tfwind_x.setText(""+(float)wind_x);tfwind_y.setText(""+(float)wind_y); tfwind_z.setText(""+(float)wind_z); int ikaze=(int)((wind_x+40.0)*3.1875); //(wind_x+40.0)*255.0/80.0 swind_x.setValue(ikaze); ikaze=(int)((wind_y+40.0)*3.1875);swind_y.setValue(ikaze); ikaze=(int)((wind_z+40.0)*3.1875);swind_z.setValue(ikaze); smk_sim.setMark(-150.0,150.0,50.0, -150.0,150.0,50.0, -120.0,120.0,50.0); smk_sim.setView(0.0,0.0,0.0,670.0,0.0,-10.0, 40.0,30.6,SIZE_X,SIZE_Y); Kaze = new Vec3(wind_x,wind_y,wind_z); Jousho = new Vec3(joush_x,joush_y,joush_z); V0 = new Vec3(v0_x,v0_y,v0_z); V0_r = new Vec3(v0r_x,v0r_y,v0r_z); srad_r0=2.00;srad_r0s=0.090;sdens_v0=1.50;sdens_v0s=-0.008; source0 = new Point3(0.0,0.0,-120.0); start_t=0.0;play_t = 30.0;t_div=250; // for water smk_sim.setParm(srad_r0,srad_r0s,sdens_v0,sdens_v0s, mb_n_max,start_t,play_t,t_div,source0,v0_rand,watr_bc,sim_type, Kaze,Jousho,V0,V0_r,rand_vel,mass); smk_sim.setFire(); } public void read_poly(){ int nv,ns; try{ InputStream is = new URL(getDocumentBase(), datafile).openStream(); //InputStream is = new URL(getCodeBase(), datafile).openStream(); DataInputStream dis = new DataInputStream(is); try{ StringTokenizer st; st = new StringTokenizer(dis.readLine()); st = new StringTokenizer(dis.readLine()); nv = Integer.parseInt(st.nextToken()); ns = Integer.parseInt(st.nextToken()); poly = new Polygon(nv,ns); for(int i=0;i < nv;i++){ st = new StringTokenizer(dis.readLine()); poly.vp[i].x = Double.valueOf(st.nextToken()).doubleValue(); poly.vp[i].y = Double.valueOf(st.nextToken()).doubleValue(); poly.vp[i].z = Double.valueOf(st.nextToken()).doubleValue(); } for(int i=0;i < ns;i++){ st = new StringTokenizer(dis.readLine()); poly.sort[i][0] = Integer.parseInt(st.nextToken()); poly.sort[i][1] = Integer.parseInt(st.nextToken()); poly.sort[i][2] = Integer.parseInt(st.nextToken()); poly.sort[i][3] = Integer.parseInt(st.nextToken()); } } catch (IOException e) { System.out.println("Data read err ="); System.err.println("Data read err : Can't access datafile " + datafile); Thread.currentThread().stop(); System.exit(1); } finally { is.close(); } } catch (FileNotFoundException e){ System.err.println("File Not Found " + datafile); Thread.currentThread().stop(); } catch (IOException e){ System.err.println("Closing error"); System.exit(1); } catch (Exception e){ System.err.println("Load datafile error"); } } public boolean action(Event evt,Object obj) { if(evt.target instanceof Button){ if(evt.target == b_sus){ smk_sim.sim_suspend(); } else if(evt.target == b_res){ smk_sim.sim_resume(); } else if(evt.target == b_rstart){ //smk_sim.suspend(); smk_sim.sim_continue(); //smk_sim.resume(); } else if(evt.target == b_vrp){ v_inc_r=3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vrm){ v_inc_r=-3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vpp){ v_inc_phi=3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vpm){ v_inc_phi=-3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vtp){ v_inc_the=3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vtm){ v_inc_the=-3.0; smk_sim.auto_v_move((byte)1,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_vst){ v_inc_r=0.0;v_inc_the=0.0;v_inc_phi=0.0; smk_sim.auto_v_move((byte)0,v_inc_r,v_inc_the,v_inc_phi); } else if(evt.target == b_contflm){ if(smk_sim.get_open_contw_flg() == 0) smk_sim.open_controlwindw(); } else if(evt.target == b_reset){ smk_sim.stop(); if(sim_type == 0){ setNew_smoke(); } else if(sim_type == 1){ setNew_water(); } else if(sim_type == 2){ setNew_fireworks(); smk_sim.sound_stop(); } smk_sim.sim_continue(); smk_sim.start(); } return true; } else if(evt.target instanceof Choice){ String si; if(evt.target == c_poly){ si = c_poly.getSelectedItem(); if(si == "no obj"){ poly_sw = 0; smk_sim.setPoly(poly_sw,poly); } else if(si == "pole"){ poly_sw = 1; datafile = "ench1.pol"; read_poly(); smk_sim.setPoly(poly_sw,poly); } } else if(evt.target == c_simtype){ si = c_simtype.getSelectedItem(); if(si == "smoke"){ smk_sim.stop(); if(sim_type == 2) { smk_sim.delFire(); smk_sim.sound_stop(); } setNew_smoke(); lwind_sped.setText("Velocity of Wind (-2.0~2.0) [m/s]"); smk_sim.sim_continue(); smk_sim.start(); } else if(si == "water"){ smk_sim.stop(); if(sim_type == 2) { smk_sim.delFire(); smk_sim.sound_stop(); } setNew_water(); lwind_sped.setText("Velocity of Wind(-40.0~40.0)[m/s]"); smk_sim.sim_continue(); smk_sim.start(); } else if(si == "fireworks"){ smk_sim.stop(); setNew_fireworks(); lwind_sped.setText("Velocity of Wind(-40.0~40.0)[m/s]"); smk_sim.sim_continue(); smk_sim.start(); } } } return super.action(evt,obj); } public boolean handleEvent(Event evt){ if(evt.target instanceof Scrollbar){ Scrollbar scr = (Scrollbar)evt.target; if(evt.target.equals(swind_x)) { wind_x = -2.0+((double)swind_x.getValue()/63.75); if(sim_type == 1) wind_x=wind_x*20.0; if(sim_type == 2) wind_x=wind_x*20.0; //-> wind_x = -2.0+4.0*((double)swind_x.getValue()/255); tfwind_x.setText(""+(float)wind_x); Kaze = new Vec3(wind_x,wind_y,wind_z); //System.out.println("Kaze "+Kaze.x+" "+Kaze.y+" "+Kaze.x); smk_sim.setWind(Kaze); } else if(evt.target.equals(swind_y)) { wind_y = -2.0+((double)swind_y.getValue()/63.75); if(sim_type == 1) wind_y=wind_y*20.0; if(sim_type == 2) wind_y=wind_y*20.0; tfwind_y.setText(""+(float)wind_y); Kaze = new Vec3(wind_x,wind_y,wind_z); smk_sim.setWind(Kaze); } else if(evt.target.equals(swind_z)) { wind_z = -2.0+((double)swind_z.getValue()/63.75); if(sim_type == 1) wind_z=wind_z*20.0; if(sim_type == 2) wind_z=(wind_z+2.0)*10.0; tfwind_z.setText(""+(float)wind_z); Kaze = new Vec3(wind_x,wind_y,wind_z); smk_sim.setWind(Kaze); } return true; } else if((evt.target instanceof TextField) && (evt.id == Event.ACTION_EVENT)){ int ikaze=0; TextField texf = (TextField)evt.target; if(evt.target.equals(tfwind_x)){ wind_x = Double.valueOf(tfwind_x.getText()).doubleValue(); Kaze = new Vec3(wind_x,wind_y,wind_z); //System.out.println("Kaze "+Kaze.x+" "+Kaze.y+" "+Kaze.x); smk_sim.setWind(Kaze); if(sim_type == 0) ikaze=(int)((wind_x+2.0)*63.75); //(wind_x+2.0)*255.0/4.0 else if(sim_type == 1) ikaze=(int)((wind_x+40.0)*3.1875); //(wind_x+40.0)*255.0/80.0 else if(sim_type == 2) ikaze=(int)((wind_x+40.0)*3.1875); //(wind_x+40.0)*255.0/80.0 swind_x.setValue(ikaze); } else if(evt.target.equals(tfwind_y)){ wind_y = Double.valueOf(tfwind_y.getText()).doubleValue(); Kaze = new Vec3(wind_x,wind_y,wind_z); smk_sim.setWind(Kaze); if(sim_type == 0) ikaze=(int)((wind_y+2.0)*63.75); else if(sim_type == 1) ikaze=(int)((wind_y+40.0)*3.1875); else if(sim_type == 2) ikaze=(int)((wind_y+40.0)*3.1875); swind_y.setValue(ikaze); } else if(evt.target.equals(tfwind_z)){ wind_z = Double.valueOf(tfwind_z.getText()).doubleValue(); Kaze = new Vec3(wind_x,wind_y,wind_z); smk_sim.setWind(Kaze); if(sim_type == 0) ikaze=(int)((wind_z+2.0)*63.75); else if(sim_type == 1) ikaze=(int)((wind_z+40.0)*3.1875); else if(sim_type == 2) ikaze=(int)(wind_z*1.375); swind_z.setValue(ikaze); } return true; } return super.handleEvent(evt); } public boolean mouseDown(Event ev, int x, int y) { prev = new Point(x, y); return true; } public boolean mouseDrag(Event ev, int x, int y) { smk_sim.changeView1(0.0,(double)(x-prev.x),(double)(y-prev.y)); prev.move(x, y); return true; } public boolean mouseUp(Event ev, int x, int y) { prev = null; return true; } } class Smoke_Simulate1 extends Applet implements Runnable { final double RD=0.0174533; /* 3.1415927/180 */ final double RD2=57.295779; /* 180/3.1415927 */ final double PAI=3.1415927; final double PAI2=6.2831854; final int SIZE_X=300; final int SIZE_Y=225; double px_g,py_g; int dvx_g,dvy_g,out0_g; double mark_xmin,mark_xmax,mark_xstp,mark_ymin,mark_ymax,mark_ystp, mark_zmin,mark_zmax,mark_zstp; double viewp_xf,viewp_yf,viewp_zf,viewp_r,viewp_the,viewp_phi, viewp_vthx,viewp_vthy,v_inc_r,v_inc_the,v_inc_phi,rand_vel; int viewp_dwnx,viewp_dwny,v_dispx,v_dispy; byte dcircle_sw,vmove_sw,mark_sw; double wv_time,wx1,wx2,wy1,wy2,sth,cth,cfi,sfi; Smoke_Ball smk[]; Fire firew[]; byte cw_flg=0,sim_type; byte poly_sw; /* --- ball_parm --- */ double srad_r0,srad_r0s,sdens_v0,sdens_v0s,v0_rand,watr_bc,mass; int rand_seed; Point3 source0; int mb_n_max; /* ^^^ ball_parm ^^^ */ /* --- time_parm --- */ double start_t,play_t,t_div; double end_t,end_ft,stp_t; /* ^^^ Parm_time ^^^ */ /* --- velocity_parm --- */ Vec3 Kaze,Jousho,V0,V0_r; /* ^^^ velocity_parm ^^^ */ Image doubleBuffer; Graphics myGC; Thread kick=null; ControlFrame contwindw; Polygon poly; AudioClip exp_sound; AudioClip exp_sound2; AudioClip go_sound; AudioClip go_sound2; boolean contr_flg=false; Smoke_Simulate1(){ } Smoke_Simulate1(AudioClip snd,AudioClip snd2,AudioClip snd3,AudioClip snd4){ contwindw = new ControlFrame(); exp_sound = snd; exp_sound2 = snd2; go_sound = snd3; go_sound2 = snd4; dcircle_sw=0;mark_sw=1; v_dispx=20; v_dispy=10; } public void setMark(double xmin,double xmax,double xstp, double ymin,double ymax,double ystp, double zmin,double zmax,double zstp){ mark_xmin=xmin;mark_xmax=xmax;mark_xstp=xstp; mark_ymin=ymin;mark_ymax=ymax;mark_ystp=ystp; mark_zmin=zmin;mark_zmax=zmax;mark_zstp=zstp; } public void setView(double xf,double yf,double zf, double r,double the,double phi,double vthx,double vthy, int dwnx,int dwny){ viewp_xf=xf;viewp_yf=yf;viewp_zf=zf; viewp_r=r;viewp_the=the;viewp_phi=phi; viewp_vthx=vthx;viewp_vthy=vthy; viewp_dwnx=dwnx;viewp_dwny=dwny; } public void changeView1(double r,double the,double phi){ viewp_r+=r;viewp_the+=the;viewp_phi-=phi; if(viewp_r < 0.) viewp_r =0.0; if(viewp_the >= 360.) viewp_the=0.0; else if(viewp_the < 0.0) viewp_the=360.0; if(viewp_phi >= 360.) viewp_phi=0.0; else if(viewp_phi < 0.0) viewp_phi=360.0; } public void setWind(Vec3 A){ Kaze = new Vec3();Kaze = A; } public void setParm(double r0,double r0s,double v0,double v0s, int n,double st,double pt,double t_d,Point3 s,double vr0, double wbc,byte simt,Vec3 K,Vec3 J,Vec3 V,Vec3 Vr,double rndv, double ms){ Point3 p0,sump; Vec3 smkV0; double dt,vx,vy,vz,vxy,th,phi,th_r,phi_r, costh,cosphi,sinth,sinphi,cpct,cpst,spct,spst; srad_r0=r0;srad_r0s=r0s;sdens_v0=v0;sdens_v0s=v0s; mb_n_max=n;start_t=st;play_t=pt;t_div=t_d; source0 = new Point3();source0=s; end_ft=start_t+play_t; stp_t=play_t/t_div; v0_rand=vr0;watr_bc=wbc;mass=ms; sim_type=simt; Kaze = new Vec3();Kaze = K; Jousho = new Vec3();Jousho = J; V0 = new Vec3();V0 = V; V0_r = new Vec3();V0_r = Vr; rand_vel = rndv; dt=play_t/(double)mb_n_max; smk = new Smoke_Ball[mb_n_max]; th=V0.y*RD;phi=(90.0-V0.z)*RD; costh = Math.cos(th);cosphi = Math.cos(phi); sinth = Math.sin(th);sinphi = Math.sin(phi); cpct=cosphi*costh;cpst=cosphi*sinth; spct=sinphi*costh;spst=sinphi*sinth; for(int cont=0;cont < mb_n_max;cont++){ p0 = new Point3(0.0,0.0,0.0); sump = new Point3(source0.x,source0.y,source0.z); th_r = Math.random()*PAI2; phi_r = (90.0-v0_rand*Math.random())*RD; vxy=V0.x*Math.cos(phi_r); vx=vxy*Math.cos(th_r);vy=vxy*Math.sin(th_r); vz=V0.x*Math.sin(phi_r); smkV0 = new Vec3(vx*cpct-vy*sinth+vz*spct, vx*cpst+vy*costh+vz*spst, -vx*sinphi+vz*cosphi); double b = Math.random(); smk[cont] = new Smoke_Ball(dt*(double)cont,0.0,srad_r0*b, srad_r0s,0.0,sdens_v0,sdens_v0s,0.0,0.0,p0,sump,smkV0); } if(contwindw.open_flg == 1){ contwindw.setParm(V0,V0_r,mb_n_max,srad_r0,srad_r0s, sdens_v0,sdens_v0s,play_t,t_div,dcircle_sw,mark_sw,rand_vel, v0_rand,watr_bc,sim_type,mass); } } public void setFire(){ firew = new Fire[mb_n_max]; for(int i=0;i= 360.) viewp_the=0.0; else if(viewp_the < 0.0) viewp_the=360.0; if(viewp_phi >= 360.) viewp_phi=0.0; else if(viewp_phi < 0.0) viewp_phi=360.0; } } // for(double wv_time } // for (int continue_n kick=null; } void sim_smoke(int cont){ double x,y,z,rsit; x = rand_vel*(-1.0 + Math.random()*2.0); smk[cont].p0.x=(smk[cont].p0.x*0.20 + x*0.80 + Kaze.x + Jousho.x + smk[cont].V0.x); smk[cont].sump.x += smk[cont].p0.x*stp_t; //y = -1.5 + Math.random()*3.0; y = rand_vel*(-1.0 + Math.random()*2.0); smk[cont].p0.y=(smk[cont].p0.y*0.20 + y*0.80 + Kaze.y + Jousho.y + smk[cont].V0.y); smk[cont].sump.y += smk[cont].p0.y*stp_t; //rsit=V0_r.z*smk[cont].spend_t*smk[cont].spend_t; rsit=(1.0-0.5/(0.4995+(0.001*mass)))*9.8*smk[cont].spend_t; //z = -1.5 + Math.random()*3.0; z = rand_vel*(-1.0 + Math.random()*2.0); //smk[cont].p0.z=(smk[cont].p0.z*0.20 + z*0.80 + // Kaze.z + Jousho.z + V0.z); smk[cont].p0.z=(smk[cont].p0.z*0.20 + z*0.80 + Kaze.z + Jousho.z + smk[cont].V0.z - rsit); smk[cont].sump.z += smk[cont].p0.z*stp_t; //System.out.println("test mass"+mass+" smk.sump "+smk[cont].sump.x+" "+ // smk[cont].sump.y+" "+smk[cont].sump.z); //System.out.println("rand_vel "+rand_vel); smk[cont].rad_r = smk[cont].rad_r0+ smk[cont].rad_r0s*smk[cont].spend_t; smk[cont].dens_v = smk[cont].dens_v0+ smk[cont].dens_v0s*smk[cont].spend_t; smk[cont].spend_t = smk[cont].spend_t+stp_t; if(dcircle_sw == 0) uspset3d(smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z,250,250,0); else uscircle3d(smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z,smk[cont].rad_r,250,250,0); } void sim_water(int cont){ double v0,vr,randx,randy,randz,vx,vy,vz; int col_r,col_g,col_b; if(rand_vel > 0.0){ randx=rand_vel*(-1.0 + Math.random()*2.0); randy=rand_vel*(-1.0 + Math.random()*2.0); randz=rand_vel*(-1.0 + Math.random()*2.0); }else{ randx=0.0;randy=0.0;randz=0.0; } vz = smk[cont].V0.z-9.8*smk[cont].spend_t2+Kaze.z+randz; smk[cont].sump.z = smk[cont].sump.z+ vz*stp_t; vx = smk[cont].V0.x+Kaze.x+randx; smk[cont].sump.x = smk[cont].sump.x+ vx*stp_t; vy = smk[cont].V0.y+Kaze.y+randy; smk[cont].sump.y = smk[cont].sump.y+ vy*stp_t; if(smk[cont].sump.z <= mark_zmin){ smk[cont].colflg += 1; smk[cont].V0.z = -(watr_bc)*vz; //smk[cont].V0.x = -(watr_bc)*vx; //smk[cont].V0.y = -(watr_bc)*vy; smk[cont].spend_t2 = 0.0; smk[cont].sump.z = mark_zmin; } smk[cont].rad_r = smk[cont].rad_r0+ smk[cont].rad_r0s*smk[cont].spend_t; smk[cont].dens_v = smk[cont].dens_v0+ smk[cont].dens_v0s*smk[cont].spend_t; if(dcircle_sw == 0){ if(smk[cont].spend_t != 0.0){ if(smk[cont].sump.z > mark_zmin){ if(smk[cont].colflg == 0) { col_r=100;col_g=100;col_b=255; } else { col_r=200;col_g=200;col_b=255; } //if(smk[cont].colflg usline3d(smk[cont].oldp.x,smk[cont].oldp.y,smk[cont].oldp.z, smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z, col_r,col_g,col_b); } // if(smk[cont].sump.z } //if(smk[cont].spend_t } else { if(smk[cont].spend_t != 0.0){ if(smk[cont].sump.z > mark_zmin){ if(smk[cont].colflg == 0) { col_r=100;col_g=100;col_b=255; } else { col_r=200;col_g=200;col_b=255; } //if(smk[cont].colflg uscircle3d(smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z, smk[cont].rad_r,col_r,col_g,col_b); usline3d(smk[cont].oldp.x,smk[cont].oldp.y,smk[cont].oldp.z, smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z, col_r,col_g,col_b); } // if(smk[cont].sump.z } //if(smk[cont].spend_t } //if(dcircle_sw smk[cont].spend_t = smk[cont].spend_t+stp_t; smk[cont].spend_t2 = smk[cont].spend_t2+stp_t; smk[cont].oldp.x = smk[cont].sump.x; smk[cont].oldp.y = smk[cont].sump.y; smk[cont].oldp.z = smk[cont].sump.z; } void sim_fireworks(int cont){ int fcont; double v0,vr,randx,randy,randz,vx,vy,vz; if(smk[cont].spend_t == 0.0) if((cont % 2) == 0) go_sound.play(); else go_sound2.play(); if(smk[cont].colflg == 0){ if(rand_vel > 0.0){ randx=rand_vel*(-1.0 + Math.random()*2.0); randy=rand_vel*(-1.0 + Math.random()*2.0); randz=rand_vel*(-1.0 + Math.random()*2.0); }else{ randx=0.0;randy=0.0;randz=0.0; } vz = smk[cont].V0.z-9.8*smk[cont].spend_t+Kaze.z+randz; smk[cont].sump.z = smk[cont].sump.z+ vz*stp_t; vx = smk[cont].V0.x+Kaze.x+randx; smk[cont].sump.x = smk[cont].sump.x+ vx*stp_t; vy = smk[cont].V0.y+Kaze.y+randy; smk[cont].sump.y = smk[cont].sump.y+ vy*stp_t; if(smk[cont].spend_t != 0.0){ usline3d(smk[cont].oldp.x,smk[cont].oldp.y,smk[cont].oldp.z, smk[cont].sump.x,smk[cont].sump.y,smk[cont].sump.z, firew[cont].col_r,firew[cont].col_g,firew[cont].col_b); } smk[cont].spend_t = smk[cont].spend_t+stp_t; if(smk[cont].oldp.z > smk[cont].sump.z){ smk[cont].colflg = 1; for(fcont=0;fcont < firew[cont].npart;fcont++){ firew[cont].fpart[fcont].oldp.x = smk[cont].sump.x; firew[cont].fpart[fcont].oldp.y = smk[cont].sump.y; firew[cont].fpart[fcont].oldp.z = smk[cont].sump.z; firew[cont].fpart[fcont].oldp2.x = smk[cont].sump.x; firew[cont].fpart[fcont].oldp2.y = smk[cont].sump.y; firew[cont].fpart[fcont].oldp2.z = smk[cont].sump.z; firew[cont].fpart[fcont].sump.x = smk[cont].sump.x; firew[cont].fpart[fcont].sump.y = smk[cont].sump.y; firew[cont].fpart[fcont].sump.z = smk[cont].sump.z; } } } else if(smk[cont].colflg == 1){ if(rand_vel > 0.0){ randx=rand_vel*(-1.0 + Math.random()*2.0); randy=rand_vel*(-1.0 + Math.random()*2.0); randz=rand_vel*(-1.0 + Math.random()*2.0); }else{ randx=0.0;randy=0.0;randz=0.0; } for(fcont=0;fcont < firew[cont].npart;fcont++){ vx=firew[cont].fpart[fcont].V0.x+Kaze.x+randx; firew[cont].fpart[fcont].sump.x += vx*stp_t; vy=firew[cont].fpart[fcont].V0.y+Kaze.y+randy; firew[cont].fpart[fcont].sump.y += vy*stp_t; vz=firew[cont].fpart[fcont].V0.z+Kaze.z+randz -9.8*firew[cont].spend_t; firew[cont].fpart[fcont].sump.z += vz*stp_t; if(firew[cont].spend_t != 0.0){ firew[cont].chagecol(); usline3d(firew[cont].fpart[fcont].oldp2.x, firew[cont].fpart[fcont].oldp2.y,firew[cont].fpart[fcont].oldp2.z, firew[cont].fpart[fcont].sump.x,firew[cont].fpart[fcont].sump.y, firew[cont].fpart[fcont].sump.z,firew[cont].col_r, firew[cont].col_g,firew[cont].col_b); usline3d(firew[cont].fpart[fcont].oldp.x, firew[cont].fpart[fcont].oldp.y,firew[cont].fpart[fcont].oldp.z, firew[cont].fpart[fcont].sump.x,firew[cont].fpart[fcont].sump.y, firew[cont].fpart[fcont].sump.z,firew[cont].col_r, firew[cont].col_g,firew[cont].col_b); } firew[cont].fpart[fcont].oldp2.x=firew[cont].fpart[fcont].oldp.x; firew[cont].fpart[fcont].oldp2.y=firew[cont].fpart[fcont].oldp.y; firew[cont].fpart[fcont].oldp2.z=firew[cont].fpart[fcont].oldp.z; firew[cont].fpart[fcont].oldp.x=firew[cont].fpart[fcont].sump.x; firew[cont].fpart[fcont].oldp.y=firew[cont].fpart[fcont].sump.y; firew[cont].fpart[fcont].oldp.z=firew[cont].fpart[fcont].sump.z; } if(firew[cont].spend_t == 0.0){ if((cont % 2) == 0) exp_sound.play(); else exp_sound2.play(); } firew[cont].spend_t += stp_t; if(firew[cont].spend_t > 3.0) smk[cont].colflg = 2; } smk[cont].oldp.x = smk[cont].sump.x; smk[cont].oldp.y = smk[cont].sump.y; smk[cont].oldp.z = smk[cont].sump.z; } void draw_poly(){ int i1,i2,i3,i4; for(int i=0;i < poly.n_sort;i++){ i1=poly.sort[i][0]-1;i2=poly.sort[i][1]-1; i3=poly.sort[i][2]-1;i4=poly.sort[i][3]-1; usline3d(poly.vp[i1].x,poly.vp[i1].y,poly.vp[i1].z, poly.vp[i2].x,poly.vp[i2].y,poly.vp[i2].z, 80, 80, 80); usline3d(poly.vp[i2].x,poly.vp[i2].y,poly.vp[i2].z, poly.vp[i3].x,poly.vp[i3].y,poly.vp[i3].z, 80, 80, 80); if(i4 == -1){ usline3d(poly.vp[i3].x,poly.vp[i3].y,poly.vp[i3].z, poly.vp[i1].x,poly.vp[i1].y,poly.vp[i1].z, 80, 80, 80); } else { usline3d(poly.vp[i3].x,poly.vp[i3].y,poly.vp[i3].z, poly.vp[i4].x,poly.vp[i4].y,poly.vp[i4].z, 80, 80, 80); usline3d(poly.vp[i4].x,poly.vp[i4].y,poly.vp[i4].z, poly.vp[i1].x,poly.vp[i1].y,poly.vp[i1].z, 80, 80, 80); } } } void check_contpnl(){ if(cw_flg == 0) return; if(contwindw.evt_flg == 1){ if(contwindw.evt_inf == 1){ //Jousho=contwindw.Jousho; V0=contwindw.V0; changeV0(); } else if(contwindw.evt_inf == 2){ mass=contwindw.mass; } else if(contwindw.evt_inf == 3){ if(contwindw.mb_n_max < 2000){ mb_n_max=contwindw.mb_n_max; sim_continue(); } } else if(contwindw.evt_inf == 4){ srad_r0=contwindw.srad_r0; } else if(contwindw.evt_inf == 5){ srad_r0s=contwindw.srad_r0s; } else if(contwindw.evt_inf == 6){ sdens_v0=contwindw.sdens_v0; } else if(contwindw.evt_inf == 7){ sdens_v0s=contwindw.sdens_v0s; /* } else if(contwindw.evt_inf == 8){ if(contwindw.play_t > 0.0){ play_t=contwindw.play_t; sim_continue(); } System.out.println("play_t= "+play_t); } else if(contwindw.evt_inf == 9){ if(t_div > 0.0){ t_div=contwindw.t_div; sim_continue(); } System.out.println("t_div= "+t_div); */ } else if(contwindw.evt_inf ==10){ dcircle_sw=0; sim_continue(); } else if(contwindw.evt_inf ==11){ dcircle_sw=1; sim_continue(); } else if(contwindw.evt_inf ==12){ mark_sw=0; } else if(contwindw.evt_inf ==13){ mark_sw=1; } else if(contwindw.evt_inf ==14){ mark_sw=2; } else if(contwindw.evt_inf ==15){ rand_vel = contwindw.rand_vel; } else if(contwindw.evt_inf ==16){ watr_bc = contwindw.watr_bc; } else if(contwindw.evt_inf ==17){ v0_rand = contwindw.v0_rand; changeV0(); } } contwindw.evt_flg=0;contwindw.evt_inf=0; } void usline3d(double x0,double y0,double z0,double x1,double y1, double z1,int col_r,int col_g,int col_b){ int xx0,yy0,xx1,yy1,out0,out1; out0_g=0; turntrs(x0,y0,z0); convert(); xx0=dvx_g;yy0=dvy_g;out0=out0_g; turntrs(x1,y1,z1); convert(); xx1=dvx_g;yy1=dvy_g;out1=out0_g; /* if((out0 == 0)&&(out1 == 0)){ usline(xx0,yy0,xx1,yy1,col_r,col_g,col_b); } */ myGC.setColor(new Color(col_r,col_g,col_b)); myGC.drawLine(xx0,SIZE_Y-yy0,xx1,SIZE_Y-yy1); } void uspset3d(double x0,double y0,double z0, int col_r,int col_g,int col_b) { out0_g=0; turntrs(x0,y0,z0); convert(); if(out0_g == 0){ myGC.setColor(new Color(col_r,col_g,col_b)); myGC.drawLine(dvx_g,SIZE_Y-dvy_g,dvx_g,SIZE_Y-dvy_g); } } void uscircle3d(double x0,double y0,double z0,double rr, int col_r,int col_g,int col_b) { double a,rd,th,px,py; int out0,ix0,iy0,ix1,iy1,xx,yy; rd=viewp_r/(viewp_r-rr)*rr; a=rd/Math.abs((double)(wx2-wx1)); rd=(double)viewp_dwnx*a; turntrs(x0,y0,z0); convert(); /* printf("circle = %f %f %d %d %f %f \n",px,py,xx,yy,rd,rr); */ if(out0_g == 0){ myGC.setColor(new Color(col_r,col_g,col_b)); myGC.drawOval(dvx_g,SIZE_Y-dvy_g,(int)rd,(int)rd); } } void setscrn_size() { /* -- output viewp_dwny -- */ double a,b,px,py; a=viewp_r*Math.tan(viewp_vthx*.5*RD); b=viewp_r*Math.tan(viewp_vthy*.5*RD); turntrs_vf0(viewp_xf,viewp_yf,viewp_zf,0.0,0.0,0.0,viewp_r); wx1=px_g-a;wx2=py_g+a;wy1=py_g-b;wy2=py_g+b; viewp_dwny=(int)((double)viewp_dwnx*b/a); } void turntrs(double xx1,double yy1,double zz1) { // output px_g,py_g double x,y,z,a,b,c; x=xx1-viewp_xf; y=yy1-viewp_yf; z=zz1-viewp_zf; a=x*cth+y*sth; b=viewp_r-a*cfi-z*sfi; c=viewp_r/b; px_g=(y*cth-x*sth)*c; py_g=(z*cfi-a*sfi)*c; } void turntrs_vf0(double xx1,double yy1,double zz1, double xf,double yf,double zf,double r) { // output px_g,py_g double x,y,z,a,b,c; x=xx1-xf; y=yy1-yf; z=zz1-zf; a=x*cth+y*sth; b=r-a*cfi-z*sfi; c=r/b; px_g=(y*cth-x*sth)*c; py_g=(z*cfi-a*sfi)*c; } void convert() { // input px_g,py_g // output dvx_g,dvy_g,out0_g double a; a=(px_g-wx1)/(wx2-wx1); dvx_g=(int)(.5+(double)viewp_dwnx*a); a=(py_g-wy1)/(wy2-wy1); dvy_g=(int)(.5+(double)viewp_dwny*a); /* printf("dvx = %d,%d\n",*dvx,*dvy); */ out0_g=0; if ((dvx_g < 0) || (dvx_g >= viewp_dwnx)) out0_g=1; if ((dvy_g < 0) || (dvy_g >= viewp_dwny)) out0_g=1; } void write_marking(){ double memr_x,memr_y,memr_z; int isw,col_r,col_g,col_b; if(mark_sw != 0){ if(mark_sw == 1) isw = 2; else isw = 3; memr_z=0.0; for(int i=0;i 0) { usline3d(mark_xmin,0.0,0.0,0.0,0.0,0.0,155,0,0); usline3d(0.0,0.0,0.0,mark_xmax,0.0,0.0,255,100,100); usline3d(0.0,mark_ymin,0.0,0.0,0.0,0.0,0,100,0); usline3d(0.0,0.0,0.0,0.0,mark_ymax,0.0,100,255,100); usline3d(0.0,0.0,mark_zmin,0.0,0.0,0.0,100,100,0); usline3d(0.0,0.0,0.0,0.0,0.0,mark_zmax,255,255,100); } myGC.setColor(Color.white); turntrs(mark_xmin,0.0,0.0);convert(); myGC.drawString("-x",dvx_g,SIZE_Y-dvy_g); turntrs(mark_xmax,0.0,0.0);convert(); myGC.drawString("+x",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,mark_ymin,0.0);convert(); myGC.drawString("-y",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,mark_ymax,0.0);convert(); myGC.drawString("+y",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,0.0,mark_zmin);convert(); myGC.drawString("-z",dvx_g,SIZE_Y-dvy_g); turntrs(0.0,0.0,mark_zmax);convert(); myGC.drawString("+z",dvx_g,SIZE_Y-dvy_g); } } class ControlFrame extends Frame{ public Vec3 V0,V0_r; public byte evt_flg=0; public byte evt_inf=0; public byte open_flg=0; public byte dcircle_sw,mark_sw,sim_type; public int mb_n_max; public double srad_r0,srad_r0s,sdens_v0,sdens_v0s,play_t,t_div, rand_vel,v0_rand,watr_bc,mass; Label l_v0,l_v0_r,l_v0_th,l_v0_phi,l_v0_rand, l_mass,l_randv,l_watr_bc, l_smbt,l_smbnb,l_smbr,l_smbd, l_simt,l_sims,l_simn,l_circsw,l_marksw; Scrollbar s_v0_r,s_v0_th,s_v0_phi,s_v0_rand,s_mass,s_randv, s_watr_bc; TextField tf_v0_r,tf_v0_th,tf_v0_phi, tf_v0_rand,tf_play_t,tf_t_div, tf_smbnb,tf_smbr,tf_smbra,tf_smbd,tf_smbda, tf_mass,tf_randv,tf_watr_bc; CheckboxGroup circgrp,markgrp; Checkbox cwb_on,cwb_off,m_off,m_type1,m_type2; ControlFrame(){ super("Control Window"); } ControlFrame(Vec3 V,Vec3 Vr,int mb_n_max,double r0,double r0s, double v0,double v0s,double plyt,double td,byte dc_sw, byte mk_sw,double rnd,double r0_r,double watr_bc,byte st, double ms){ super("Control Window"); int i = 0; open_flg=1; V0 = new Vec3(V.x,V.y,V.z); V0_r = new Vec3(Vr.x,Vr.y,Vr.z); srad_r0 = r0;srad_r0s=r0s;sdens_v0=v0;sdens_v0s=v0s; play_t=plyt;t_div=td;dcircle_sw=dc_sw;mark_sw=mk_sw; rand_vel=rnd;v0_rand=r0_r;sim_type=st;mass=ms; setLayout(null); l_v0 = new Label(); if(sim_type == 0){ l_v0.setText("Farst velocity Smoke(0.~2.)[m/s] "); } else if (sim_type == 1){ l_v0.setText("Farst velocity Water(0.~60.)[m/s] "); } else if (sim_type == 2){ l_v0.setText("Farst velocity FireWorks(0.~90.)[m/s] "); } l_v0_r = new Label("v");l_v0_th = new Label("th"); l_v0_phi = new Label("phi"); l_v0_rand = new Label("rand"); add(l_v0);add(l_v0_r);add(l_v0_th);add(l_v0_phi); add(l_v0_rand); s_v0_r = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); s_v0_th = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); s_v0_phi = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); s_v0_rand = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); setBackground(Color.blue); add(s_v0_r);add(s_v0_th);add(s_v0_phi);add(s_v0_rand); setBackground(Color.gray); tf_v0_r = new TextField("",Label.CENTER); tf_v0_th = new TextField("",Label.CENTER); tf_v0_phi = new TextField("",Label.CENTER); tf_v0_rand = new TextField("",Label.CENTER); add(tf_v0_r);add(tf_v0_th);add(tf_v0_phi);add(tf_v0_rand); tf_v0_r.setText(""+(float)V0.x); tf_v0_th.setText(""+(float)V0.y); tf_v0_phi.setText(""+(float)V0.z); tf_v0_rand.setText(""+(float)v0_rand); if(sim_type == 0) i=(int)(V0.x*255.0/2.0); else if(sim_type == 1) i=(int)(V0.x*255.0/60.0); else if(sim_type == 2) i=(int)(V0.x*255.0/90.0); s_v0_r.setValue(i); s_v0_th.setValue((int)((V0.y+180.0)*255.0/360.0)); if(sim_type < 2) s_v0_phi.setValue((int)((V0.z+90.0)*255.0/180.0)); else s_v0_phi.setValue((int)(V0.z*255.0/90.0)); if(sim_type == 0) i=(int)(v0_rand*4.25); // (int)(v0_rand*255.0/60.0) else if(sim_type == 1) i=(int)(v0_rand*4.25); // v0_rand i*255./60.0; else if(sim_type == 2) i=(int)(v0_rand*4.25); // v0_rand i*255./60.0; s_v0_rand.setValue(i); int px=15;int py=35; l_v0.reshape (px ,py + 15,250,15); py = 50; l_v0_r.reshape (px ,py + 20, 30,20); l_v0_th.reshape (px ,py + 50, 30,20); l_v0_phi.reshape (px ,py + 80, 30,20); l_v0_rand.reshape (px ,py +110, 55,20); s_v0_r.reshape (px + 35,py + 20,175,17); s_v0_th.reshape (px + 35,py + 50,175,17); s_v0_phi.reshape (px + 35,py + 80,175,17); s_v0_rand.reshape (px + 60,py +110,150,17); tf_v0_r.reshape(px +215,py + 15, 90,28); tf_v0_th.reshape(px +215,py + 45, 90,28); tf_v0_phi.reshape(px +215,py + 75, 90,28); tf_v0_rand.reshape(px +215,py +105, 90,28); l_mass = new Label("Mass of particle [0.0~1.0](smoke)"); if(sim_type == 0) l_randv = new Label("Random velocity of particle [0.0~3.0 (m/s)]"); else if(sim_type ==1) l_randv = new Label("Random velocity of particle [0.0~30.0(m/s)]"); else if(sim_type ==2) l_randv = new Label("Random velocity of particle [0.0~30.0(m/s)]"); add(l_mass);add(l_randv); s_mass = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); s_randv = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); add(s_mass);add(s_randv); tf_mass = new TextField("",Label.CENTER); tf_randv = new TextField("",Label.CENTER); tf_mass.setText(""+(float)mass); tf_randv.setText(""+(float)rand_vel); add(tf_mass);add(tf_randv); i=(int)(mass*255.0);s_mass.setValue(i);//i=(int)(mass*255.0/1.0); //i=(int)((V0_r.z+0.0002)*255.0/0.0004);s_mass.setValue(i); if(sim_type == 0) i=(int)(rand_vel*255.0/3.0); else if(sim_type == 1) i=(int)(rand_vel*255.0/30.0); else if(sim_type == 2) i=(int)(rand_vel*255.0/30.0); s_randv.setValue(i); px=15;py=180; l_mass.reshape(px,py,200,20); l_randv.reshape (px ,py + 43,270,20); s_mass.reshape (px + 35,py + 20,175,17); s_randv.reshape (px + 35,py + 70,175,17); tf_mass.reshape (px +215,py + 15, 90,28); tf_randv.reshape (px +215,py + 62, 90,28); l_smbt = new Label("Smoke ball parameter"); l_smbnb = new Label("Number of ball (max 1999)"); l_smbr = new Label("radius[m],accel[m^2/s]"); l_smbd = new Label("density,d-accel"); add(l_smbt);add(l_smbnb);add(l_smbr);//add(l_smbd); tf_smbnb = new TextField("",Label.CENTER); tf_smbr = new TextField("",Label.CENTER); tf_smbra = new TextField("",Label.CENTER); tf_smbd = new TextField("",Label.CENTER); tf_smbda = new TextField("",Label.CENTER); tf_smbnb.setText(""+mb_n_max); tf_smbr.setText(""+(float)srad_r0); tf_smbra.setText(""+(float)srad_r0s); tf_smbd.setText(""+(float)sdens_v0); tf_smbda.setText(""+(float)sdens_v0s); add(tf_smbnb);add(tf_smbr);add(tf_smbra); //add(tf_smbd);add(tf_smbda); px=15;py=270; l_smbt.reshape (px ,py ,150,20); l_smbnb.reshape (px ,py + 20,150,20); l_smbr.reshape (px ,py + 45,140,20); //l_smbd.reshape (px ,py + 80,135,20); tf_smbnb.reshape(px +170,py + 15, 50,28); tf_smbr.reshape (px +150,py + 45, 50,28); tf_smbra.reshape(px +210,py + 45, 50,28); //tf_smbd.reshape (px +140,py + 85, 85,28); //tf_smbda.reshape(px +270,py + 85, 85,28); /* l_simt = new Label("simulate time");l_sims= new Label("(sec)"); l_simn = new Label("Number of time division"); tf_play_t = new TextField("",Label.CENTER); tf_t_div = new TextField("",Label.CENTER); tf_play_t.setText(""+play_t);tf_t_div.setText(""+t_div); add(l_simt);add(l_sims);add(l_simn);add(tf_play_t);add(tf_t_div); px=15;py=400; l_simt.reshape (px ,py ,150,20); tf_play_t.reshape(px +180,py - 5, 85,28); l_sims.reshape (px +270,py , 85,20); l_simn.reshape (px ,py + 30,150,20); tf_t_div.reshape (px +180,py + 25, 85,28); */ l_watr_bc = new Label("Bound coefficient [0~1.0](water) "); s_watr_bc = new Scrollbar(Scrollbar.HORIZONTAL,0,50,0,255); tf_watr_bc = new TextField("",Label.CENTER); tf_watr_bc.setText(""+(float)watr_bc); //i=(int)(watr_bc*255.0);s_watr_bc.setValue(i); i=(int)(watr_bc*255.0);s_watr_bc.setValue(i); add(l_watr_bc);add(s_watr_bc);add(tf_watr_bc); px=15;py=345; l_watr_bc.reshape (px ,py ,230,20); s_watr_bc.reshape (px + 20,py + 22,175,17); tf_watr_bc.reshape (px +215,py + 20, 90,28); l_circsw = new Label("Circle draw switch"); circgrp = new CheckboxGroup(); cwb_on = new Checkbox("circle_on",circgrp,false); cwb_off = new Checkbox("circle_off",circgrp,true); add(l_circsw);add(cwb_on);add(cwb_off); px=15;py=395; l_circsw.reshape(px ,py ,250,20); cwb_off.reshape (px + 50,py + 20, 90,20); cwb_on.reshape (px +150,py + 20, 90,20); l_marksw = new Label("Marking Switch"); markgrp = new CheckboxGroup(); m_off = new Checkbox("m_off",markgrp,false); m_type1 = new Checkbox("m_type1",markgrp,true); m_type2 = new Checkbox("m_type2",markgrp,false); add(l_marksw);add(m_off);add(m_type1);add(m_type2); px=15;py=435; l_marksw.reshape (px ,py ,250,20); m_off.reshape (px + 50,py + 20, 60,20); m_type1.reshape(px +130,py + 20, 70,20); m_type2.reshape(px +210,py + 20, 70,20); } public void setSimtype(byte type){ sim_type=type; if(open_flg == 1) { if(sim_type == 0){ l_v0.setText("Farst velocity Smoke(0.0~2.0)[m/s] "); l_randv = new Label("Random velocity of particle [0.0~3.0 (m/s)]"); } else if (sim_type == 1){ l_v0.setText("Farst velocity Water(0.0~60.0)[m/s] "); l_randv = new Label("Random velocity of particle [0.0~30.0(m/s)]"); } else if (sim_type == 2){ l_v0.setText("Farst velocity Fireworks(0.0~90.0)[m/s] "); l_randv = new Label("Random velocity of particle [0.0~30.0(m/s)]"); } } } public void setParm(Vec3 V,Vec3 Vr,int mb_n_max,double r0,double r0s, double v0,double v0s,double plyt,double td,byte dc_sw, byte mk_sw,double rnd,double r0_r,double watr_bc,byte st, double ms){ int i=0; V0 = new Vec3(V.x,V.y,V.z); V0_r = new Vec3(Vr.x,Vr.y,Vr.z); srad_r0 = r0;srad_r0s=r0s;sdens_v0=v0;sdens_v0s=v0s; play_t=plyt;t_div=td;dcircle_sw=dc_sw;mark_sw=mk_sw; rand_vel=rnd;v0_rand=r0_r;sim_type=st;mass=ms; if(sim_type == 0) i=(int)(V0.x*255.0/2.0); else if(sim_type == 1) i=(int)(V0.x*255.0/60.0); else if(sim_type == 2) i=(int)(V0.x*255.0/90.0); s_v0_r.setValue(i); s_v0_th.setValue((int)((V0.y+180.0)*255.0/360.0)); if(sim_type < 2) s_v0_phi.setValue((int)((V0.z+90.0)*255.0/180.0)); else s_v0_phi.setValue((int)(V0.z*255.0/90.0)); if(sim_type == 0) i=(int)(v0_rand*85.0); // (int)(v0_rand*255./3.0) else if(sim_type == 1) i=(int)(v0_rand*4.25); // v0_rand i*255./60.0; else if(sim_type == 2) i=(int)(v0_rand*4.25); // v0_rand i*255./60.0; s_v0_rand.setValue(i); tf_v0_r.setText(""+(float)V0.x); tf_v0_th.setText(""+(float)V0.y); tf_v0_phi.setText(""+(float)V0.z); tf_v0_rand.setText(""+(float)v0_rand); s_mass.setValue((int)(mass*213.3)); if(sim_type == 0) i=(int)(rand_vel*255.0/3.0); else if(sim_type == 1) i=(int)(rand_vel*255.0/60.0); else if(sim_type == 2) i=(int)(rand_vel*255.0/60.0); s_randv.setValue(i); tf_mass.setText(""+(float)mass); tf_randv.setText(""+(float)rand_vel); tf_smbnb.setText(""+mb_n_max); tf_smbr.setText(""+(float)srad_r0); tf_smbra.setText(""+(float)srad_r0s); tf_smbd.setText(""+(float)sdens_v0); tf_smbda.setText(""+(float)sdens_v0s); s_watr_bc.setValue((int)(watr_bc*255.0)); tf_watr_bc.setText(""+(float)watr_bc); } public boolean handleEvent(Event evt){ double aa; int i = 0; if(evt.target instanceof Scrollbar){ evt_flg = 1; if (evt.target.equals(s_v0_r)){ evt_inf = 1; if(sim_type == 0) V0.x = 2.0*((double)s_v0_r.getValue()/255.0); else if(sim_type == 1) V0.x = 60.0*((double)s_v0_r.getValue()/255.0); else if(sim_type == 2) V0.x = 90.0*((double)s_v0_r.getValue()/255.0); tf_v0_r.setText(""+(float)V0.x); } else if (evt.target.equals(s_v0_th)){ evt_inf = 1; V0.y = -180.0+360.0*((double)s_v0_th.getValue()/255.0); tf_v0_th.setText(""+(float)V0.y); } else if (evt.target.equals(s_v0_phi)){ evt_inf = 1; if(sim_type < 2) V0.z = -90.0+180.0*((double)s_v0_phi.getValue()/255.0); else V0.z = 90.0*((double)s_v0_phi.getValue()/255.0); tf_v0_phi.setText(""+(float)V0.z); } else if (evt.target.equals(s_mass)){ evt_inf = 2; mass=((double)s_mass.getValue()/255.0); tf_mass.setText(""+(float)mass); } else if (evt.target.equals(s_randv)){ evt_inf = 15; if(sim_type == 0) rand_vel=3.0*((double)s_randv.getValue()/255.0); else if(sim_type == 1) rand_vel=30.0*((double)s_randv.getValue()/255.0); else if(sim_type == 2) rand_vel=30.0*((double)s_randv.getValue()/255.0); tf_randv.setText(""+(float)rand_vel); } else if (evt.target.equals(s_watr_bc)){ evt_inf = 16; watr_bc=(double)s_watr_bc.getValue()/255.0; tf_watr_bc.setText(""+(float)watr_bc); } else if (evt.target.equals(s_v0_rand)){ evt_inf = 17; if(sim_type == 0) v0_rand=3.0*((double)s_v0_rand.getValue()/255.0); else if(sim_type == 1) v0_rand=60.0*((double)s_v0_rand.getValue()/255.0); else if(sim_type == 2) v0_rand=60.0*((double)s_v0_rand.getValue()/255.0); tf_v0_rand.setText(""+(float)v0_rand); } return true; } else if((evt.target instanceof TextField) && (evt.id == Event.ACTION_EVENT)){ evt_flg = 1; if(evt.target.equals(tf_v0_r)){ evt_inf = 1; V0.x = Double.valueOf(tf_v0_r.getText()).doubleValue(); if(sim_type == 0) i=(int)(V0.x*255.0/2.0); else if(sim_type == 1) i=(int)(V0.x*255.0/60.0); else if(sim_type == 2) i=(int)(V0.x*255.0/60.0); s_v0_r.setValue(i); } else if(evt.target.equals(tf_v0_th)){ evt_inf = 1; V0.y = Double.valueOf(tf_v0_th.getText()).doubleValue(); s_v0_th.setValue((int)((V0.y+180.0)*255.0/360.0)); } else if(evt.target.equals(tf_v0_phi)){ evt_inf = 1; V0.z = Double.valueOf(tf_v0_phi.getText()).doubleValue(); if(sim_type < 2) s_v0_phi.setValue((int)((V0.z+90.0)*255.0/180.0)); else s_v0_phi.setValue((int)(V0.z*255.0/90.0)); } else if(evt.target.equals(tf_mass)){ evt_inf = 2; mass = Double.valueOf(tf_mass.getText()).doubleValue(); i=(int)(mass*213.3);s_mass.setValue(i); } else if(evt.target.equals(tf_randv)){ evt_inf = 15; rand_vel = Double.valueOf(tf_randv.getText()).doubleValue(); if(sim_type ==0) i=(int)(rand_vel*255.0/3.0); else if(sim_type == 1) i=(int)(rand_vel*255.0/60.0); else if(sim_type == 2) i=(int)(rand_vel*255.0/60.0); s_randv.setValue(i); } else if(evt.target.equals(tf_smbnb)){ evt_inf = 3; mb_n_max = Integer.valueOf(tf_smbnb.getText()).intValue(); } else if(evt.target.equals(tf_smbr)){ evt_inf = 4; srad_r0 = Double.valueOf(tf_smbr.getText()).doubleValue(); } else if(evt.target.equals(tf_smbra)){ evt_inf = 5; srad_r0s = Double.valueOf(tf_smbra.getText()).doubleValue(); } else if(evt.target.equals(tf_smbd)){ evt_inf = 6; sdens_v0 = Double.valueOf(tf_smbd.getText()).doubleValue(); } else if(evt.target.equals(tf_smbda)){ evt_inf = 7; sdens_v0s = Double.valueOf(tf_smbda.getText()).doubleValue(); /* } else if(evt.target.equals(tf_play_t)){ evt_inf = 8; play_t = Double.valueOf(tf_play_t.getText()).doubleValue(); } else if(evt.target.equals(tf_t_div)){ evt_inf = 9; t_div = Double.valueOf(tf_t_div.getText()).doubleValue(); */ } else if(evt.target.equals(tf_watr_bc)){ evt_inf = 16; watr_bc = Double.valueOf(tf_watr_bc.getText()).doubleValue(); i=(int)(watr_bc*255.0);s_watr_bc.setValue(i); } else if(evt.target.equals(tf_v0_rand)){ evt_inf = 17; v0_rand = Double.valueOf(tf_v0_rand.getText()).doubleValue(); if(sim_type == 0) i=(int)(v0_rand*85.0); else if(sim_type == 1) i=(int)(v0_rand*4.25); else if(sim_type == 2) i=(int)(v0_rand*4.25); //v0_rand*255.0/60.0; s_v0_rand.setValue(i); } return true; } if(evt.id == Event.WINDOW_DESTROY){ open_flg=0; dispose(); } return super.handleEvent(evt); } public boolean action(Event evt,Object obj){ evt_flg = 1; if(evt.target instanceof Checkbox){ String str = ((Checkbox)evt.target).getLabel(); if("circle_off".equals(str)){ evt_inf=10;dcircle_sw=0; } else if("circle_on".equals(str)){ evt_inf=11;dcircle_sw=1; } else if("m_off".equals(str)){ evt_inf=12;mark_sw=0; } else if("m_type1".equals(str)){ evt_inf=13;mark_sw=1; } else if("m_type2".equals(str)){ evt_inf=14;mark_sw=2; } } return true; } } class Smoke_Ball{ public double born_t,rad_r,rad_r0,rad_r0s, dens_v,dens_v0,dens_v0s,spend_t,old_r,th,phi,spend_t2; public Point3 p0,sump,oldp; public Vec3 V0; public byte colflg; Smoke_Ball(){ } Smoke_Ball(double pr0,double pr1,double pr2,double pr3,double pr4, double pr5,double pr6,double pr7,double pr8, Point3 prp0,Point3 prp1,Vec3 V){ born_t=pr0;rad_r=pr1;rad_r0=pr2;rad_r0s=pr3;dens_v=pr4; dens_v0=pr5;dens_v0s=pr6;spend_t=pr7;old_r=pr8; p0 = new Point3();sump = new Point3(prp1.x,prp1.y,prp1.z); V0 = new Vec3(); oldp = new Point3(prp1.x,prp1.y,prp1.z); p0 = prp0;V0=V; double RD=0.0174533;spend_t2=0.0; th = Math.random()*360.0*RD;phi = (90.0-45.0*Math.random())*RD; colflg = 0; } } class Fire{ public Fire_particle fpart[]; public int npart=20; public double spend_t; public int col_r,col_g,col_b; byte col_rsw,col_gsw,col_bsw; Fire(){ fpart = new Fire_particle[npart]; for(int i=0;i 255) col_r=255; if(col_g < 0) col_g=0; else if(col_g > 255) col_g=255; if(col_b < 0) col_b=0; else if(col_b > 255) col_b=255; } } class Fire_particle{ public Point3 p0,sump,oldp,oldp2; public Vec3 V0; Fire_particle(){ double th,phi,vxy; double vr = 30.0; p0 = new Point3(0.0,0.0,0.0);sump = new Point3(0.0,0.0,0.0); oldp = new Point3(0.0,0.0,0.0);oldp2 = new Point3(0.0,0.0,0.0); th = Math.random()*6.2831854; // 2*pi = 6.2831854 phi = Math.random()*6.2831854; vxy = vr*Math.cos(phi); V0 = new Vec3(vxy*Math.cos(th),vxy*Math.sin(th),vr*Math.sin(phi)); } } class Point3{ public double x,y,z; Point3(){ } Point3(double a,double b,double c){ x=a;y=b;z=c; } } class Vec3{ public double x,y,z,ux,uy,uz; Vec3(){ } Vec3(double a,double b,double c){ x=a;y=b;z=c; } } class Polygon { public Point3 vp[]; public int sort[][]; public int n_vp,n_sort; Polygon(){ } Polygon(int nv,int ns){ n_vp = nv;n_sort=ns; vp = new Point3[n_vp]; sort = new int [n_sort][4]; for(int i=0;i