// AUTO SHOOT copyright September 2000 Rune S. Johansen // While "Fire" is on the turret will keep shooting with certain // intervals in the direction it is pointing. When a projectile // hits something, it will explode. // The scene itself is pretty simple, but it can easily be modified. // For an example, try rendering this file using: +kff50 +kc // User settings #declare Fire = ( clock<0.5 ? on : off ); #declare FireDelay = 4; // time (in frames) between shots #declare ProjectileSpeed = 0.5; // units per frame #declare ExplosionTime = 10; // time (in frames) the explosions take #declare Projectiles = 10; // max number of simultaneous projectiles. #declare TurretLocation = y; #declare TurretDirection = vnormalize( vrotate(z-x,-50*y*cos(clock*2*pi)) +0.3*y*sin(clock*4*pi) ); #declare Object = // object projectiles are tested against union { torus {8, 2} difference { box {<-7,-3,-7>, <7,2,7>} box {<-6,-2,-6>, <6,3,6>} } } // End of user settings. #macro Vectors2Matrix (A,B,C,D) matrix #end #macro Perpendiculize (V1,V2) vnormalize(vcross(vcross(V2,V1),V2)) #end #declare Location = array[Projectiles] #declare Direction = array[Projectiles] #declare Status = array[Projectiles] #if (clock=0) // In the first frame #declare C = 0; #while (C; #declare Direction[C] = <0,0,0>; #declare Status[C] = 0; #declare C = C+1; #end #declare WaitTime = 0; #else // In all frames but the first #include "data.inc" // Check if any projectiles have hit the Object. #declare C = 0; #while ( C0) #declare WaitTime = WaitTime-1; #end // Update projectiles #declare C = 0; #while (C=2&Status[C]<3) // Evolve ecplosion of ecploding projectiles. #declare Status[C] = Status[C]+(1/ExplosionTime); #end #if (Status[C]>=3) // When ecplosion is over, make projectile inactive. #declare Status[C] = 0; #declare Location[C] = <0,0,0>; #declare Direction[C] = <0,0,0>; #end #declare C = C+1; #end #end // Save data to file #fopen data "data.inc" write #write (data,"#declare WaitTime = ",WaitTime,"\n") #write (data,"#declare Location = array[",Projectiles,"] {") #local C = 0; #while (C look_at y } light_source {<1,2,-3>*1000, color 1.0} light_source {<2,3,-1>*1000, color 0.5 shadowless} #declare Texture = texture { pigment { bozo scale 0.1 color_map {[0,color rgb 0.7][1,color rgb 1.0]} } } object {Object texture {Texture}} // Cannon cone { -2*y, 0.3, y, 0.2 texture {Texture} } union { box {-0.3, 0.3} cylinder {0, z, 0.2} texture {Texture} #declare AZ = TurretDirection; #declare AY = Perpendiculize(y,AZ); #declare AX = vcross(AY,AZ); #declare AP = TurretLocation; Vectors2Matrix (AX,AY,AZ,AP) } // Projectiles #declare C = 0; #while (C1) // For exploding projectiles: // ExplosionClock goes from 0 to 1 as the explosion evolves: #declare ExplosionClock = Status[C]-2; sphere { Location[C], 0.1+1.9*ExplosionClock pigment {color <1.0,0.5*ExplosionClock,0.0> transmit ExplosionClock} finish {ambient 1 diffuse 0} no_shadow } #end #declare C = C+1; #end