CPR(9.1)                                                 CPR(9.1)

     NAME
          cpr, cprview - cheesy polygon renderer and viewer

     SYNOPSIS
          fb/cpr [ -a aspect ] [ -c rgbaz ] [ -w nx ny ] file ...

          fb/cprview [ file ... ]

     DESCRIPTION
          Cpr creates an image from a list of polygons in three dimen-
          sions.  Its output is a picture file, written to standard
          output.  The -w flag sets the width and height of the output
          file.  The default size is 640×480.  The -a flag indicates
          the aspect ratio of the image.  The default aspect ratio is
          the ratio of the output file's width and height, in pixels.
          It may be set independently to handle displays with non-
          square pixels.  The -c flag indicates which channels the
          output image should have.  Possible values are -crgb (the
          default), -crgba, and -crgbaz.

          Cpr's input is a simple textual command language, read from
          the input files named on the command line (default standard
          input).  Each command is a single character followed by
          arguments, separated by spaces.  The commands are:

          v  fov near far ex ey ez lx ly lz ux uy uz
               Set viewing parameters.  Fov is the horizontal field-
               of-view angle.  (ex, ey, ez) is the eye location from
               which the scene is viewed.  These and all other coordi-
               nates are floating point values.  (lx, ly, lz) is the
               location the eye is looking at - a point that the view-
               ing transformation will map to the center of the
               screen.  (ux, uy, uz) indicates the up direction.  It
               is the coordinate of a point that the viewing transfor-
               mation will map somewhere on the ray ascending from
               (lx, ly, lz) through the top of the screen.  Exactly
               where on that ray the image of (ux, uy, uz) is depends
               on the field of view angle.  Near and far are the dis-
               tances from the eyepoint to the near and far clipping
               planes.  Objects closer than near or farther than far
               will not be displayed.  Both near and far must be posi-
               tive, with far>near.

          t  x0 y0 z0 x1 y1 z1 x2 y2 z2 c0 c1
               draw a triangle.  (x0, y0, z0), (x1, y1, z1), and (x2,
               y2, z2) are the corners of the triangle.  C0 and c1 are
               the colors of the two sides of the triangle, with c0
               being the color of the side from which the vertices are
               viewed clockwise.  Color values are integers with abso-
               lute values no larger than 255.  Their absolute values

     Page 1                       Plan 9            (printed 12/21/24)

     CPR(9.1)                                                 CPR(9.1)

               index a table of colors whose entries are set using the
               c command (vide infra).  A positive color indicates
               that the object should be drawn in exactly that color;
               a negative value means that the polygon should be a
               shade of that color computed according to the light
               source position.

          p  c0 c1 [ x y z ]* ;
               draw a polygon.  C0 and c1 are the colors of its two
               sides.  The (x, y, z) values are its vertices.

          h  c0 c1 nx ny x0 y0 x1 y1 file
               draw a height field from a file of z values.  C0 and c1
               are its colors.  X0, y0, x1, and y1 give the range of x
               and y values.  The file contains an array of nx by ny
               floating point numbers, in row major order, in the
               native floating-point representation of the machine
               running cpr. This is not portable.

          s  c0 c1 x y z r
               draw a sphere of the given color, with center at (x, y,
               z) and radius r.

          {    push the transformation stack.  Cpr maintains a stack
               of transformation matrices.  The following transforma-
               tion commands operate on the top of the stack.  All
               objects to be drawn are operated on by this transforma-
               tion.

          }    pop the transformation stack

          R  angle axis
               Rotate by the given angle (in degrees) about the speci-
               fied axis, which must be 0 for x, 1 for y, or 2 for z.

          T  dx dy dz
               Translate by the given offset

          S  sx sy sz
               Scale by the given factors in the x, y, and z direc-
               tions.

          M  m00 m01 m02 m03 m10 m11 ... m33
               Multiply the top of the transformation stack by the
               given matrix.

          c  num r g b a
               Set the red, green, blue and α components of the num-
               bered color table entry.  Color components must be
               integers between 0 (black) and 255 (full on).

          l  x y z

     Page 2                       Plan 9            (printed 12/21/24)

     CPR(9.1)                                                 CPR(9.1)

               Set the direction that the light source shines from.

          b  r g b a
               Clear the background to the given color.

          Cprview displays a wire frame version of a cpr image in a
          window.  Dragging with button 1 rotates the image.  Button 2
          pops up a reread menu item that causes the input files to be
          reread.  Button 3 pops up a menu containing output and exit
          items.  Output writes a pic(1) representation of the display
          on standard output.  Exit exits.

     SOURCE
          /sys/src/fb/cpr.c
          /sys/src/fb/cprview.c

     Page 3                       Plan 9            (printed 12/21/24)