home *** CD-ROM | disk | FTP | other *** search
/ Ray Tracing Box / RAY_CD.mdf / raytrace / rtag / rtag.doc < prev    next >
Text File  |  1993-07-08  |  95KB  |  2,083 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                      R T A G
  7.  
  8.  
  9.  
  10.                          Ray Tracing Animation Generator
  11.  
  12.                               A "shareware" program
  13.  
  14.  
  15.  
  16.  
  17.                                Phillip H. Sherrod
  18.  
  19.               Member, Association of Shareware Professionals (ASP)
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.            RTAG  is  a  program  to  facilitate  the generation of ray
  28.            traced animations.  RTAG is  not  a  ray  tracing  program;
  29.            rather,   it   enables  you  to  generate  the  appropriate
  30.            position of objects to produce an animation using  the  ray
  31.            tracing   program   of   your   choice.   RTAG  compiles  a
  32.            programming language  designed  for  animation  generation.
  33.            This   programming   language   contains   full  arithmetic
  34.            expressions, conditional control, looping, I/O, and a  rich
  35.            set  of library functions including spline path generation.
  36.            The output of RTAG is a set of files that can  be  used  to
  37.            drive  ray  tracing  programs such as POV-Ray, or other ray
  38.            tracers, to produce an image for each frame.
  39.  
  40.  
  41.  
  42.  
  43.  
  44.                                 Table of Contents
  45.  
  46.  
  47.  
  48.        1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  1
  49.          1.1 Ray Tracing Driver Files  . . . . . . . . . . . . . . . . .  1
  50.          1.2 Files Produced by RTAG  . . . . . . . . . . . . . . . . . .  3
  51.          1.3 Auxiliary Programs  . . . . . . . . . . . . . . . . . . . .  4
  52.  
  53.        2. Running RTAG . . . . . . . . . . . . . . . . . . . . . . . . .  6
  54.          2.1 Command Line Options  . . . . . . . . . . . . . . . . . . .  6
  55.          2.2 The RTAG Animation Control File . . . . . . . . . . . . . .  7
  56.          2.3 Arithmetic and Logical Expressions  . . . . . . . . . . . .  8
  57.            2.3.1 Numeric Constants . . . . . . . . . . . . . . . . . . .  9
  58.            2.3.2 Built-in Constant . . . . . . . . . . . . . . . . . . . 10
  59.          2.4 Built in Functions  . . . . . . . . . . . . . . . . . . . . 10
  60.            2.4.1 Notes on the SPLINE and LINEAR Functions  . . . . . . . 13
  61.  
  62.        3. The Animation Control Language . . . . . . . . . . . . . . . . 15
  63.          3.1 Comments  . . . . . . . . . . . . . . . . . . . . . . . . . 15
  64.          3.2 Basic Statement Syntax  . . . . . . . . . . . . . . . . . . 15
  65.          3.3 Declaration of Variables (The VAR Statatement)  . . . . . . 15
  66.          3.4 Output File Declarations  . . . . . . . . . . . . . . . . . 17
  67.          3.5 Assignment Statement  . . . . . . . . . . . . . . . . . . . 18
  68.          3.6 IF Statement  . . . . . . . . . . . . . . . . . . . . . . . 18
  69.          3.7 WHILE Statement . . . . . . . . . . . . . . . . . . . . . . 19
  70.          3.8 DO Statement  . . . . . . . . . . . . . . . . . . . . . . . 19
  71.          3.9 FOR Statement . . . . . . . . . . . . . . . . . . . . . . . 20
  72.          3.10 BREAK Statement  . . . . . . . . . . . . . . . . . . . . . 20
  73.          3.11 CONTINUE Statement . . . . . . . . . . . . . . . . . . . . 21
  74.          3.12 STOP Statement . . . . . . . . . . . . . . . . . . . . . . 21
  75.          3.13 WRITE Statements . . . . . . . . . . . . . . . . . . . . . 21
  76.          3.14 SUBCHAR Statement  . . . . . . . . . . . . . . . . . . . . 22
  77.          3.15 NEXTFRAME Statement  . . . . . . . . . . . . . . . . . . . 23
  78.          3.16 EPILOG Statement . . . . . . . . . . . . . . . . . . . . . 23
  79.          3.17 Self-continuing Batch Files  . . . . . . . . . . . . . . . 23
  80.          3.18 Auxiliary Data Files . . . . . . . . . . . . . . . . . . . 24
  81.            3.18.1 Opening a File for Reading . . . . . . . . . . . . . . 24
  82.            3.18.2 Creating an Output File  . . . . . . . . . . . . . . . 24
  83.            3.18.3 Closing an Auxiliary File  . . . . . . . . . . . . . . 25
  84.            3.18.4 Reading from an Auxiliary File . . . . . . . . . . . . 25
  85.            3.18.5 Writing to an Auxiliary File . . . . . . . . . . . . . 26
  86.          3.19 Notes About The System Variables . . . . . . . . . . . . . 26
  87.  
  88.        4. Animation And Time Control . . . . . . . . . . . . . . . . . . 28
  89.  
  90.        5. Example Animations . . . . . . . . . . . . . . . . . . . . . . 29
  91.  
  92.        6. Use And Distribution of RTAG . . . . . . . . . . . . . . . . . 30
  93.          6.1 Disclaimer  . . . . . . . . . . . . . . . . . . . . . . . . 31
  94.  
  95.  
  96.  
  97.                                         i
  98.  
  99.        Contents                                                         ii
  100.  
  101.  
  102.        7. Other Software . . . . . . . . . . . . . . . . . . . . . . . . 32
  103.          7.1 Mathplot -- Mathematical Function Plotting Program  . . . . 32
  104.          7.2 Nonlin -- Linear & Nonlinear Statistical Regression . . . . 32
  105.          7.3 TSX-32 -- Multi-User Operating System . . . . . . . . . . . 33
  106.  
  107.        8. Software Order Form  . . . . . . . . . . . . . . . . . . . .  35
  108.  
  109.        Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  36
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.                                     Chapter 1
  117.  
  118.                                   Introduction
  119.  
  120.  
  121.  
  122.  
  123.        An animation is  composed  of  a  sequence  of  individual  images,
  124.        called  "frames,"  which are displayed rapidly to give the illusion
  125.        of motion.  Anyone who sets out to create an  animation  must  deal
  126.        with  two  design  issues:  (1)  the  generation of the basic scene
  127.        (objects, colors, lights, etc.), and (2) the changing  position  of
  128.        the  objects  between  frames.  RTAG deals with the second of these
  129.        issues -- object motion.  The first issue, basic scene  design  and
  130.        rendering,  is carred out by the ray tracing program of your choice
  131.        (POV-Ray, Polyray, BOB, etc.).
  132.  
  133.        RTAG reads an animation control file that you create and  generates
  134.        one  or more files that automate the rendering of individual frames
  135.        and the construction of  the  animation  sequence.   The  animation
  136.        control file is the focus of this manual.
  137.  
  138.        RTAG  implements  an animation language with a syntax similar to C.
  139.        Although simple in comparison to full featured languages such as  C
  140.        and  Pascal,  the  RTAG  language is far from trivial.  It provides
  141.        full arithmetic and logical expressions, control  statements  (IF),
  142.        loop  statement  (FOR,  WHILE,  and  DO),  a  rich  set  of library
  143.        functions (trig, log, roots,  spline,  etc.),  and  statements  for
  144.        writing  commands  to  the  output  files  which  will  be  used to
  145.        generate the frames.  Using  the  RTAG  language  you  can  perform
  146.        realistic  simulations of physical processes such as accelerations,
  147.        falling objects, and interactions between objects.  RTAG  also  can
  148.        be used as a general purpose programming language.
  149.  
  150.  
  151.        1.1 Ray Tracing Driver Files
  152.  
  153.        The  basic  purpose of RTAG is to produce a set of files which will
  154.        cause ray tracing programs such as POV-Ray,  Polyray,  Vivid,  BOB,
  155.        and  other  ray  tracers  to generate the sequence of frames for an
  156.        animation.
  157.  
  158.        All ray tracers accept some  sort  of  scene  description  file  in
  159.        which  you  specify  the  position  of  objects,  colors, textures,
  160.        camera angle, etc.  With rare exeception, one run of a  ray  tracer
  161.        with  one  scene  description produces one image file.  In order to
  162.        produce an animation you must run the  ray  tracer  once  for  each
  163.        frame  and  vary  the position of the objects and/or camera between
  164.        frames to produce the illusion of  motion.   This  means  that  the
  165.        scene   description   file   must  be  different  for  each  frame.
  166.  
  167.  
  168.                                         1
  169.  
  170.        Chapter 1. Introduction                                           2
  171.  
  172.  
  173.        Fortunately, all good ray tracers provide a facility for  including
  174.        one  or more external files while processing the scene description.
  175.        In the case of POV-Ray this is  accomplished  with  the  "#include"
  176.        statement.   Other  tracers  have  similar  statements.  Using this
  177.        facility you can have a common scene  description  file  and  place
  178.        only  the commands to describe the positions of moving objects in a
  179.        separate  file  that  is  included  in  the  scene.   For  example,
  180.        consider this simple POV-Ray scene description file:
  181.  
  182.            #include "colors.inc"
  183.            #include "shapes.inc"
  184.            #include "move.inc"
  185.            camera {
  186.                location <.5 1 -22> direction <0 0 1.5>
  187.                up <0 1 0> right <1.33 0 0> look_at <0 4 0>
  188.            }
  189.            object { light_source { <6 15 -4> color White} }
  190.            object {
  191.                sphere { <xpos ypos 0> .5}
  192.                texture { color red .9 green 0 blue .1 ambient .8 }
  193.            }
  194.  
  195.        This  scene  has  a camera, a single light source, and a ball.  The
  196.        position of the ball is specified as "<xpos ypos 0>" but note  that
  197.        xpos  and  ypos are not defined in the file.  Rather, the values of
  198.        xpos and ypos are defined in a separate file named "move.inc"  that
  199.        in  included  in this scene.  Typical statements in move.inc are as
  200.        follows:
  201.  
  202.            #declare xpos = 3
  203.            #declare ypos = 4
  204.  
  205.        To simulate motion  of  the  ball  you  would  prepare  a  separate
  206.        move.inc  file for each frame with slightly altered values for xpos
  207.        and ypos.  Since there will be an  include  file  for  each  frame,
  208.        they  are  typically  given names containing the frame numbers such
  209.        as "MOVE001.INC", "MOVE002.INC", etc.  A primary  purpose  of  RTAG
  210.        is to automate the generation of these include files.
  211.  
  212.        In  addition  to  a  scene  description file and a separate include
  213.        file for each frame, you also need a DOS batch file  to  cause  the
  214.        ray  tracing program to be run for each frame.  RTAG also helps you
  215.        produce this file.
  216.  
  217.        For each frame, the batch file will  contain  commands  to  perform
  218.        the  following  operations:  (1)  make the appropriate include file
  219.        the current  include  file  for  the  next  image  generation;  (2)
  220.        execute  the ray tracing program which will generate an image based
  221.        on  frame-dependent  data  in  the  current   include   file;   (3)
  222.        additional  commands  to delete intermediate files or pack together
  223.        the frame files.  Typical commands written to the batch file for  a
  224.        frame are:
  225.  
  226.            COPY MOVE001.INC MOVE.INC
  227.            POVRAY +iMOVE.POV +oMOVE.TGA
  228.  
  229.        Chapter 1. Introduction                                           3
  230.  
  231.  
  232.        Rather  than  having  RTAG produce a separate include file for each
  233.        frame (which can end up being a lot of files), it is also  possible
  234.        to  write  commands  to the batch file to cause the include file to
  235.        be created just before it is needed by  the  ray  tracing  program.
  236.        To  do  this,  use  the  DOS  ECHO command with the ">" redirection
  237.        operator  to  create  the  file  and  the  ">>"  operator  to   add
  238.        additional  commands  to  the file.  The following is an example of
  239.        commands that create an include  file  named  MOVE.INC,  write  two
  240.        commands into it, and then call POV-Ray to render the image:
  241.  
  242.            ECHO #declare xpos = 2.5 > move.inc
  243.            ECHO #declare ypos = 8.6 >> move.inc
  244.            POVRAY +iMOVE.POV +oMOVE.TGA
  245.  
  246.        Note  that  the  ">"  redirection operator creates a new file so it
  247.        should be used with the first ECHO command  for  each  frame.   The
  248.        ">>"  redirection  operator  appends  to  the  end  of a file so it
  249.        should be used for additional ECHO commands for the frame.
  250.  
  251.        To summarize, there are two methods for producing the include  file
  252.        for  a  frame: (1) have RTAG generate a separate file with a unique
  253.        name that is copied (or renamed) to the name used by  the  #include
  254.        statement;  or  (2) use ECHO commands in the batch file to generate
  255.        the include file just before invoking the ray tracing  program  for
  256.        the frame.
  257.  
  258.  
  259.        1.2 Files Produced by RTAG
  260.  
  261.        Include  files  --  If  you  wish  to have RTAG generate a separate
  262.            include file for each frame, you must use an OFILE  command  to
  263.            declare  the  file name.  The name must include one or more '#'
  264.            characters which are replaced by the frame number  to  generate
  265.            the   actual   include  file  name.   The  NEXTFRAME  statement
  266.            increments the frame number and opens  the  next  include  file
  267.            being  created.   OWRITE commands are used to write information
  268.            to the currently open include file.
  269.  
  270.            If you create the include file by writing ECHO commands to  the
  271.            batch  file,  then  you  will  NOT  use  the  OFILE  and OWRITE
  272.            statements which cause RTAG  to  generate  a  separate  include
  273.            file for each frame.
  274.  
  275.        Batch  file  --  This  is  a  DOS  batch (.BAT) file containing the
  276.            commands to perform the following operations for each frame:
  277.  
  278.            1.  make the appropriate include file the current include  file
  279.                for  the  next  image  generation  (or generate the include
  280.                file);
  281.  
  282.            2.  execute the ray tracing  program  which  will  generate  an
  283.                image  based on frame-dependent data in the current include
  284.                file;
  285.  
  286.        Chapter 1. Introduction                                           4
  287.  
  288.  
  289.            3.  additional commands to delete intermediate  files  or  pack
  290.                together  the  frame  files.  Use BWRITE statements in your
  291.                control file  to  write  to  the  batch  file.   The  BFILE
  292.                statement  declares  the name of the batch file.  This file
  293.                is  not  created  unless  you  use  the  BFILE  and  BWRITE
  294.                commands.
  295.  
  296.        Auxiliary  files -- RTAG includes statements for opening, creating,
  297.            reading from, and writing to auxiliary files.  Auxiliary  input
  298.            files  can  be  used  to  transfer  animation  data  from other
  299.            programs to RTAG.  One use of an auxiliary output  file  is  to
  300.            store  the  names of the generated targa or GIF files so that a
  301.            subsequent program such as DTA can read this file to  determine
  302.            which files to string together in the final animation file.
  303.  
  304.        Listing  file  --  This  file  has  the  same name as the animation
  305.            control file but an extension of ".LST".  It contains the  same
  306.            output  displayed  by  RTAG  on  the screen during an animation
  307.            generation run.  You  can  use  PRINT  statements  within  your
  308.            control  file  to  write  output  to the screen and the listing
  309.            file.
  310.  
  311.  
  312.        1.3 Auxiliary Programs
  313.  
  314.        RTAG is one component in the set of programs needed to produce  and
  315.        display  an  animation.   In  addition  to  RTAG  you will need the
  316.        following programs:
  317.  
  318.        Ray Tracing Program -- There  are  several  excellent  ray  tracing
  319.            programs  available  as  freeware or shareware.  Three programs
  320.            with which I am familiar are POV-Ray (freeware) by  Drew  Wells
  321.            and  the  POV team (CompuServe 73767,1244); Polyray (shareware)
  322.            by Alexander R.  Enzmann (CompuServe 70323,2461);  and  BOB  by
  323.            Christopher  Watkins,  Stephen  Coy,  and Mark Finlay (included
  324.            with the excellent book "Photorealism and Ray Tracing in C").
  325.  
  326.        GIF generator -- Most ray tracing  programs  output  "targa"  files
  327.            which  contain  higher  resolution  images  than usually can be
  328.            displayed.  These targa files must be  converted  into  GIF  or
  329.            other  image  formats  before  they can be displayed.  One fine
  330.            freeware program  for  doing  this  is  Piclab  by  Lee  Daniel
  331.            Crocker and the Stone Soup Group (CompuServe 73407,2030).
  332.  
  333.        Scene  viewer  -- When designing a scene you will need a program to
  334.            display the TGA or GIF file for  an  individual  frame  of  the
  335.            animation.   There  are  many programs available to do this.  A
  336.            popular shareware choice is  CSHOW  by  Bob  Berry  (CompuServe
  337.            76555,167).
  338.  
  339.        Animation  sequencer  -- Once the individual frame images have been
  340.            generated, they must be combined into a single  file  that  can
  341.            be  displayed  rapidly.   A  shareware  program which I use for
  342.            this is DTA by David K.  Mason  (CompuServe  76546,1321).   DTA
  343.            reads  the  targa  or  GIF files produced by the ray tracer and
  344.  
  345.        Chapter 1. Introduction                                           5
  346.  
  347.  
  348.            produces a .FLI (flick)  file  that  can  be  displayed  as  an
  349.            animation.
  350.  
  351.        Animation  display  --  This  program  reads the finished animation
  352.            file and displays it  on  your  screen.   A  popular  shareware
  353.            program  for  displaying  .FLI  files  is PLAY.EXE by Trilobyte
  354.            (CompuServe 72330,3276).
  355.  
  356.        These  programs,  and  many  others  related  to  ray  tracing  and
  357.        animation,  are  available  in  the  libraries  of  the  CompuServe
  358.        GRAPHDEV forum.  This  is  also  an  excellent  place  for  posting
  359.        messages or getting help regarding ray tracing and animation.
  360.  
  361.        Two  bulletin  boards  which specialize in graphics development are
  362.        "You  Can  Call  Me   Ray,"   708-358-5611;   and   "The   Graphics
  363.        Alternative," 510-524-2780.
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.                                     Chapter 2
  371.  
  372.                                   Running RTAG
  373.  
  374.  
  375.  
  376.  
  377.        Once  you  create an RTAG control file, you can use RTAG to compile
  378.        and execute it by issuing a DOS command of the form:
  379.  
  380.            RTAG control_file [option1] [option2]...
  381.  
  382.        where "control_file" is the name of the control file.  If  no  file
  383.        extension is specified, ".RTA" is used by default.
  384.  
  385.  
  386.        2.1 Command Line Options
  387.  
  388.        Following  the  control  file  name  you  may  specify  the options
  389.        described below.  If more than one option is  provided,  they  must
  390.        be   separated   by  spaces.   The  option  letters  are  not  case
  391.        sensitive.  Values specified with  command  line  options  override
  392.        the corresponding values specified in the control file.
  393.  
  394.        /B=file  --  Specifies  the name of the batch file.  The batch file
  395.            name can also be specified using  a  BFILE  statement  in  your
  396.            control file.  The default extension is ".BAT".
  397.  
  398.        /F=number  --  Specifies the first frame that is to produce output.
  399.            Output generated  with  the  BWRITE  and  OWRITE  functions  is
  400.            discarded  for  frames prior to this number.  The default value
  401.            is 1.
  402.  
  403.        /L=number -- Specifies the last frame that is  to  produce  output.
  404.            Output  generated  with  the  BWRITE  and  OWRITE  functions is
  405.            discarded for frames following this number.  By default,  there
  406.            is no last frame (i.e., all frames are output).
  407.  
  408.        /N  --  Specifies  that no output is to be written to the batch and
  409.            include files.  This  is  useful  when  you  are  debugging  an
  410.            animation  control  file and want to test it without generating
  411.            the  output  files.   Output  generated  by  PRINTF  and  WRITE
  412.            functions always is written, even if this option is specified.
  413.  
  414.        /O=file  --  Specifies  the  name  of  the  include files generated
  415.            during the run.  Include file names  must  include  the  string
  416.            '###'  (1  to  5 '#' characters) which is replaced by the frame
  417.            number.  The output file names can  also  be  specified  by  an
  418.            OFILE  statement  in  your control file.  The default extension
  419.            is ".INC".
  420.  
  421.  
  422.                                         6
  423.  
  424.        Chapter 2. Running RTAG                                           7
  425.  
  426.  
  427.        /P -- Causes the entire control file to be  listed  on  the  screen
  428.            and  written to the listing file.  Normally only error messages
  429.            and output generated by PRINTF statements are displayed.
  430.  
  431.        /S=number -- Specifies the number of  steps  between  frames  whose
  432.            output  is  to  be  generated.   Output is discarded for frames
  433.            between the step frames if a value other than 1  is  specified.
  434.            The  default  value  is  1.   If stepping is enabled, the first
  435.            frame  is  generated  and  then  frames  are  skipped   up   to
  436.            first+step.   The  sequence  continues  with subsequent frames.
  437.            This option is useful  for  producing  an  abbreviated  set  of
  438.            frames for evaluation and debugging purposes.
  439.  
  440.        /T  --  Specifies  that  each  source  statement is to be displayed
  441.            before it is executed.  This is useful for debugging purposes.
  442.  
  443.  
  444.        2.2 The RTAG Animation Control File
  445.  
  446.        RTAG reads an animation control file that you create, compiles  the
  447.        commands,  and executes the resulting program.  The commands in the
  448.        control file are formed from the RTAG animation language  which  is
  449.        described  in  the  sections  that follow.  However, before getting
  450.        into a detailed discussion of the animation  language,  let's  look
  451.        at  a  simple  example  to  get  a  feeling for the language.  This
  452.        example is a complete RTAG command file  which  will  generate  the
  453.        appropriate  commands  to  move  an  object  on  a spline path that
  454.        passes through a specified set of x,y,z coordinates:
  455.  
  456.        Chapter 2. Running RTAG                                           8
  457.  
  458.  
  459.            //  Simple animation example.
  460.            //  Declare variables
  461.            var lastframe = 60;      // Generate 60 frames
  462.            var x,y,z;
  463.            //  Declare files
  464.            bfile "move";              // Batch file MOVE.BAT
  465.            //  Begin main animation loop to generate 60 frames.
  466.            while (curframe < lastframe) {
  467.                //  Begin the next frame (this increments curframe)
  468.                nextframe;
  469.                //  Use spline function to compute x,y,z position.
  470.                x = spline(curframe, 1,-8, 20,0, 40,5, 60,8);
  471.                y = spline(curframe, 1,1,  20,5, 40,5, 60,1);
  472.                z = spline(curframe, 1,0,  20,4, 40,6, 60,10);
  473.                //  Report the position
  474.                printf("At frame `curframe`, x=`x`, y=`y`, z=`z`\n");
  475.                //  Write commands to the batch file.
  476.                //  These commands create a move.inc include file.
  477.                bwrite("ECHO #declare xpos = `x` > move.inc\n");
  478.                bwrite("ECHO #declare ypos = `y` >> move.inc\n");
  479.                bwrite("ECHO #declare zpos = `z` >> move.inc\n");
  480.                //  Generate command to render the image.
  481.                bwrite("call render move move`###`\n");
  482.            }
  483.            //  Write batch command that runs DTA to build the animation.
  484.            epilog;
  485.            bwrite("call dta move\n");
  486.  
  487.  
  488.        2.3 Arithmetic and Logical Expressions
  489.  
  490.        Much of the power  of  RTAG  comes  from  its  ability  to  perform
  491.        mathematical  calculations.   This  is  important  for  any type of
  492.        animation generation,  but  is  especially  critical  for  physical
  493.        system   simulations.    This   section   explains  the  arithmetic
  494.        operators and built in functions that may  be  used  in  arithmetic
  495.        expressions.
  496.  
  497.        The following arithmetic operators may be used in expressions:
  498.  
  499.            ++       add 1 to a variable
  500.            --       subtract 1 from a variable
  501.            +        addition
  502.            -        subtraction or unary minus
  503.            *        multiplication
  504.            /        division
  505.            %        modulo
  506.            ** or ^  exponentiation
  507.  
  508.        The  "++"  and "--" operators may be used either immediately before
  509.        or after a variable name.  If they are used before  the  name,  the
  510.        increment  or  decrement  is  performed  before  the  value  of the
  511.        variable is used in the expression.  If they  are  used  after  the
  512.        name,  the  value  of the variable before being modified is used in
  513.  
  514.        Chapter 2. Running RTAG                                           9
  515.  
  516.  
  517.        the expression and then the increment  or  decrement  takes  place.
  518.        For example, the sequence:
  519.  
  520.            a = 3;
  521.            b = 3;
  522.            x = ++a;
  523.            y = b++;
  524.  
  525.        assigns  the  value 4 to x and 3 to y.  At the end of the sequence,
  526.        both a and b have the value 4.
  527.  
  528.        The following assignment operators can be used in expressions:
  529.  
  530.            variable = expression;      // Assign expression to variable
  531.            variable += expression;     // Add expression to variable
  532.            variable -= expression;     // Subtract expression from variable
  533.            variable *= expression;     // Multiply variable by expression
  534.            variable /= expression;     // Divide variable by expression
  535.  
  536.        The following operators compare two values and produce a  value  of
  537.        1 if the comparison is true, or 0 if the comparison is false:
  538.  
  539.            ==   Equal
  540.            !=   Not equal
  541.            <=   Less than or equal
  542.            >=   Greater than or equal
  543.            <    Less than
  544.            >    Greater than
  545.  
  546.        The following logical operators may be used:
  547.  
  548.            !    Logical NOT (negates true and false)
  549.            &&   AND
  550.            ||   OR
  551.  
  552.        There  are  two  other  special  operators:  "[]" (square brackets)
  553.        which enclose subscripts on arrays, and "," (comma) which  is  used
  554.        to  specify  left-to-right,  sequential  evaluation  of  a  list of
  555.        expressions.
  556.  
  557.        Operator  precedence,  in  decreasing   order,   is   as   follows:
  558.        subscript,  unary  minus,  logical  NOT,  ++ and --, exponentation,
  559.        multiplication, division  and  modulo,  addition  and  subtraction,
  560.        relational  (comparison),  logical (AND and OR), assignment, comma.
  561.        Parentheses may be used to group terms.
  562.  
  563.        2.3.1 Numeric Constants
  564.  
  565.        Numeric constants may be written in their natural form (1, 0,  1.5,
  566.        .0003,  etc.) or in exponential form, n.nnnEppp, where n.nnn is the
  567.        base value and ppp is the  power  of  ten  by  which  the  base  is
  568.        multiplied.   For example, the number 1.5E4 is equivalent to 15000.
  569.        All numbers are treated as "floating point" values,  regardless  of
  570.        whether  a decimal point is specified or not.  As a convenience for
  571.        entering time values, if a value contains one or more  colons,  the
  572.  
  573.        Chapter 2. Running RTAG                                          10
  574.  
  575.  
  576.        portion  to  the  left  of  the  colon  is  multiplied  by 60.  For
  577.        example, 1:00 is equivalent to 60; 1:00:00 is equivalent to 3600.
  578.  
  579.        2.3.2 Built-in Constant
  580.  
  581.        The  symbolic  name  "PI"  is  equivalent  to  the  value  of   pi,
  582.        3.14159...  You may write PI using either upper or lower case.
  583.  
  584.  
  585.        2.4 Built in Functions
  586.  
  587.        The  following  functions  are  built  into RTAG and may be used in
  588.        expressions:
  589.  
  590.        ABS(x) -- Absolute value of x.
  591.  
  592.        ACOS(x) -- Arc cosine of x.  Angles are measured in degrees.
  593.  
  594.        ASIN(x) -- Arc sine of x.  Angles are measured in degrees.
  595.  
  596.        ATAN(x) -- Arc tangent of x.  Angles are measured in degrees.
  597.  
  598.        CEIL(x) -- Ceiling of x (an equivalent name for  this  function  is
  599.            INT).   Returns  the smallest integer that is at least as large
  600.            as x.  For example, CEIL(1.5)=2; CEIL(4)=4; CEIL(-2.6)=-2.
  601.  
  602.        CLOSE(file) -- Close the specified file.
  603.  
  604.        COS(x) -- Cosine of x.  Angles are measured in degrees.
  605.  
  606.        COSH(x) -- Hyperbolic cosine of x.
  607.  
  608.        COT(x) -- Cotangent of x.  (COT(x) = 1/TAN(x)).  Angle in degrees.
  609.  
  610.        CREATE("file name") -- Create  a  new  auxiliary  data  file.   The
  611.            value  returned  by  this function is a file number that can be
  612.            used with subsequent WRITE functions.  See the  description  of
  613.            auxiliary file I/O for additional information.
  614.  
  615.        CSC(X) -- Cosecant of x.  (CSC(x) = 1/SIN(x)).  Angle in degrees.
  616.  
  617.        DEG(x)  --  Converts  an  angle,  x,  measured  in  radians  to the
  618.            equivalent number of degrees.
  619.  
  620.        EXP(x) -- e (base of natural logarithms) raised to the x power.
  621.  
  622.        FAC(x) -- x factorial (x!).  The FAC  function  is  computed  using
  623.            the  GAMMA function (FAC(x)=GAMMA(x+1)) so non-integer argument
  624.            values may be computed.
  625.  
  626.        FLOOR(x) -- Floor of x.  Returns the largest integer that  is  less
  627.            than  or  equal  to  x.  For example, FLOOR(2.5)=2; FLOOR(4)=4;
  628.            FLOOR(-3.6)=-4.
  629.  
  630.        Chapter 2. Running RTAG                                          11
  631.  
  632.  
  633.        GAMMA(x) -- Gamma function.  Note, GAMMA(x+1) = x!  (x factorial).
  634.  
  635.        INT(x) -- Ceiling of x (an equivalent name  for  this  function  is
  636.            CEIL).   Returns the smallest integer that is at least as large
  637.            as x.  For example, INT(1.5)=2; INT(4)=4; INT(-2.6)=-2.
  638.  
  639.        LINEAR(t,   t1,x1,   t2,x2,   ...    tn,xn)   --   Perform   linear
  640.            interpolation  between  a  set  of  points.   If the value of a
  641.            function is x1 at some point t1, x2 at t2, etc., this  function
  642.            determines  the value at some arbitrary point, t, where t falls
  643.            in the  range  (t1,tn).   The  first  argument  to  the  LINEAR
  644.            function  is  the  value  t at which the interpolation is to be
  645.            performed.  The remaining arguments  are  (ti,xi)  data  pairs.
  646.            For  example,  consider  the function LINEAR(t, 0,0, 1,6, 2,4).
  647.            This specifies that when t is 0, the value of the  function  is
  648.            0,  when  t  is 1, the value is 6, and when t is 2 the value is
  649.            4.  If this function is called with  a  t  value  of  0.5,  the
  650.            returned  value  of the function will be 3.  If the function is
  651.            called with a t value of 1.5, the returned  value  will  be  5.
  652.            You  can  use  expressions  as arguments to this function.  For
  653.            example, the following function invocation is valid:  LINEAR(t,
  654.            starttime,basex,  starttime+3,midx,  endtime,midx*2).   If  the
  655.            function is called with a t value that  is  outside  the  range
  656.            (t1,tn)  (i.e.,  beyond either end point), then the nearest end
  657.            point and the second closest point are used to  extrapolate  to
  658.            the  specified t value.  See also the description of the SPLINE
  659.            function.
  660.  
  661.        LOG(x) -- Natural logarithm of x.
  662.  
  663.        LOG10(x) -- Base 10 logarithm of x.
  664.  
  665.        MAX(x1,x2) -- Maximum value of x1 or x2.
  666.  
  667.        MIN(x1,x2) -- Minimum value of x1 or x2.
  668.  
  669.        MOD(x1,x2) -- x1  modulo  x2.   The  MOD  function  calculates  the
  670.            floating-point  remainder, f, of x1/(i*x2) such that x1=i*x2+f,
  671.            where i is an integer; f has the  same  sign  as  x1,  and  the
  672.            absolute  value  of  f  is  less than the absolute value of x2.
  673.            The % operator perform the same operation.
  674.  
  675.        MOREDATA(file) -- This function checks to see if there  is  another
  676.            data  record  available  in the external file whose file number
  677.            is specified as the argument.  If there is a record  available,
  678.            this  function  returns  the value true (1), if not, it returns
  679.            false (0).  This function does not  consume  any  data  in  the
  680.            file,  you  must  use  the  READ statement to actually read the
  681.            next record.   You  can  call  MOREDATA  any  number  of  times
  682.            without  disturbing  the  next  record  in  the  file.  See the
  683.            section on auxiliary file I/O for additional information.
  684.  
  685.        NPD(x,mean,std)  --  Normal  probability  distribution  of  x  with
  686.            specified  mean  and  standard  deviation.   X  is  in units of
  687.            standard deviations from the mean.
  688.  
  689.        Chapter 2. Running RTAG                                          12
  690.  
  691.  
  692.        OPEN("file name") -- Open an existing file for reading.  The  value
  693.            returned  by  this  function  is a file number that can be used
  694.            with  subsequent  READ  functions.   See  the  description   of
  695.            auxiliary file I/O for additional information.
  696.  
  697.        PAREA(x)  --  Area  under the normal probability distribution curve
  698.            from -infinity to x.  (i.e., integral from -infinity  to  x  of
  699.            NORMAL(x)).
  700.  
  701.        PRINTF("format"[,expression1,expression2,...])   --   Evaluate  the
  702.            expressions (if any) and write the values  with  the  specified
  703.            formatting string to the console and the listing file.
  704.  
  705.        PULSE(a,x,b)  --  Pulse function.  If the value of x is less than a
  706.            or greater than b, the value of the function is  0.   If  x  is
  707.            greater  than  or  equal  to a and less than or equal to b, the
  708.            value of the function is 1.  In other words, it is  1  for  the
  709.            domain  (a,b)  and zero elsewhere.  If you need a function that
  710.            is  zero  in  the  domain  (a,b)  and  1  elsewhere,  use   the
  711.            expression (1-PULSE(a,x,b)).
  712.  
  713.        RAD(x)  --  Converts an angle measured in degrees to the equivalent
  714.            number of radians.
  715.  
  716.        RANDOM() -- Returns a random value  uniformly  distributed  in  the
  717.            range  0  to  1.   You  can  use  the  srand system variable to
  718.            specify a starting seed.
  719.  
  720.        READ(file,variable1,variable2,...)  --  Read  one  line  from   the
  721.            specified  file, scan the input line for values, and assign the
  722.            values to the specified variables.
  723.  
  724.        ROUND(x)  --  Rounds  x  to  the  nearest  integer.   For  example,
  725.            ROUND(1.1)=1; ROUND(1.8)=2; ROUND(-2.8)=-3;
  726.  
  727.        SEC(x) -- Secant of x.  (SEC(x) = 1/COS(x)).  Angle in degrees.
  728.  
  729.        SEL(a1,a2,v1,v2)  --  If  a1  is less than a2 then the value of the
  730.            function is v1.  If a1 is greater than or  equal  to  a2,  then
  731.            the value of the function is v2.
  732.  
  733.        SIN(x) -- Sine of x.  Angles are measured in degrees.
  734.  
  735.        SINH(x) -- Hyperbolic sine of x.
  736.  
  737.        SPLINE(t,  t1,x1,  t2,x2,  ...   tn,xn)  --  Perform a cubic spline
  738.            interpolation between a set of points.  A spline  is  a  smooth
  739.            path  (continuous  first  and  second  derivatives) that passes
  740.            through a set of points.  The SPLINE function  is  very  useful
  741.            in  animations  because  it  allows  you  to easily construct a
  742.            smooth path for the motion of some object (or the camera).
  743.  
  744.            If the value of a function is x1 at some point t1,  x2  at  t2,
  745.            etc.,  this  function  determines  the  value at some arbitrary
  746.            point, t, where t  falls  in  the  range  (t1,tn).   The  first
  747.  
  748.        Chapter 2. Running RTAG                                          13
  749.  
  750.  
  751.            argument  to  the  SPLINE  function is the value t at which the
  752.            interpolation is to be performed.  The remaining arguments  are
  753.            (ti,xi)  data  pairs.   You can use expressions as arguments to
  754.            this function.  For example, the following function  invocation
  755.            is    valid:   SPLINE(t,   starttime,basex,   starttime+3,midx,
  756.            endtime,midx*2).  If the function is  called  with  a  t  value
  757.            that  is  outside  the  range  (t1,tn) (i.e., beyond either end
  758.            point), then the value of  the  function  at  the  nearest  end
  759.            point  and  the slope of the function at that point are used to
  760.            extrapolate in a linear fashion to the specified t value.   See
  761.            also the description of the LINEAR function.
  762.  
  763.        SQRT(x) -- Square root of x.
  764.  
  765.        STEP(a,x)  -- Step function.  If x is less than a, the value of the
  766.            function is 0.  If x is greater than or equal to a,  the  value
  767.            of  the function is 1.  If you need a function which is 1 up to
  768.            a  certain  value  and  then  0  beyond  that  value,  use  the
  769.            expression STEP(x,a).
  770.  
  771.        TAN(x) -- Tangent of x.  Angles are measured in degrees.
  772.  
  773.        TANH(x) -- Hyperbolic tangent of x.
  774.  
  775.        WRITE(file,"format"[,expression1,expression2,...])  -- Evaluate the
  776.            expressions (if any) and write the values  with  the  specified
  777.            formatting  string  to  auxiliary output file whose file number
  778.            is specified as the first argument.
  779.  
  780.        2.4.1 Notes on the SPLINE and LINEAR Functions
  781.  
  782.        RTAG includes two library functions for  performing  interpolation:
  783.        LINEAR  and  SPLINE.   If you have two pairs of values, (t1,x1) and
  784.        (t2,x2), these functions determine the value of x that  corresponds
  785.        to  some  value  of t between t1 and t2.  If you have more than two
  786.        pairs, the function determines the  value  of  x  that  is  on  the
  787.        segment that spans the specified value of t.
  788.  
  789.        The  function parameters, t and x, can represent any type of value.
  790.        However, in animations t is usually a time value or  frame  number,
  791.        and  x  is a position (either in the X, Y, or Z dimension).  If you
  792.        want an object to follow a path through a set of three  dimensional
  793.        points,   you   have   to   use  three  statements,  each  with  an
  794.        interpolation function.  For example, if at frame  1  you  want  an
  795.        object  to be at (-8,0,-3), frame 20 to be at (0,5,-1), frame 40 to
  796.        be at (2,2,0), and frame 60 to be at (7,4,2), then  you  could  use
  797.        the following statements:
  798.  
  799.            while (curframe <= 60) {
  800.                nextframe;
  801.                x = spline(curframe, 1,-8, 20,0,  40,2, 60,7);
  802.                y = spline(curframe, 1,0,  20,5,  40,2, 60,4);
  803.                z = spline(curframe, 1,-3, 20,-1, 40,0, 60,2);
  804.                << other statements >>
  805.            }
  806.  
  807.        Chapter 2. Running RTAG                                          14
  808.  
  809.  
  810.        The  spline  function  will force the object to be at the specified
  811.        x,y,z coordinate at frames 1, 20, 40, and  60,  and  will  generate
  812.        intermediate positions between these frames.
  813.  
  814.        While  the  method  explained  above  of  specifying absolute frame
  815.        numbers works well, you will have  to  change  the  values  in  the
  816.        function  specification if you change the total number of frames in
  817.        the animation.  A better approach is to use the percentage  of  the
  818.        total  animation  as  the  control  values  and  use the expression
  819.        (100*(curframe-1)/(lastframe-1)) to specify the position along  the
  820.        path.   Note that the a value must be specified for lastframe.  The
  821.        following program illustrates this approach:
  822.  
  823.            var x,y,z,position;
  824.            var lastframe = 50;     // Animation will have 50 frames
  825.            while (curframe < lastframe) {
  826.                nextframe;          // This increments curframe
  827.                position = 100*(curframe-1)/(lastframe-1);
  828.                x = spline(position, 0,-8, 40,0,  60,2, 100,7);
  829.                y = spline(curframe, 0,0,  40,5,  60,2, 100,4);
  830.                z = spline(curframe, 0,-3, 40,-1, 60,0, 100,2);
  831.            statements to output position >>
  832.            }
  833.  
  834.        If the path described by  a  spline  function  completes  a  closed
  835.        circuit,  a  smoother  transition can be accomplished by specifying
  836.        an extra point beyond either end which matches the  next  point  on
  837.        the  path.   The following statements illustrate this for forming a
  838.        roughly circular path (a better way to do this would be to use  sin
  839.        and cos functions):
  840.  
  841.            position = 100*(curframe-1)/(lastframe-1);
  842.            x = spline(position, -20,0.3,   0,1.0,   20,0.3,  40,-0.8,
  843.                                  60,-0.8, 80,0.3,  100,1.0, 120,0.3);
  844.            y = spline(position, -20,-1.0,  0,0.0,   20,1.0,  40,0.6,
  845.                                  60,-0.6, 80,-1.0, 100,0.0, 120,1.0);
  846.  
  847.        Note  that the first point specified (-20) and the last point (120)
  848.        will never be reached since the value of position ranges from 0  to
  849.        100.   However, because the spline function depends not only on the
  850.        current position but also on the points on either side,  specifying
  851.        these  points smooths out the transition near the end points.  This
  852.        trick does not apply to  spline  curves  that  are  not  closed  on
  853.        themselves.
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.                                     Chapter 3
  861.  
  862.                          The Animation Control Language
  863.  
  864.  
  865.  
  866.  
  867.        The  RTAG  animation  control  language  is similar to other modern
  868.        programming languages such as C.  It provides the  tools  you  need
  869.        to  easily perform animation simulations and generate the necessary
  870.        output files to drive the ray tracing and auxiliary programs.
  871.  
  872.  
  873.        3.1 Comments
  874.  
  875.        The beginning of a comment is denoted with  "//"  (two  consecutive
  876.        slash  characters).   Everything  from the "//" sequence to the end
  877.        of the line is treated as a comment.  Comments may be on  lines  by
  878.        themselves  or  on  the  ends  of  other  statements.  You can also
  879.        specify a comment by beginning the comment with the "/*"  character
  880.        sequence.   All  characters  following this are treated as comments
  881.        up to the matching "*/" sequence.  The following  lines  illustrate
  882.        both types of comments:
  883.  
  884.            //  Begin main simulation loop
  885.            y = y + timestep * yvelocity;  //  Advance y position
  886.            /*
  887.             *  This is a comment.
  888.             */
  889.            z = y / 5;                  /* This is a comment too */
  890.  
  891.  
  892.        3.2 Basic Statement Syntax
  893.  
  894.        The  RTAG  language  has  a  syntax  that  is  very  similar  to C:
  895.        statements are terminated with a semicolon,  and  brace  characters
  896.        ("{" and "}") are used to group statements.
  897.  
  898.  
  899.        3.3 Declaration of Variables (The VAR Statatement)
  900.  
  901.        All  variables used in your animation control file must be declared
  902.        before they are used.  This is done using the VAR  statement  which
  903.        may  optionally  assign  an  initial  value to the variable.  If no
  904.        initial value is specified,  0  is  used  by  default.   VAR  is  a
  905.        declarative  statement:  that  is, it declares the existance of the
  906.        variable and assigns an initial value, it  does  not  reassign  the
  907.        value to the variable if the VAR statement appears in a loop.
  908.  
  909.  
  910.  
  911.  
  912.                                        15
  913.  
  914.        Chapter 3. The Animation Control Language                        16
  915.  
  916.  
  917.        Variable  names  may  be  up  to 30 characters long.  They ARE case
  918.        sensitive.  Keywords (FOR, WHILE, VAR, etc.) and  library  function
  919.        names  (SIN, COS, ABS, etc.) are NOT case sensitive.  All variables
  920.        are double precision (64 bit) floating point values.
  921.  
  922.        The syntax of the VAR statement is:
  923.  
  924.            VAR variable1[=value], variable2[=value], ...;
  925.  
  926.        You may use as many VAR statements as you need.  The following  are
  927.        examples of this statement:
  928.  
  929.            var x, y, speed = 5;
  930.            var Acceleration = 2.5;
  931.  
  932.        In  addition  to  simple  scalar variables, RTAG also allows you to
  933.        use  one-dimensional  array  variables.   To   declare   an   array
  934.        variable,  follow  the  name  of  the  variable  with the number of
  935.        elements enclosed in square brackets.  For example,  the  following
  936.        command declares a variable named speeds that will have 20 values:
  937.  
  938.            var speeds[20];
  939.  
  940.        If  you wish to assign initial values to an array, enclose the list
  941.        of values in braces.  For example,
  942.  
  943.            var xpos[3] = {1.2, 2.7, 4.6};
  944.  
  945.        Subscripts follow the C convention of being 0 based.  That is,  the
  946.        first  element of an array is referenced using a subscript value of
  947.        0.  For example, if the variable x is declared with three  elements
  948.        (var  x[3])  then  the  elements would be referenced as x[0], x[1],
  949.        and x[2].  The expression x[3] would NOT be valid.
  950.  
  951.        In addition to your own variables,  RTAG  provides  several  system
  952.        variables.   If  you  do  not  provide  VAR  statements  for  these
  953.        variables, they are defined automatically at the  start  of  a  run
  954.        and RTAG assigns their values.
  955.  
  956.             Variable   Default               Meaning
  957.            ----------  -------  -------------------------------------------
  958.            curframe       0     The current frame number. Set by NEXTFRAME.
  959.            firstframe     1     The first frame that will generate output.
  960.            lastframe    999999  The last frame that will generate output.
  961.            stepinc        1     The step increment between frames.
  962.            srand          1     Seed for random number generator.
  963.  
  964.        These  variables  may  be  used in your animation control file just
  965.        like ordinary variables.  If you  want  to  set  different  default
  966.        values  for  firstframe,  lastframe,  stepinc  or  srand, use a VAR
  967.        statement  and  specify  an  initial  value.   For   example,   the
  968.        following commands would cause frames 20 through 40 to be output:
  969.  
  970.            var firstframe = 20;
  971.            var lastframe = 40;
  972.  
  973.        Chapter 3. The Animation Control Language                        17
  974.  
  975.  
  976.        The  default values, or the values specified by VAR statements, can
  977.        be  overridden  by  qualifiers  on  the  command  line.   /F   sets
  978.        firstframe, /L sets lastframe, and /S sets stepinc.
  979.  
  980.        The  srand  system  variable is used to set a starting "seed" value
  981.        for the RANDOM() function.  The default value for srand is 1.   For
  982.        a  given  starting  seed value, the pseudorandom sequence is always
  983.        the same.
  984.  
  985.  
  986.        3.4 Output File Declarations
  987.  
  988.        RTAG is capable of producing multiple files during each run.   Most
  989.        of  these  files  are  optional  and  will  only be produced if you
  990.        include the appropriate statements in your control file.
  991.  
  992.        The listing file is always produced.  It has the same name  as  the
  993.        animation control file but with an extension of ".LST".
  994.  
  995.        Most  RTAG  runs will produce a batch file to drive the ray tracing
  996.        program.  The batch file  may  contain  commands  to  generate  the
  997.        appropriate  include  file for each frame or you may choose to have
  998.        RTAG generate the full set  of  include  files  separate  from  the
  999.        batch  file.  If you wish to generate a batch file you must place a
  1000.        command of the following form in your control file:
  1001.  
  1002.            BFILE "name";
  1003.  
  1004.        where 'name' is the name of the batch file.  The default  extension
  1005.        is  ".BAT".   Note  that  the  file  name must be enclosed on quote
  1006.        marks.
  1007.  
  1008.        The batch file normally contains a set of commands to  render  each
  1009.        frame.    Typically,  the  commands  for  each  frame  perform  the
  1010.        following actions:
  1011.  
  1012.        1.  Generate an include file with object position information.
  1013.  
  1014.        2.  Run the ray tracer using the current include file.
  1015.  
  1016.        The BWRITE function is used to write to the batch file.  The  batch
  1017.        file  is  optional  and  is  generated  only  if  you  use  a BFILE
  1018.        statement.
  1019.  
  1020.        If you wish to have RTAG generate a set of include files, you  must
  1021.        use the following command to declare the names of the files:
  1022.  
  1023.            OFILE "name";
  1024.  
  1025.        If  the  OFILE  statement is used, one output file is generated for
  1026.        each frame.  The output file name must include a string of  one  to
  1027.        seven  '#'  characters.   These  characters  are  replaced  by  the
  1028.        current frame  number  when  the  file  is  opened.   For  example,
  1029.        consider the following command:
  1030.  
  1031.        Chapter 3. The Animation Control Language                        18
  1032.  
  1033.  
  1034.            ofile "bounc###.inc";
  1035.  
  1036.        Then   for   frame  27  the  name  of  the  created  file  will  be
  1037.        BOUNC027.INC.  The default extension is ".INC".
  1038.  
  1039.        The NEXTFRAME command closes the current  output  file,  increments
  1040.        the  frame  number,  and  opens  the next output file (assuming the
  1041.        OFILE statement was specified).  The last  output  file  is  closed
  1042.        when  the  program  stops.  The OWRITE function writes lines to the
  1043.        currently open output file.
  1044.  
  1045.        RTAG can also create or read from auxiliary data  files.   This  is
  1046.        described in a subsequent section.
  1047.  
  1048.  
  1049.        3.5 Assignment Statement
  1050.  
  1051.        The  assignment statement is an executable statement that evaluates
  1052.        an expression and assigns its value to a variable.  The syntax  for
  1053.        an assignment statement is:
  1054.  
  1055.            variable = expression;     // Assign expression to variable
  1056.            variable += expression;    // Add expression to variable
  1057.            variable -= expression;    // Subtract expression from variable
  1058.            variable *= expression;    // Multiply variable by expression
  1059.            variable /= expression;    // Divide variable by expression
  1060.  
  1061.        where  "variable"  is  a  previously declared variable which may be
  1062.        subscripted and "expression"  is  a  valid  arithmetic  or  logical
  1063.        expression   following   the   rules  explained  earlier.   If  the
  1064.        expression involves a relational comparison operator (e.g.,  <,  >,
  1065.        >=,  etc.)  or a logical operation (&&, ||, !), the value 1 is used
  1066.        for true and 0 for false.
  1067.  
  1068.  
  1069.        3.6 IF Statement
  1070.  
  1071.        The form of the IF statement is:
  1072.  
  1073.            IF (expression) statement1 [ELSE statement2]
  1074.  
  1075.        If the expression is true (not zero)  statement1  is  executed,  if
  1076.        the  expression  is  false  (0)  and  the ELSE clause is specified,
  1077.        statement2 is executed.  The ELSE clause  and  the  second  set  of
  1078.        controlled  statements  are  optional.   You  may control groups of
  1079.        statements  by  enclosing  them  in  braces.   The  following   are
  1080.        examples of valid IF statements:
  1081.  
  1082.            if (x > bigx) bigx = x;
  1083.  
  1084.        Chapter 3. The Animation Control Language                        19
  1085.  
  1086.  
  1087.            if (x <= 10) {
  1088.                y = linear(x, 0,0, 10,6);
  1089.                z = .5 * x;
  1090.            } else {
  1091.                y = y + yspeed * timestep;
  1092.                z = .3 * x;
  1093.            }
  1094.  
  1095.  
  1096.        3.7 WHILE Statement
  1097.  
  1098.        The  WHILE statement loops until the controlling expression becomes
  1099.        false (0) or a BREAK statement is executed within  the  loop.   The
  1100.        form of the WHILE statement is:
  1101.  
  1102.            WHILE (expression) {
  1103.                << controlled statements >>
  1104.            }
  1105.  
  1106.        Each  time  around  the loop the expression is evaluated.  If it is
  1107.        true (non zero) the controlled statements  are  executed  and  then
  1108.        the  process  repeats  until  the  expression  becomes false.  If a
  1109.        BREAK statement is executed within the loop, execution of the  loop
  1110.        terminates  and  control  is  transferred  to  the  first statement
  1111.        beyond the end of the loop.  If a CONTINUE  statement  is  executed
  1112.        in  the loop, control is transferred to the conditional test at the
  1113.        top  of  the  loop.   The  following  is  an  example  of  a  WHILE
  1114.        statement:
  1115.  
  1116.            while (x < 5) {
  1117.                x = x + xmove;
  1118.                y = y + ymove;
  1119.            }
  1120.  
  1121.  
  1122.        3.8 DO Statement
  1123.  
  1124.        The  DO statement is very similar to the WHILE statement except the
  1125.        control expression is evaluated at the end of the loop rather  than
  1126.        the  beginning.   This  causes  the  loop  always to be executed at
  1127.        least once.  The form of the DO statement is:
  1128.  
  1129.            DO {
  1130.                << controlled statements >>
  1131.            WHILE (expression);
  1132.  
  1133.        For each iteration  of  the  loop  the  controlled  statements  are
  1134.        executed  and  then the conditional expression is evaluated.  If it
  1135.        is true  (non-zero)  control  transfers  to  the  first  controlled
  1136.        statement  at  the  top of the loop.  A BREAK statement may be used
  1137.        to  terminate  the  loop  before  the  conditional  expression   is
  1138.        evaluated.   A  CONTINUE  statement can be used to cause control to
  1139.        be transferred  from  within  the  loop  to  the  point  where  the
  1140.        conditional  expression  is evaluated.  The following is an example
  1141.        of a DO statement:
  1142.  
  1143.        Chapter 3. The Animation Control Language                        20
  1144.  
  1145.  
  1146.            do {
  1147.               read(infile,lastflag,x[numpoints++]);
  1148.            } while (!lastflag);
  1149.  
  1150.  
  1151.        3.9 FOR Statement
  1152.  
  1153.        The FOR statement is a looping control  statement  similar  to  the
  1154.        WHILE  statement;  however,  the  FOR  statement also allows you to
  1155.        specify initialization expressions that are executed  once  at  the
  1156.        beginning  of  the loop, and loop-end expressions that are executed
  1157.        at the end of each loop cycle.  The form of the FOR statement is:
  1158.  
  1159.            FOR (expression1; expression2; expression3) statement
  1160.  
  1161.        Execution of a FOR statement proceeds as follows:
  1162.  
  1163.        1.  Evaluate expression1.  Typically this expression  will  include
  1164.            assignment  operators  ("=")  to  set  initial  values for loop
  1165.            variables.  If you  need  more  than  one  initial  expression,
  1166.            specify them as a list separated by commas.
  1167.  
  1168.        2.  Evaluate  expression2.  If its value is false (0) terminate the
  1169.            FOR statement  and  transfer  control  to  the  statement  that
  1170.            follows  the  controlled  statement.   If  expression2 is true,
  1171.            proceed to the next step.
  1172.  
  1173.        3.  Execute the controlled statement.  If more than  one  statement
  1174.            is  to  be  controlled, enclose them with brace characters ("{"
  1175.            "}").
  1176.  
  1177.        4.  Evaluate expression3.  This expression will  typically  contain
  1178.            operators  such  as  "++",  "+=",  "--",  or "-=" to modify the
  1179.            value of a loop variable.
  1180.  
  1181.        5.  Transfer control to step 2, where  expression2  is  once  again
  1182.            evaluated.
  1183.  
  1184.        The following is an example of a FOR statement:
  1185.  
  1186.            for (time=starttime; time<endtime; time+=timestep) {
  1187.                << controlled statements >>
  1188.            }
  1189.  
  1190.  
  1191.        3.10 BREAK Statement
  1192.  
  1193.        The  BREAK  statement  can  be  used in FOR, WHILE, and DO loops to
  1194.        terminate the loop and cause control to transfer to  the  statement
  1195.        beyond  the  end  of  the  loop.   The following is an example of a
  1196.        BREAK statement:
  1197.  
  1198.        Chapter 3. The Animation Control Language                        21
  1199.  
  1200.  
  1201.            time = 0;
  1202.            x = 0;
  1203.            while (time < endtime) {
  1204.                x += delta * xspeed;
  1205.                if (x > 10) break;
  1206.            }
  1207.  
  1208.  
  1209.        3.11 CONTINUE Statement
  1210.  
  1211.        The CONTINUE statement can be used in FOR, WHILE, and DO  loops  to
  1212.        terminate  the  current  iteration  and  begin  the next one.  When
  1213.        CONTINUE is executed  in  a  WHILE  or  DO  statement,  control  is
  1214.        transferred  to  the  point  in  the  loop  where  the loop control
  1215.        expression is evaluated.   When  CONTINUE  is  executed  in  a  FOR
  1216.        statement,  control  is transferred to the bottom of the loop where
  1217.        expression3 is evaluated (which normally  augments  the  values  of
  1218.        the loop variables for the next iteration).
  1219.  
  1220.  
  1221.        3.12 STOP Statement
  1222.  
  1223.        The  STOP statement terminates the execution of RTAG and closes all
  1224.        output files.  An implicit STOP occurs if you  "fall  through"  the
  1225.        bottom  of  your  animation  control  file.   The  following  is an
  1226.        example of the STOP statement:
  1227.  
  1228.            while (curframe < 60) {
  1229.                << controlled statements >>
  1230.                if (xposition1 >= xposition2) stop;
  1231.            }
  1232.  
  1233.  
  1234.        3.13 WRITE Statements
  1235.  
  1236.        RTAG has three functions for  writing  output  to  standard  files.
  1237.        These functions and the files they write to are as follows:
  1238.  
  1239.        PRINTF -- Listing file (also displayed on screen).
  1240.  
  1241.        OWRITE -- Output file (OFILE).
  1242.  
  1243.        BWRITE -- Batch file (BFILE).
  1244.  
  1245.        Since  the  form  for  these  functions is the same (except for the
  1246.        keyword), the PRINTF statement will be used in  the  illustrations.
  1247.        The form of the function is:
  1248.  
  1249.            printf("string"[,expression1, expression2,...])
  1250.  
  1251.        where  "string" is a quoted text string that may including variable
  1252.        and expression replacement operators.  You can  cause  the  current
  1253.        value  of  a  variable to be substituted into a string by inserting
  1254.        the variable name in the string enclosed by "`" characters.   Note,
  1255.        this  is  not the apostrophe, it is the accent character that is on
  1256.  
  1257.        Chapter 3. The Animation Control Language                        22
  1258.  
  1259.  
  1260.        the same key as the tilde on  most  keyboards.   You  can  use  the
  1261.        SUBCHAR  statement (see below) to change the character used to mark
  1262.        a  variable  value  substitution.   For  example,   the   following
  1263.        statement prints the values of the xpos and ypos variables:
  1264.  
  1265.            printf("X position is `xpos`, and Y position is `ypos`\n");
  1266.  
  1267.        When  this  statement is executed `xpos` and `ypos` are replaced by
  1268.        the current values of the xpos and ypos variables.
  1269.  
  1270.        Following the C model, control characters are placed in the  string
  1271.        by  prededing  the character with a backslash.  The following table
  1272.        indicates each of the valid control sequences:
  1273.  
  1274.        \a -- Bell character (0x07).
  1275.  
  1276.        \b -- Backspace (0x08).
  1277.  
  1278.        \f -- Form feed (0x0C);
  1279.  
  1280.        \n -- End of print line (carriage-return, line-feed).
  1281.  
  1282.        \r -- Carriage return only.
  1283.  
  1284.        \" -- Quote character.
  1285.  
  1286.        \\ -- Literal backslash character (i.e., replace "\\" with "\").
  1287.  
  1288.        \xddd -- Hexadecimal value 0xddd.
  1289.  
  1290.        If the sequence `###` (1  to  7  '#'  characters  enclosed  by  "`"
  1291.        characters)  appears in the string, the pound signs are replaced by
  1292.        the current frame number  with  leading  zeros.   If  the  sequence
  1293.        `+++`  (1  to  7  '+'  characters)  appears in the string, the plus
  1294.        signs are replaced by a value equal to  the  current  frame  number
  1295.        plus  1.  In addition, the strings `ofile` and `bfile` are replaced
  1296.        by the names of the output file, and batch file respectively.   The
  1297.        string  `file`  is  replaced  by  the  name  of the input animation
  1298.        command file with any device, directory, and extension removed.
  1299.  
  1300.        You can also substitute the values of  expressions.   To  do  this,
  1301.        use  the  C  programming notation "%w.dlf" where 'w' is the overall
  1302.        field width and 'd' is the number of decimal places.  For  example,
  1303.        the following statement prints the value of an expression:
  1304.  
  1305.            printf("The diagonal distance is %5.1lf\n", sqrt(xd^2 + yd^2));
  1306.  
  1307.  
  1308.        3.14 SUBCHAR Statement
  1309.  
  1310.        The  SUBCHAR  statement  specifies which character is to be used in
  1311.        write strings to enclose the names of variables  whose  values  are
  1312.        to  be  substituted in the string.  The default character is "`" --
  1313.        the accent character which is usually on the same key as the  tilde
  1314.        character.  The form of the statement is:
  1315.  
  1316.        Chapter 3. The Animation Control Language                        23
  1317.  
  1318.  
  1319.            SUBCHAR "char";
  1320.  
  1321.        where  "char"  is a single character that must be included in quote
  1322.        marks.  For example, the following statement declares  dollar  sign
  1323.        to be the substitution marker character:
  1324.  
  1325.            subchar "$";
  1326.  
  1327.  
  1328.        3.15 NEXTFRAME Statement
  1329.  
  1330.        The  NEXTFRAME  statement performs the following actions: (1) close
  1331.        the currently open output file, if any; (2) increment  the  current
  1332.        frame  number  (and  curframe  variable); (3) if an OFILE statement
  1333.        was used, open a new output file  with  the  current  frame  number
  1334.        substituted for the "###" characters in the file name.
  1335.  
  1336.        You  must  execute  a  NEXTFRAME  statement  before  you can use an
  1337.        OWRITE  function.   PRINT,  BWRITE  and  WRITE  functions  can   be
  1338.        executed  before the first NEXTFRAME command.  The last output file
  1339.        is closed when your program stops.
  1340.  
  1341.  
  1342.        3.16 EPILOG Statement
  1343.  
  1344.        The EPILOG statement (which may also be spelled  EPILOGUE)  informs
  1345.        RTAG  that  the  last  frame has been completed and that subsequent
  1346.        BWRITE  function  calls  are  unconditionally  to  generate  output
  1347.        regardless  of  the  setting  of  the  firstframe,  lastframe,  and
  1348.        stepinc values.  Otherwise BWRITE functions do not generate  output
  1349.        if  they  occur  after the last frame, or between frames if stepinc
  1350.        is not 1.  Commonly statements using the BWRITE function  are  used
  1351.        after   EPILOG   to   write  some  "end-of-all-frames"  termination
  1352.        statements to the batch file, such as commands to run DTA to  build
  1353.        the animation sequence.
  1354.  
  1355.  
  1356.        3.17 Self-continuing Batch Files
  1357.  
  1358.        Because  so  much  computer  time  is required to create ray traced
  1359.        animations, it is sometimes necessary to produce the  frames  using
  1360.        a  series  of  runs  rather than in a single run.  Using RTAG it is
  1361.        easy to produce BAT files that automatically will restart with  the
  1362.        first  frame  that  does not exist.  This is done by generating "IF
  1363.        EXIST...GOTO" commands as part of the batch file.  For  each  frame
  1364.        you  cause  the  BAT  file  to check if the TGA file exists; if so,
  1365.        control skips to the test for the next file.  The  following  is  a
  1366.        skeleton  of  an  RTAG  program to generate these statements.  Note
  1367.        the use of the `###`  sequence  to  substitute  the  current  frame
  1368.        number and the `+++` sequence to substitute the next frame number.
  1369.  
  1370.        Chapter 3. The Animation Control Language                        24
  1371.  
  1372.  
  1373.            while (curframe < lastframe) {
  1374.                nextframe;
  1375.                bwrite(":do`###`\n");
  1376.                bwrite("if exist tour`###`.tga goto do`+++`\n");
  1377.                << other commands to write info for this frame >>
  1378.            }
  1379.            epilog;
  1380.            bwrite(":do`+++`\n");
  1381.            bwrite("call dodta TOUR /S8\n");
  1382.  
  1383.        The  commands  written  to  the  BAT  file  for each frame have the
  1384.        following form:
  1385.  
  1386.            :do001
  1387.            if exist tour001.tga goto do002
  1388.            << commands to generate frame 1 >>
  1389.            :do002
  1390.            if exist tour002.tga goto do003
  1391.            << commands to generate frame 2 >>
  1392.            :do003
  1393.  
  1394.  
  1395.        3.18 Auxiliary Data Files
  1396.  
  1397.        RTAG provides functions to open, close, read  from,  and  write  to
  1398.        auxiliary  data  files.   This  is useful if some other program has
  1399.        computed  object  positions  or  other  data   that   affects   the
  1400.        animation.
  1401.  
  1402.        Up  to  30 auxiliary data files can be open at once.  The files are
  1403.        identified  by  numbers  (also  called  file  "handles")  that  are
  1404.        assigned  by  RTAG  at  the time that the file is opened.  The file
  1405.        numbers can be reused by closing and  reopening  files.   You  must
  1406.        use  the  VAR  statement  to  declare  variables  to  hold the file
  1407.        numbers.
  1408.  
  1409.        3.18.1 Opening a File for Reading
  1410.  
  1411.        The form of the  statement  used  to  open  an  existing  file  for
  1412.        reading is:
  1413.  
  1414.            variable = open("file name");
  1415.  
  1416.        where  'variable'  is a varible you have previously declared with a
  1417.        VAR statement.  When RTAG opens the  file  it  generates  a  unique
  1418.        file  number  and  assignes  it  to the variable on the left of the
  1419.        equal sign.  This file number can  be  used  subsequently  in  READ
  1420.        functions.  An example of this statement is
  1421.  
  1422.            infile = open("spiral.dat");
  1423.  
  1424.        Chapter 3. The Animation Control Language                        25
  1425.  
  1426.  
  1427.        3.18.2 Creating an Output File
  1428.  
  1429.        The  form  of the statement used to create an auxiliary output file
  1430.        is
  1431.  
  1432.            variable = create("file name");
  1433.  
  1434.        When RTAG creates the file it assignes a unique file number to  the
  1435.        specified  variable.   This file number can be used subsequently in
  1436.        WRITE functions.  An example of this statement is
  1437.  
  1438.            outfile = create("trace.dat");
  1439.  
  1440.        3.18.3 Closing an Auxiliary File
  1441.  
  1442.        The function used to close an auxiliary file is:
  1443.  
  1444.            close(file)
  1445.  
  1446.        where 'file' is a variable that has a file number.  For example:
  1447.  
  1448.            close(outfile);
  1449.  
  1450.        Any  open  files  are  closed  automatically  when   your   program
  1451.        terminates.
  1452.  
  1453.        3.18.4 Reading from an Auxiliary File
  1454.  
  1455.        You  may  read  data  from  an  open auxiliary file by using a READ
  1456.        function of the following form:
  1457.  
  1458.            read(file,variable1,variable2,...);
  1459.  
  1460.        Where 'file' is a file number assigned  by  a  previously  executed
  1461.        OPEN  function.   Each  READ  function  call reads the next line of
  1462.        data from the file and  assigns  numeric  values  to  the  list  of
  1463.        variables  you specify.  There must be at least as many data values
  1464.        on the line as the number of  variables  specified  with  the  READ
  1465.        function  (additional  values are ignored).  The data values may be
  1466.        separated by spaces, tabs, and/or commas.  Numeric  values  may  be
  1467.        specified  in  the  same  form  as numbers within an RTAG animation
  1468.        control file (natural, exponential, or dd:dd:dd).
  1469.  
  1470.        The MOREDATA function can be used to control how many  records  are
  1471.        read  from  the  file.   The value of MOREDATA(file) is true (1) if
  1472.        there is another, unread, record available in the file;  its  value
  1473.        is  false  (0)  if  there  is  no  more data available in the file.
  1474.        MOREDATA does  not  consume  any  data,  it  just  checks  for  the
  1475.        availability  of  data.   The  following  statements would read all
  1476.        data in a file and generate a frame file for each record:
  1477.  
  1478.        Chapter 3. The Animation Control Language                        26
  1479.  
  1480.  
  1481.            var f,xpos,ypos;
  1482.            f = open("indata.dat");
  1483.            while (moredata(f)) {
  1484.                nextframe;
  1485.                read(f,xpos,ypos);
  1486.                owrite("#declare xpos=`xpos`\n");
  1487.                owrite("#declare ypos=`ypos`\n");
  1488.            }
  1489.  
  1490.        3.18.5 Writing to an Auxiliary File
  1491.  
  1492.        The form of the function used to write to an auxiliary file is:
  1493.  
  1494.            WRITE(file,"string"[,expression1,expression2,...]);
  1495.  
  1496.        where 'file' is a variable containing a file number assigned  by  a
  1497.        previously  executed  CREATE function.  "string" is a quoted string
  1498.        of the same form as described for  the  PRINT,  OWRITE  and  BWRITE
  1499.        functions.    The   string  may  include  variable  and  expression
  1500.        replacement  operators.   Expression1,   expression2,   etc.    are
  1501.        optional  expressions  whose  values are to be substituted into the
  1502.        string where "%w.dlf" sequences occur.   The  following  statements
  1503.        illustrate the use of the WRITE function:
  1504.  
  1505.            var f,x,y;
  1506.            f = create("sine.out");
  1507.            for (x=0; x<360; x+=2) {
  1508.                y = sin(x);
  1509.                write(f,"x=`x`, y=`y`\n");
  1510.            }
  1511.            close(f);
  1512.  
  1513.  
  1514.        3.19 Notes About The System Variables
  1515.  
  1516.        There  are  four  system  variables  that  affect frame generation:
  1517.        curframe, firstframe, lastframe, and  stepinc.   Curframe  has  the
  1518.        current  frame  number.   Its  initial  value is 0 before the first
  1519.        frame is started.  The NEXTFRAME statement closes the  output  file
  1520.        (OFILE)  if  it is open, increments the value of curframe by 1, and
  1521.        opens a new output file (if  an  OFILE  statement  was  specified).
  1522.        The  following  loop  would be appropriate to generate an animation
  1523.        with 60 frames:
  1524.  
  1525.            while (curframe < 60) {
  1526.                nextframe;
  1527.                << commands to generate frame >>
  1528.            }
  1529.  
  1530.        By default, firstframe has a value of 1, lastframe has a  value  of
  1531.        999999,  and  stepinc  has  a  value  of  1.  There are two ways to
  1532.        assign different values to these variables: the  VAR  statement  or
  1533.        with  command  line  options (/F, /L, and /S).  The main reason for
  1534.        setting firstframe and stepinc to something  other  than  1  is  to
  1535.        make  an  abbreviated  animation which will give you an idea of how
  1536.  
  1537.        Chapter 3. The Animation Control Language                        27
  1538.  
  1539.  
  1540.        objects will move without spending the  time  rending  all  of  the
  1541.        images  for  a  full  animation.   The  following  example  shows a
  1542.        command file that will generate images for frames  10  through  60,
  1543.        stepping 5 between the frames:
  1544.  
  1545.            var firstframe = 10;
  1546.            var lastframe = 60;
  1547.            var stepinc = 5;
  1548.            while (curframe < lastframe) {
  1549.                nextframe;
  1550.                << commands to generate frame >>
  1551.            }
  1552.  
  1553.        The  effect  of setting firstframe to something other than 1 may be
  1554.        different  than  what  you  expect.   The  current   frame   number
  1555.        (curframe)  ALWAYS  starts at 0 and increments by 1.  If firstframe
  1556.        is set to something other than 1, the OWRITE and  BWRITE  functions
  1557.        have  no effect until the frame number reaches the firstframe value
  1558.        (i.e., when executed they do not write anything to  a  file).   The
  1559.        reason  that  firstframe  works like this is that when performing a
  1560.        simulation the state of the  system  usually  depends  on  previous
  1561.        iterations  (e.g.,  the  position  of a falling ball depends on how
  1562.        long it has been dropping  and  whether  it  has  already  hit  the
  1563.        floor).   Because of this it is necessary to start at the beginning
  1564.        each time.  However, by cancelling the actions of  the  OWRITE  and
  1565.        BWRITE  functions  prior to firstframe, you can save the expense of
  1566.        rendering frames before the one of interest.
  1567.  
  1568.        There are two exceptions to this  rule.   BWRITE  functions  always
  1569.        generate  output  before  the  first  execution  of  the  NEXTFRAME
  1570.        statement regardless of the value  of  firstframe,  lastframe,  and
  1571.        stepinc.   This  is  done  so that initialization statements can be
  1572.        generated before the frame  generation  iteration  begins.   BWRITE
  1573.        functions  also  always  generate  output after the execution of an
  1574.        EPILOG statement.  This is done so that you can write  cleanup  and
  1575.        termination  commands to the batch and auxiliary files.  PRINTF and
  1576.        WRITE  functions  generate  output  regardless  of  the  value   of
  1577.        firstframe.
  1578.  
  1579.        The  effect  of  stepinc  is  similar to firstframe.  The NEXTFRAME
  1580.        statement ALWAYS increments the frame number by 1.  If  stepinc  is
  1581.        not  1, OWRITE and BWRITE functions are disabled between the steps.
  1582.        BWRITE always generates output before the execution  of  the  first
  1583.        NEXTFRAME statement and after execution of an EPILOG statement.
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.                                     Chapter 4
  1591.  
  1592.                            Animation And Time Control
  1593.  
  1594.  
  1595.  
  1596.  
  1597.        Time  is  an  essential  component  of  any  animation.  Except for
  1598.        special  effects,  time  advances  by  a  constant  amount  between
  1599.        frames.   Most RTAG animation control files will have an outer loop
  1600.        advancing through either frames or time.  For simple animations  it
  1601.        is   usually   easier  to  loop  through  frames,  calculating  the
  1602.        simulated time as a function of the  frame  number.   For  example,
  1603.        the  following  statements  would move an object along a sinusoidal
  1604.        (wavey) path using the frame number  as  an  argument  to  the  SIN
  1605.        function:
  1606.  
  1607.            while (curframe < 60) {
  1608.                nextframe;
  1609.                x = -6 + (curframe / 5);
  1610.                y = 3 * sin(curframe * 12);
  1611.                << other statements to generate output >>
  1612.            }
  1613.  
  1614.        This  approach  works well for simple animations where the position
  1615.        of the objects can be calculated as a direct function of the  frame
  1616.        number.   However,  for  more  complex animations, especially those
  1617.        involving acceleration and interactions between objects, it may  be
  1618.        necessary  to  perform  the simulation with smaller time steps than
  1619.        the time between frames.  In other words,  the  outer  loop  should
  1620.        advance  the  simulation  time  and  frames  should be generated at
  1621.        periodic  intervals  to  take  "snapshots"  of  the  objects.   The
  1622.        following statements illustrate this approach:
  1623.  
  1624.            for (time=0; time<endtime; time+=timestep) {
  1625.                //  Calculate updated positions of objects
  1626.                x = x + xspeed * timestep;
  1627.                y = y + yspeed * timestep;
  1628.                << other statements to compute object positions >>
  1629.                //  See if it is time to generate a frame
  1630.                if (time >= frametime) {
  1631.                    //  Generate a frame
  1632.                    nextframe;
  1633.                    << statements to write to files >>
  1634.                    //  Calculate when next frame should be generated
  1635.                    frametime = frametime + sampletime;
  1636.                }
  1637.            }
  1638.  
  1639.  
  1640.  
  1641.  
  1642.                                        28
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.                                     Chapter 5
  1650.  
  1651.                                Example Animations
  1652.  
  1653.  
  1654.  
  1655.  
  1656.        The  RTAG  distribution  comes with several example files which are
  1657.        explained below.  For each example there  is  an  ".RTA"  animation
  1658.        command file and a ".POV" POV-Ray scene description file.
  1659.  
  1660.        TOUR  --  There  is a simulated "city" (would you believe a village
  1661.            with  high  rise  buildings?).   The  camera  begins  from  the
  1662.            distance,  sweeps  down and along "Main Street", circles a dome
  1663.            structure at the end, and then climbs while still  keeping  the
  1664.            buildings  in  view  as  it moves away.  The SPLINE function is
  1665.            used both to control the position of the camera  and  also  the
  1666.            location  that  the  camera  is  looking  at.   This  120-frame
  1667.            animation takes about 6 hours to render in  320x200  size  with
  1668.            anti-aliasing turned on running on a 486/33 using POV-Ray.
  1669.  
  1670.        BOUNC  --  Bouncing  ball  simulation.   A  ball rolls down a ramp,
  1671.            falls, bounces twice, and ends up in landing in  a  can.   This
  1672.            is  a  good  example  of a simulation where time is advanced in
  1673.            small  steps  and  frames   are   generated   periodically   as
  1674.            "snapshots"  of  the  scene.   The  position  of  the  ball  is
  1675.            calculated  using  elementary  physics:   The   speed   of   an
  1676.            accelerating  object  at the end of a time interval is equal to
  1677.            its speed at the beginning plus the acceleration multiplied  by
  1678.            the  time  interval.  The position at the end of an interval is
  1679.            equal to the position at the start of  the  interval  plus  the
  1680.            speed  multiplied  by  the time interval.  An animation with 60
  1681.            to 70 frames seems to work best with this example.
  1682.  
  1683.        ORBIT -- Orbital simulation.   Three  planets  move  in  elliptical
  1684.            orbits  around  a  sun.   One  of  the  planets has a moon in a
  1685.            circular orbit.  The  orbital  speeds  of  the  planets  follow
  1686.            Kepler's  laws.   If you look closely you can see the shadow as
  1687.            one planet eclipes  another.   The  200  frame  sequence  takes
  1688.            about 4 hours to render on a 386/25 with coprocessor.
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.                                        29
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.                                     Chapter 6
  1709.  
  1710.                           Use And Distribution of RTAG
  1711.  
  1712.  
  1713.  
  1714.  
  1715.        You  are welcome to make copies of this program and pass them on to
  1716.        friends or post this program on bulletin boards  or  distribute  it
  1717.        via  disk catalog services provided the entire RTAG distribution is
  1718.        included in its original, unmodified form.  A distribution fee  may
  1719.        be  charged  for  the  cost of the diskette, shipping and handling.
  1720.        However, RTAG may not be sold, or incorporated in  another  product
  1721.        that  is  sold,  without  the  permission  of  Phillip H.  Sherrod.
  1722.        Vendors are encouraged to  contact  the  author  to  get  the  most
  1723.        recent version of RTAG.
  1724.  
  1725.        As  a shareware product, you are granted a no-cost, trial period of
  1726.        30 days during which you may evaluate RTAG.  If you  find  RTAG  to
  1727.        be  useful,  educational,  and/or entertaining, and continue to use
  1728.        it beyond the 30 day trial period, you are required  to  compensate
  1729.        the  author  by sending the registration form printed at the end of
  1730.        this  document  (and  in   REGISTER.DOC)   with   the   appropriate
  1731.        registration  fee  to  help  cover  the  development and support of
  1732.        RTAG.
  1733.  
  1734.        In return for registering,  you  will  be  authorized  to  continue
  1735.        using  RTAG  beyond  the trial period and you will receive the most
  1736.        recent version of the program, a laser-printed, bound  manual,  and
  1737.        three  months  of support via telephone, mail, or CompuServe.  Your
  1738.        registration fee will be refunded if you encounter  a  serious  bug
  1739.        that cannot be corrected.
  1740.  
  1741.        You are welcome to contact the author:
  1742.  
  1743.                                Phillip H. Sherrod
  1744.                                 4410 Gerald Place
  1745.                          Nashville, TN  37205-3806  USA
  1746.                              615-292-2881 (evenings)
  1747.                              CompuServe: 76166,2640
  1748.                        Internet: 76166.2640@compuserve.com
  1749.  
  1750.        Both  the  RTAG program and documentation are copyright (c) 1993 by
  1751.        Phillip  H.   Sherrod.   You  are  not  authorized  to  modify  the
  1752.        program.  "RTAG" is a trademark.
  1753.  
  1754.        This  program  is  produced  by  a  member  of  the  Association of
  1755.        Shareware Professionals (ASP).  ASP wants to  make  sure  that  the
  1756.        shareware  principle works for you.  If you are unable to resolve a
  1757.        shareware-related problem with an  ASP  member  by  contacting  the
  1758.  
  1759.  
  1760.                                        30
  1761.  
  1762.        Chapter 6. Use And Distribution of RTAG                          31
  1763.  
  1764.  
  1765.        member  directly,  ASP  may be able to help.  The ASP Ombudsman can
  1766.        help you resolve a dispute or problem with an ASP member, but  does
  1767.        not  provide technical support for members' products.  Please write
  1768.        to the ASP Ombudsman at 545 Grover  Road,  Muskegon,  MI  49442  or
  1769.        send  a  CompuServe  message  via  CompuServe Mail to ASP Ombudsman
  1770.        7007,3536.
  1771.  
  1772.  
  1773.        6.1 Disclaimer
  1774.  
  1775.        RTAG is provided "as is"  without  warranty  of  any  kind,  either
  1776.        expressed   or  implied.   This  program  may  contain  "bugs"  and
  1777.        inaccuracies, and its results should not be assumed to  be  correct
  1778.        unless  they are verified by independent means.  The author assumes
  1779.        no responsibility for the use of RTAG and will not  be  responsible
  1780.        for any damage resulting from its use.
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.                                     Chapter 7
  1788.  
  1789.                                  Other Software
  1790.  
  1791.  
  1792.  
  1793.  
  1794.        If  you  like  RTAG, you should check out the following programs by
  1795.        the same author.
  1796.  
  1797.  
  1798.        7.1 Mathplot -- Mathematical Function Plotting Program
  1799.  
  1800.        Mathplot allows you to specify complicated  mathematical  functions
  1801.        using  ordinary  algebraic  expressions  and immediately plot them.
  1802.        Four types of  functions  may  be  specified:  cartesian  (Y=f(X));
  1803.        parametric  cartesian (Y=f(T) and X=f(T)); polar (Radius=f(Angle));
  1804.        and parametric polar (Radius=f(T)  and  Angle=f(T)).   Up  to  four
  1805.        functions  may  be  plotted  simultaneously.  Scaling is automatic.
  1806.        Options are available to control axis display and labeling as  well
  1807.        as  grid  lines.   Hard  copy  output  may  be generated as well as
  1808.        screen  display.   Mathplot  is  an  ideal  tool   for   engineers,
  1809.        scientists,  math  and  science teachers, and anyone else who needs
  1810.        to quickly visualize mathematical functions.
  1811.  
  1812.  
  1813.        7.2 Nonlin -- Linear & Nonlinear Statistical Regression
  1814.  
  1815.        Nonlin  performs  linear  and  nonlinear   statistical   regression
  1816.        analysis.   What  is regression analysis?  Regression analysis is a
  1817.        mathematical  technique  for  determining  the   best   values   of
  1818.        parameters  to  fit  an  equation  to  a  set  of data points.  For
  1819.        example, you might want to develop an equation of the form
  1820.  
  1821.            price = p0 + p1*age + p2*miles
  1822.  
  1823.        to predict the price of a used car based on its age and the  number
  1824.        of  miles  driven.   With  Nonlin you can collect data from car ads
  1825.        and then perform the analysis using the following set of commands:
  1826.  
  1827.            VARIABLES PRICE,AGE,MILES
  1828.            PARAMETERS P0,P1,P2
  1829.            FUNCTION  PRICE = P0 + P1*AGE + P2*MILES
  1830.            DATA
  1831.  
  1832.        Nonlin will analyze the data and determine the best values  of  the
  1833.        parameters P0, P1, and P2 to fit the data values.
  1834.  
  1835.        Ordinary  linear  regression  programs can only determine parameter
  1836.        values for linear (straight line) equations.  Nonlin, on the  other
  1837.  
  1838.  
  1839.                                        32
  1840.  
  1841.        Chapter 7. Other Software                                        33
  1842.  
  1843.  
  1844.        hand,  can  handle  multivariate,  linear,  polynomial, and general
  1845.        nonlinear equations.  For example,  using  Nonlin  you  can  easily
  1846.        determine  the  best  values  for the parameters Offset, Amplitude,
  1847.        and Frequency for an equation of the form:
  1848.  
  1849.            Y = Offset + Amplitude * sin(Frequency * X)
  1850.  
  1851.        Nonlin uses the same expression evaluator as Mathplot  so  you  can
  1852.        model  complicated  equations  using  the full set of operators and
  1853.        library functions available in Mathplot.
  1854.  
  1855.        Nonlin comes  with  a  48  page  manual  that  explains  regression
  1856.        analysis  and  gives  many  examples.   Nonlin  is  in  use at many
  1857.        universities and research labs around the world.
  1858.  
  1859.  
  1860.        7.3 TSX-32 -- Multi-User Operating System
  1861.  
  1862.        If you have  a  need  for  a  multi-user,  multi-tasking  operating
  1863.        system,  you  should  look into TSX-32.  TSX-32 is a full-featured,
  1864.        high performance, multi-user operating system for the 386  and  486
  1865.        that  provides  both  32-bit  and  16-bit  program  support.   With
  1866.        facilities such  as  multitasking  and  multisessions,  networking,
  1867.        virtual  memory,  X-Windows, background batch queues, data caching,
  1868.        file  access  control,  real-time,  and  dial-in  support,   TSX-32
  1869.        provides a solid environment for a wide range of applications.
  1870.  
  1871.        A  two  user,  shareware  version of TSX-32 called TSX-Lite is also
  1872.        available.
  1873.  
  1874.        TSX  is  particularly  valuable  for  ray  tracing  and   animation
  1875.        generation  which  can  take  a  long  time to run.  These jobs can
  1876.        execute as background "batch" jobs while  you  perform  interactive
  1877.        operations with virtually no degredation from the batch execution.
  1878.  
  1879.        TSX-32  is  not a limited, 16-bit, multi-DOS add-on.  Rather, it is
  1880.        a complete 32-bit operating system which  makes  full  use  of  the
  1881.        hardware's  potential,  including protected mode execution, virtual
  1882.        memory, and demand paging.  TSX-32 sites range from  small  systems
  1883.        with  2-3  terminals  to  large  installations  with  more than 100
  1884.        terminals on a single 486.
  1885.  
  1886.        In addition to supporting most popular 16-bit DOS programs,  TSX-32
  1887.        also  provides a 32-bit "flat" address space with both Phar Lap and
  1888.        DPMI compatible modes of execution.
  1889.  
  1890.        Since the DOS file  structure  is  standard  for  TSX-32,  you  can
  1891.        directly  read  and  write DOS disks.  And, you can run DOS part of
  1892.        the time and TSX-32 the rest of the time on the same computer.
  1893.  
  1894.        TSX-32 allows each user to control up  to  10  sessions.   Programs
  1895.        can  also  "fork"  subtasks  for  multi-threaded applications.  The
  1896.        patented Adaptive Scheduling Algorithm provides  consistently  good
  1897.        response time under varying conditions.
  1898.  
  1899.        Chapter 7. Other Software                                        34
  1900.  
  1901.  
  1902.        The   TSX-32  network  option  provides  industry  standard  TCP/IP
  1903.        networking through Ethernet and serial lines.  Programs can  access
  1904.        files  on  remote  machines as easily as on their own machine.  The
  1905.        SET HOST command allows a user on one machine to log  onto  another
  1906.        computer  in  the  network.  FTP, Telnet, and NFS are available for
  1907.        interoperability with other systems.
  1908.  
  1909.        TSX-32 is, quite simply,  the  best  and  most  powerful  operating
  1910.        system  available  for the 386 and 486.  For additional information
  1911.        contact:
  1912.  
  1913.                            S&H Computer Systems, Inc.
  1914.                              1027 17th Avenue South
  1915.                              Nashville, TN 37212 USA
  1916.                               615-327-3670 (voice)
  1917.                                615-321-5929 (fax)
  1918.                               CompuServe: 71333,27
  1919.                         Internet: 71333.27@compuserve.com
  1920.  
  1921.          ===============================================================
  1922.                                Software Order Form
  1923.          ===============================================================
  1924.  
  1925.        Name ______________________________________________________
  1926.  
  1927.        Address ___________________________________________________
  1928.  
  1929.        City _______________________  State _______ Zip ___________
  1930.  
  1931.        Country ____________________
  1932.  
  1933.        Telephone _________________________________________________
  1934.  
  1935.        CompuServe account (optional) _____________________________
  1936.  
  1937.        RTAG version ______________________________________________
  1938.  
  1939.        Bulletin board where you found RTAG _______________________
  1940.  
  1941.        Comments __________________________________________________
  1942.  
  1943.        Check the boxes which indicate your order type:
  1944.  
  1945.            ___ I wish to register RTAG ($20).
  1946.  
  1947.            ___ I wish to order Mathplot ($20).
  1948.  
  1949.            ___ I wish to order Nonlin ($25)
  1950.  
  1951.        Add $5 to the total amount of the order if the  software  is  being
  1952.        shipped out of the United States.
  1953.  
  1954.        In  return  for  registering,  you  will  receive  the  most recent
  1955.        version of the program, a laser-printed, bound copy of the  manual,
  1956.        and   three  months  of  telephone  or  CompuServe  support.   Your
  1957.        registration fee will be refunded if you find a  serious  bug  that
  1958.        cannot be corrected.
  1959.  
  1960.        Distribution disk choice (check one):
  1961.  
  1962.              3.50" HD (1.4 MB)  ______
  1963.              5.25" HD (1.2 MB)  ______
  1964.              5.25" DD (360 KB)  ______
  1965.  
  1966.        Send this form with the amount indicated to the author:
  1967.  
  1968.                                Phillip H. Sherrod
  1969.                                 4410 Gerald Place
  1970.                           Nashville, TN  37205-3806 USA
  1971.  
  1972.                              615-292-2881 (evenings)
  1973.                              CompuServe: 76166,2640
  1974.                        Internet: 76166.2640@compuserve.com
  1975.  
  1976.        Index                                                            36
  1977.  
  1978.  
  1979.        ABS function, 10                   FLOOR function, 10
  1980.        ACOS function, 10                  FOR statement, 20
  1981.        AND operator, 9                    GAMMA function, 11
  1982.        Arithmetic operators, 8            GRAPHDEV forum, 5
  1983.        Array variables, 16                IF statement, 18
  1984.        ASIN function, 10                  #include statement, 1
  1985.        ASP, 30                            INT function, 11
  1986.        Assignment operator, 18            Internet, 34
  1987.        Assignment operators, 9            /L option, 6, 17
  1988.        ATAN function, 10                  lastframe variable, 16, 26
  1989.        Auxiliary data files, 24           LINEAR function, 11, 13
  1990.        /B option, 6                       Listing file, 17
  1991.        Batch file, 17                     LOG function, 11
  1992.        Batch jobs, 33                     LOG10 function, 11
  1993.        Berry, Bob, 4                      Logical operators, 9
  1994.        BFILE statement, 17                Mason, David K., 4
  1995.        BOB, 4                             Mathplot, 32
  1996.        BOUNC.POV example, 29              MAX function, 11
  1997.        BREAK statement, 19, 20            MIN function, 11
  1998.        Bulletin boards, 5                 MOD function, 11
  1999.        BWRITE function, 17, 21, 27        MOREDATA function, 11, 25
  2000.        CEIL function, 10                  Multi-user operating system,
  2001.        CLOSE function, 10, 25                      33
  2002.        Comments, 15                       /N option, 6
  2003.        Comparison operators, 9            Networking, 34
  2004.        CompuServe, 34                     NEXTFRAME statement, 18, 23,
  2005.        Constants, 9                                26, 27
  2006.        CONTINUE statement, 19, 21         Nonlin, 32
  2007.        Copyright notice, 30               Nonlinear regression, 32
  2008.        COS function, 10                   NOT operator, 9
  2009.        Cosecant function, 10              NPD function, 11
  2010.        COSH function, 10                  Numeric constants, 9
  2011.        COT function, 10                   /O option, 6
  2012.        Coy, Stephen, 4                    OFILE statement, 17, 23, 26
  2013.        CREATE function, 10, 25, 26        OPEN function, 12, 24
  2014.        Crocker, Daniel, 4                 Operators
  2015.        CSC function, 10                      arithmetic, 8
  2016.        CSHOW, 4                              assignment, 9
  2017.        curframe variable, 16, 26             comparison, 9
  2018.        Curve fitting, 32                     logical, 9
  2019.        DEG function, 10                      precedence of, 9
  2020.        Disclaimer, 31                     OR operator, 9
  2021.        DO statement, 19                   ORBIT.POV example, 29
  2022.        DPMI support, 33                   Order form, 35
  2023.        DTA, 4                             OWRITE function, 21, 27
  2024.        Enzmann, Alexander R., 4           /P option, 7
  2025.        EPILOG statement, 23, 27           PAREA function, 12
  2026.        Example animations, 29             PI constant, 10
  2027.        EXP function, 10                   Piclab, 4
  2028.        Exponential, 10                    PLAY.EXE, 5
  2029.        /F option, 6, 17                   Polyray, 4
  2030.        FAC function, 10                   POV-Ray, 4
  2031.        Finlay, Mark, 4                    Precedence of operators, 9
  2032.        firstframe variable, 16, 26        PRINTF function, 12, 21, 27
  2033.        FLI file, 4                        PULSE function, 12
  2034.  
  2035.        Index                                                            37
  2036.  
  2037.  
  2038.        RAD function, 12
  2039.        RANDOM function, 12, 17
  2040.        READ function, 12, 25
  2041.        Real-time, 33
  2042.        Redirection operator, 3
  2043.        Registering RTAG, 30
  2044.        Registration form, 35
  2045.        Regression analysis, 32
  2046.        Relational operators, 9
  2047.        ROUND function, 12
  2048.        /S option, 7, 17
  2049.        S&H Computer Systems, Inc.,
  2050.                 34
  2051.        SEC function, 12
  2052.        SEL function, 12
  2053.        Sherrod, Phillip H., 30
  2054.        SIN function, 12
  2055.        SINH function, 12
  2056.        SPLINE function, 12, 13, 14
  2057.        SQRT function, 13
  2058.        srand variable, 16, 17
  2059.        STEP function, 13
  2060.        stepinc variable, 16, 26, 27
  2061.        Stone Soup Group, 4
  2062.        STOP statement, 21
  2063.        SUBCHAR statement, 22
  2064.        Subscripts, 16
  2065.        Syntax, 15
  2066.        /T option, 7
  2067.        TAN function, 13
  2068.        TANH function, 13
  2069.        Targa files, 4
  2070.        TCP/IP, 34
  2071.        Time control, 28
  2072.        TOUR.POV example, 29
  2073.        Trilobyte, 5
  2074.        TSX-32, 33
  2075.        TSX-Lite, 33
  2076.        VAR statement, 15
  2077.        Warranty, 31
  2078.        Watkins, Christopher, 4
  2079.        Wells, Drew, 4
  2080.        WHILE statement, 19
  2081.        WRITE function, 13, 26, 27
  2082.        X windows, 33
  2083.