home *** CD-ROM | disk | FTP | other *** search
/ ANews 3 / AnewsCD3.iso / atari / GRAPHX / POV / 68030.060 / POV31G30 / POVRAY_3.1G / SCENES / ANIMATE / BOING / BOUNCE.POV < prev    next >
Text File  |  1999-10-30  |  2KB  |  66 lines

  1. #declare Gravity=-2*y;
  2. #declare Elastic=0.7;
  3. #declare Time_Delta=0.25;
  4.  
  5. camera {location <0,10.5,-100>  look_at <0,11,0> }
  6.  
  7. light_source {<30, 120, -100> rgb 1}
  8.  
  9. #macro VReplace(V,A,N)
  10.   #local V=(V-V*A)+N*A;
  11. #end
  12.  
  13. #macro V2F(V,A)
  14.  #local T=V*A;
  15.  (T.x+T.y+T.z)
  16. #end
  17.  
  18. #macro Check_Bounce(Pos,Vel,Axis,InOut,Dist)
  19.   #local PosA=V2F(Pos,Axis);            // float position along axis
  20.   #if (((InOut < 0.0 ) & (PosA > Dist)) // Right of right barrier?
  21.        |                                //  or... 
  22.        ((InOut > 0.0 ) & (PosA < Dist)) // left of left barrier?
  23.       ) 
  24.     #local PosA = Dist - (PosA-Dist);   // New position is outside by amount inside
  25.     VReplace(Pos,Axis,PosA)             // Replace new position
  26.     VReplace(Vel,Axis,-Vel*Elastic)     //Reverse velosity along axis
  27.   #end
  28. #end
  29.  
  30. union{
  31.   plane { x, -60 } // left wall
  32.   plane {-x, -60 } // right wall
  33.   plane {-z, -40 } // back wall
  34.   plane { y, -10 } // floor
  35.   pigment {rgb 0.85}
  36. }
  37.  
  38. #if (file_exists("bounce.txt"))
  39.   #fopen Previous "bounce.txt" read
  40.   #read (Previous,Position,Velocity)
  41.   #fclose Previous 
  42. #else
  43.   #declare Position=<-45,40,5>;  // Initial position
  44.   #declare Velocity=<5,1,5>;     // Initial velocity
  45. #end
  46.  
  47. sphere { Position, 10
  48.         pigment { rgb 1}
  49. }
  50.  
  51. #declare NewPos=Position + Velocity*Time_Delta + Gravity/2*Time_Delta*Time_Delta;
  52. #declare NewVel=Velocity + Gravity*Time_Delta;
  53.  
  54. Check_Bounce (NewPos,NewVel,x,+1,-50)
  55. Check_Bounce (NewPos,NewVel,x,-1, 50)
  56. Check_Bounce (NewPos,NewVel,y,+1,  0)
  57. Check_Bounce (NewPos,NewVel,z,-1, 30)
  58. Check_Bounce (NewPos,NewVel,z,+1,-20)
  59.  
  60. #fopen Previous "bounce.txt" write
  61.  
  62. #write (Previous,NewPos,",",NewVel,"\n")
  63.  
  64. #fclose Previous 
  65.  
  66.