home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / SPRAY.ZIP / SPRAY.INC < prev    next >
Encoding:
Text File  |  1997-05-23  |  12.0 KB  |  186 lines

  1. // *******************************************************
  2. // LIQUID SPRAY INCLUDE FILE FOR PERSISTENCE OF VISION 3.x
  3. // *******************************************************
  4. //
  5. // Created by Chris Colefax, 23 May 1997
  6. //
  7. // See "Spray.txt" for more information.
  8. //
  9. // *******************************************************
  10.  
  11. // CHECK VERSION
  12. // *************
  13.    #declare _SP_tempver = version #version 3.0
  14.  
  15. // DETERMINE REQUIRED PARAMETERS
  16. // *****************************
  17.    #ifndef (spray_start)    #declare spray_start = 0     #end
  18.    #ifndef (spray_stop)     #declare spray_stop  = 1     #end
  19.    #ifndef (spray_clock)    #declare spray_clock = clock #end
  20.    #ifndef (spray_loop)     #declare spray_loop  = false #end
  21.    #ifndef (flow_rate)      #declare flow_rate   = 1     #end
  22.    #ifndef (particle_life)  #declare _SP_plife   = 1     #else #declare _SP_plife = abs(particle_life) #end
  23.    #ifndef (time_scale)     #declare _SP_tscale  = 1     #else #declare _SP_tscale = abs(time_scale)   #end
  24.    #if     (_SP_tscale = 0) #declare _SP_tscale  = 1     #end
  25.  
  26.    #declare _SP_plife = _SP_plife / _SP_tscale
  27.    #if     (spray_start >= spray_stop) #warning "The spray_start must be less than the spray_stop!  No spray created.\n" #else
  28.    #if     (flow_rate > 0 & (spray_loop != false | (spray_clock > spray_start & spray_clock < spray_stop + _SP_plife)))
  29.  
  30. // DETERMINE TIME PARAMETERS
  31. // *************************
  32.    #ifndef (spray_start_time) #declare _SP_startd = 0 #else #declare _SP_startd = spray_start_time #end
  33.    #ifndef (spray_stop_time)  #declare _SP_stopd  = 0 #else #declare _SP_stopd  = spray_stop_time  #end
  34.    #declare _SP_duration = spray_stop - spray_start
  35.    #if (_SP_startd + _SP_stopd > _SP_duration) #warning "The spray_start_time and spray_stop_time are too large!  The times have been decreased.\n" #declare _SP_startd = .5 #declare _SP_stopd = .5 #end
  36.  
  37. // DETERMINE SPRAY PARAMETERS
  38. // **************************
  39.    #ifndef (spray_location)  #declare _SP_loc       = <0, 0, 0>                            #else #declare _SP_loc  = spray_location * <1, 1, 1>              #end
  40.    #ifndef (spray_direction) #declare _SP_dir       = <0, 1, 0>                            #else #declare _SP_dir  = vnormalize(spray_direction * <1, 1, 1>) #end
  41.    #ifdef  (spray_strength)  #declare _SP_dir       = _SP_dir * spray_strength * flow_rate #end
  42.    #ifndef (wind)            #declare _SP_wind      = <0, 0, 0>                            #else #declare _SP_wind = wind * <1, 1, 1>                        #end
  43.    #ifndef (spray_sky)       #declare _SP_sky       = <0, 1, 0>                            #else #declare _SP_sky  = vnormalize(spray_sky * <1, 1, 1>)       #end
  44.    #ifndef (spray_gravity)   #declare spray_gravity = 9.8                                  #end
  45.    #declare _SP_grav = -_SP_sky * abs(spray_gravity)
  46.  
  47. // CHECK THAT SKY AND DIRECTION ARE DIFFERENT
  48. // ******************************************
  49.    #if (_SP_dir.x != 0 & _SP_sky.x != 0) #declare _SP_cvec = _SP_dir * (_SP_sky.x / _SP_dir.x)
  50.       #else #if (_SP_dir.y != 0 & _SP_sky.y != 0) #declare _SP_cvec = _SP_dir * (_SP_sky.y / _SP_dir.y)
  51.          #else #if (_SP_dir.z != 0 & _SP_sky.z != 0) #declare _SP_cvec = _SP_dir * (_SP_sky.z / _SP_dir.z)
  52.             #else #declare _SP_cvec = _SP_dir #end #end #end
  53.    #if (_SP_sky.x = _SP_cvec.x & _SP_sky.y = _SP_cvec.y & _SP_sky.z = _SP_cvec.z)
  54.       #declare _SP_dir = vrotate(_SP_dir, <1, 1, 1>) #end
  55.    #declare _SP_rotaxis = vnormalize(vcross(_SP_dir, _SP_sky))
  56.  
  57. // DETERMINE PARTICLE PARAMETERS
  58. // *****************************
  59.    #ifndef (particle_count)   #declare particle_count  = 100                                               #end
  60.    #ifndef (particle_size)    #declare _SP_pscale      = <1, 1, 1>                                         #else #declare _SP_pscale = particle_size * <1, 1, 1> #end
  61.    #ifdef  (particle_stretch) #declare _SP_pscale      = _SP_pscale * (z + (<1, 1, 0> / particle_stretch)) #end
  62.    #ifndef (particle_dist)    #declare particle_dist   = 1                                                 #end
  63.    #ifndef (particle_sep)     #declare particle_sep    = 0                                                 #end
  64.    #ifndef (evaporate)        #declare evaporate       = 0                                                 #end
  65.    #ifndef (use_blob)         #declare use_blob        = false                                             #end
  66.    #ifndef (blob_threshold)   #declare blob_threshold  = .5                                                #end
  67.    #ifndef (components_only)  #declare components_only = false                                             #end
  68.  
  69. // DETERMINE NOZZLE PARAMETERS
  70. // ***************************
  71.    #ifndef (nozzle_spin)  #declare nozzle_spin  = 1  #end
  72.    #ifndef (nozzle_angle) #declare nozzle_angle = 20 #end
  73.    #ifndef (nozzle_width) #declare nozzle_width = 0  #end
  74.    #if (nozzle_width != 0) #declare _SP_nozvec = nozzle_width * _SP_rotaxis #end
  75.  
  76. // DETERMINE GROUND PARAMETERS
  77. // ***************************
  78.    #ifndef (ground_plane) #declare ground_plane = false
  79.       #else #if (ground_plane != false)
  80.          #ifndef (ground_dist) #declare ground_dist = 0 #end
  81.          #if (vdot(_SP_loc, _SP_sky) - ground_dist <= 0) #warning "Spray_location is under ground plane!  Ground plane disabled.\n" #declare ground_plane = false #end
  82.          #ifndef (ground_reflection) #declare ground_reflection = .8 #else #declare ground_reflection = abs(ground_reflection) #end
  83.          #ifndef (ground_friction)   #declare ground_friction   = .5 #else #declare ground_friction   = abs(ground_friction)   #end
  84.          #ifndef (max_bounces)       #declare max_bounces       = 1  #else #declare max_bounces       = abs(max_bounces)       #end
  85.          #ifndef (puddle_thickness)  #declare puddle_thickness  = .3 #else #declare puddle_thickness  = abs(puddle_thickness)  #end
  86.          #ifndef (puddle_scale)      #declare puddle_scale      = 1  #end
  87.          #if (_SP_sky.y != 1)
  88.             #declare _SP_wrotx = degrees(atan2(vlength(_SP_sky * <1, 0, 1>), _SP_sky.y))
  89.             #declare _SP_wroty = degrees(atan2(_SP_sky.x, _SP_sky.z))
  90.             #declare _SP_grav  = -y * abs(spray_gravity)
  91.    #end #end #end
  92.  
  93. // DETERMINE TEXTURE PARAMETERS
  94. // ****************************
  95.    #ifndef (spray_texture) #declare spray_texture = texture {pigment {rgb <.6, .7, .8>} finish {phong .3 phong_size 2}} #end
  96.    #ifndef (use_color_map) #ifdef (spray_color_map) #declare use_color_map = true #else #declare use_color_map = false #end #end
  97.    #if (use_color_map != false)
  98.       #ifndef (spray_color_map)
  99.          #warning "You must specify a color_map to texture the spray!\n" #declare use_color_map = false
  100.       #else
  101.          #ifndef (color_map_triangle)   #declare color_map_triangle  = spray_loop #end
  102.          #ifndef (color_map_frequency)  #declare color_map_frequency = 1          #end
  103.          #if (color_map_frequency <= 0) #declare color_map_frequency = 1          #end
  104.    #end #end
  105.  
  106. // DETERMINE TURBULENCE (RANDOMNESS) PARAMETERS
  107. // ********************************************
  108.    #ifndef (spray_turb)  #declare spray_turb = 0                #end
  109.    #ifdef  (spray_seed)  #declare _SP_rand   = seed(spray_seed) #else #declare _SP_rand  = seed(0)                  #end
  110.    #ifndef (scale_turb)  #declare _SP_sturb  = spray_turb       #else #declare _SP_sturb = scale_turb * spray_turb  #end
  111.    #ifndef (angle_turb)  #declare _SP_aturb  = spray_turb       #else #declare _SP_aturb = angle_turb * spray_turb  #end
  112.    #ifndef (spin_turb)   #declare _SP_nturb  = spray_turb       #else #declare _SP_nturb = spin_turb * spray_turb   #end
  113.    #ifndef (vel_turb)    #declare _SP_vturb  = spray_turb       #else #declare _SP_vturb = vel_turb * spray_turb    #end
  114.    #ifndef (color_turb)  #declare _SP_cturb  = spray_turb       #else #declare _SP_cturb = color_turb * spray_turb  #end
  115.    #ifndef (wind_turb)   #declare _SP_wturb  = spray_turb       #else #declare _SP_wturb = wind_turb * spray_turb   #end
  116.  
  117. // CREATE LIQUID SPRAY
  118. // *******************
  119.    #if (use_blob = false) union { #else #if (components_only = false) blob {threshold blob_threshold #end #end
  120.    #if (spray_loop = false) #declare _SP_clock = spray_clock - spray_start #else #declare _SP_clock = spray_clock * _SP_plife * _SP_tscale #end
  121.    #declare _SP_pcount = particle_count * flow_rate
  122.    #declare _SP_count = 0 #while (_SP_count < _SP_pcount)
  123.  
  124. // CREATE SPRAY PARTICLE
  125. // *********************
  126.    #declare _SP_rand1 = rand(_SP_rand) #declare _SP_rand2 = rand(_SP_rand) #declare _SP_rand3 = rand(_SP_rand)
  127.    #declare _SP_pclock = _SP_clock - mod(_SP_clock, _SP_plife) + (_SP_plife * _SP_count / _SP_pcount)
  128.    #if (_SP_pclock > _SP_clock) #declare _SP_pclock = _SP_pclock - _SP_plife #end
  129.    #if (spray_loop != false | (_SP_pclock > 0 & _SP_pclock < _SP_duration))
  130.  
  131. // CALCULATE PARTICLE PARAMETERS
  132. // *****************************
  133.    #declare _SP_psize  = _SP_pscale * (1 + (<_SP_rand1, _SP_rand2, _SP_rand3> - .5) * 2 * _SP_sturb)
  134.    #if (particle_dist != 0) #declare _SP_psize  = _SP_psize * (.1 + pow(_SP_rand2, particle_dist) * .9) #end
  135.    #if (particle_sep   = 0)
  136.       #declare _SP_pangle = nozzle_angle #declare _SP_vel = 1
  137.    #else
  138.       #declare _SP_pangle = nozzle_angle + (1 - _SP_psize.z / _SP_pscale.z) * 30 * particle_sep
  139.       #declare _SP_vel    = 1 + (1 - _SP_psize.z / _SP_pscale.z) * particle_sep
  140.    #end
  141.  
  142.    #if (nozzle_width = 0) #declare _SP_idisp = _SP_loc #else #declare _SP_idisp = _SP_loc + _SP_nozvec * (_SP_rand1 - .5) #end
  143.    #declare _SP_time   = (_SP_clock - _SP_pclock) * _SP_tscale
  144.    #declare _SP_accel  = _SP_grav
  145.  
  146. // CALCULATE INITIAL VELOCITY
  147. // **************************
  148.    #if (spray_loop = false) #switch (_SP_pclock)
  149.       #range (0, _SP_startd) #declare _SP_vel = _SP_vel * pow(sin(pi * .5 * _SP_pclock / _SP_startd), .5) #break
  150.       #range (_SP_duration - _SP_stopd, _SP_duration) #declare _SP_vel = _SP_vel * pow(sin(pi * .5 * - (_SP_pclock - _SP_duration) / _SP_stopd), .5) #break
  151.       #end #end
  152.    #declare _SP_ivel = vaxis_rotate(_SP_dir * _SP_vel * (1 + ((_SP_rand1 - .5) * .5 * _SP_vturb)), _SP_rotaxis, _SP_pangle * .5 * (1 - _SP_rand2 * _SP_aturb))
  153.    #declare _SP_ivel = vaxis_rotate(_SP_ivel, _SP_dir, nozzle_spin * 360 * mod(_SP_pclock, _SP_plife) / _SP_plife + (1 + ((_SP_rand3 - .5) * _SP_nturb)) * 360)
  154.  
  155. // CREATE PARTICLE WITHOUT GROUND PLANE
  156. // ************************************
  157.    #if (ground_plane = false)
  158.       #if (vlength(_SP_wind) > 0) #declare _SP_accel = _SP_accel + vrotate(_SP_wind * _SP_pscale.z / _SP_psize.z, (<_SP_rand1, _SP_rand2, _SP_rand3> - .5) * 360 * _SP_wturb) #end
  159.       #declare _SP_cvel    = _SP_ivel + (_SP_accel * _SP_time)
  160.       #declare _SP_cdisp   = _SP_idisp + (_SP_ivel * _SP_time) + (.5 * _SP_accel * _SP_time * _SP_time)
  161.       #declare _SP_protate = <-degrees (atan2 (_SP_cvel.y, vlength (_SP_cvel * <1,0,1>))), degrees (atan2 (_SP_cvel.x, _SP_cvel.z)), 0>
  162.       #if (evaporate != 0) #declare _SP_psize = _SP_psize * (pow(1 - (_SP_time / _SP_tscale / _SP_plife), evaporate) + .01) #end
  163.  
  164.       sphere {<0, 0, 0>, 1 #if (use_blob != false) , 1 #end
  165.       #if (use_color_map = false)
  166.          #if (components_only != false & use_blob != false)
  167.             texture {spray_texture} #end
  168.       #else texture {spray_texture
  169.          pigment {gradient z color_map {spray_color_map} triangle_wave
  170.             translate (color_map_triangle = false ? .5 : 1) * (spray_loop = false ? _SP_pclock * color_map_frequency / _SP_duration : mod(_SP_pclock * color_map_frequency, _SP_plife) / _SP_plife) + ((_SP_rand3 - .5) * _SP_cturb)
  171.             scale _SP_psize * 1000}} #end
  172.          scale _SP_psize rotate _SP_protate translate _SP_cdisp}
  173.  
  174. // CREATE PARTICLE WITH GROUND PLANE
  175. // *********************************
  176.    #else #include "SprayG.inc" #end
  177.  
  178. // LOOP THROUGH PARTICLES
  179. // **********************
  180.    #else sphere {x * _SP_count, 0 #if (use_blob != false) , 0 #end } #end
  181.    #declare _SP_count = _SP_count + 1 #end
  182.    #if (use_blob != false & components_only != false) #else texture {spray_texture}} #end
  183.  
  184.    #end #end
  185.    #version _SP_tempver
  186.