home *** CD-ROM | disk | FTP | other *** search
/ Computerspiele Selbermachen / computerspieleselbermachen.iso / pov / bounc.rta < prev    next >
Text File  |  1994-09-03  |  3KB  |  78 lines

  1. /*
  2.  *  RTAG source file for Bouncing Ball Animation.
  3.  *  Created by Phillip H. Sherrod
  4.  */
  5.  
  6. //  File declarations
  7. bfile "bounc";          // bounc.bat will be the batch driver file
  8. //  Simulation parameters
  9. var numframes = 70;     // Number of frames to generate
  10. var endtime = 26.2;     // Time at end of simulation
  11. var timestep = .05;     // Time for each simulation step
  12. var xstart = -9.2;      // Initial X position of ball.
  13. var g = .6;             // Gravitational acceleration
  14. var drag = .32;         // Frictional drag on slide
  15. var angle = 30;         // Downward angle of the slide
  16. //  Variable declarations
  17. var x;                  // Current x position
  18. var y;                  // Current y position
  19. var xv;                 // X velocity
  20. var yv;                 // Y velocity
  21. var time;               // Current simulated time
  22. var frametime;          // Generate frame after this much time passes
  23. var nextframetime;      // Time when next frame should be displayed
  24. // ----- Executable code -----
  25. //  First time inititlization
  26. // Initial position
  27. x = xstart;
  28. frametime = endtime / numframes;
  29. //  Begin main simulation loop
  30.    for (time=0; time<endtime; time+=timestep) {
  31.     //  See if ball is still on the slide
  32.     if (x <= -5.75) {
  33.         // Ball is still on the slide
  34.         y = 7.43 - (5.75 + x) * tan(angle);
  35.         // Compute next x position
  36.         xv = xv + timestep * g * sin(angle) * drag;
  37.         x = x + timestep * xv;
  38.         //  Compute y velocity
  39.         yv = -xv * sin(angle);
  40.     } else {
  41.         // Ball is in free fall
  42.         //  Apply acceleration to get new speed
  43.         yv = yv - timestep * g;
  44.         //  Compute new ball position
  45.         y = y + timestep * yv;
  46.         //  If ball hit floor, reverse direction & loose energy
  47.         if (y <= 0) {
  48.             printf("Hit floor.  time=`time`,  x=`x`,  y=`y`\n");
  49.             y = 0;
  50.             yv = -.75 * yv;
  51.         }
  52.         //  Compute x position.  Note: x velocity is not changing.
  53.         x = x + timestep * xv;
  54.         //  Don't let ball go past right side of can
  55.         if (x > 8.2) {
  56.             x = 8.2;
  57.         }
  58.     }
  59.     // See if it is time to start a new frame
  60.     if (time >= nextframetime) {
  61.         // Start a new frame
  62.         nextframe;
  63.         //  Print current ball position
  64.         printf("At frame `curframe`, time=`time`, X=`x`, and Y=`y`\n");
  65.         //  Generate commands to create the include file.
  66.         bwrite("echo #declare xpos = `x` > bounc.inc\n");
  67.         bwrite("echo #declare ypos = `y` >> bounc.inc\n");
  68.         //  Generate command to run POV-Ray to render the frame.
  69.         bwrite("call trg320a bounc bounc`###` -mv1.0 -p\n");
  70.         // Remember when next frame should be produced
  71.         nextframetime = curframe * frametime;
  72.     }
  73. //  End of main simulation loop
  74. }
  75. //  Write batch command for end of run processing
  76. epilog;
  77. bwrite("dodta BOUNC\n");
  78.