Jabka Graphics Programming Reference

jabka/toad-stamp.gif

Donald H. House, June 28, 1996


This document gives a brief introduction to the special features of Jabka's version of the Scheme programming language that provide support needed for graphics programming. Central to providing this support is the addition to Scheme of two new atoms transforms and objects. This document deals with transforms, and also details a variety of procedures and definitions that facilitate dealing with geometric entities and with colors. All of these are explained below. Objects are the subject of a separate document entitled the Jabka Object System.

Contents

Points, Vertices and Polygons

Transforms

Colors


Points, Vertices and Polygons

Points, vertices and polygons are the basic building-blocks from which geometric models are built in Jabka. They are all specified using Scheme's list structure. More complex structures are built up from these simple structures using procedures that are defined in some of the following sections. The conventions for defining these geometric structures within Jabka are listed below.

definitions

procedures

The following procedures generate or operate on vertices, polygons, and points. Each function definition is followed by one or more examples. An example usually consists of a function call, followed by an arrow symbol ==>, followed by an S-expression. This indicates that the call would return the value to the right of the arrow.

Transforms

A transform is an atom that can be used in Jabka's version of Scheme to specify a transformation that is to be done on a geometric entity. The basic transformations that are directly supported in Jabka are translations, scales, and rotations. These basic transformations can also be composed together to form more complex transformations. The functions that actually make use of these transforms to operate on vertices and polygons are given below. Some of the methods that operate on geometric objects also make use of transforms (see the description of Xformables under the section on objects).

creating transforms

A transform is created by a call to one of the routines shown below. This transform is stored internally as 4 by 4 array of numbers. Simple transforms are composed together to make more complex transforms by matrix multiplication (an explanation of matrix multiplication is beyond the scope of this reference guide but can be found in any book on linear algebra). Since routines that print out or display transforms use this 4 by 4 notation, it will be helpful to know at least how the various simple transforms are stored. This is given below with the description of each transform creating routine.

     (identity) ==> #<TRANSFORM 1       0       0       0
                                0       1       0       0
                                0       0       1       0
                                0       0       0       1>
    (translate 100 -200 50)  ==>
       #<TRANSFORM     1       0       0       0
                       0       1       0       0
                       0       0       1       0
                       100     -200    50      1>

       i.e., a transform that will shift a vertex 100 in the x
       direction (right), -200 in the y direction (down), and 50
       in the z direction (into the screen).
    (x-rot 30)  ==>  #<TRANSFORM   1       0       0       0
                                   0       0.87    0.5     0
                                   0       -0.5    0.87    0
                                   0       0       0       1>

       i.e., a transform that will rotate a vertex about the x-axis
       by 30 degrees.  The rotation will be counter-clockwise if
       viewed standing at the origin, sighting along the x-axis.
    (y-rot 30)  ==>  #<TRANSFORM   0.87    0       -0.5    0
                                   0       1       0       0
                                   0.5     0       0.87    0
                                   0       0       0       1>

       i.e., a transform that will rotate a vertex about the y-axis
       by 30 degrees.  The rotation will be counter-clockwise if
       viewed standing at the origin, sighting along the y-axis.
    (z-rot 30)  ==>  #<TRANSFORM   0.87    0.5     0       0
                                   -0.5    0.87    0       0
                                   0       0       1       0
                                   0       0       0       1>

       i.e., a transform that will rotate a vertex about the z-axis
       by 30 degrees.  The rotation will be counter-clockwise if
       viewed standing at the origin, sighting along the z-axis.
    (scale 1 0.25 3)  ==>
       #<TRANSFORM     1       0       0       0
                       0       0.25    0       0
                       0       0       3       0
                       0       0       0       1>

       i.e., a transform that will scale a vertex by leaving its
       x-coordinate unchanged, reducing its y-coordinate to
       one-quarter of its original value, and tripling its z-coordinate.
    (compose (translate 100 0 0) (z-rot 30))  ==>
                   #<TRANSFORM 0.87    0.5     0       0
                               -0.5    0.87    0       0
                               0       0       1       0
                               100     0       0       1>

       i.e., a transform that will first shift a vertex by 100 in the
       x direction, then rotate it about the z-axis 30 degrees.

using transforms

The following procedures allow use of transforms to operate directly on vertices and polygons.

    (vertxform (identity) '(10 20 30))  ==>  (10 20 30)

    (vertxform (translate 10 -20 5) '(10 20 30))  ==>  (20 0 35)

    (vertxform (x-rot 30) '(10 20 30))  ==>  (10 2.321 35.98)

    (vertxform (y-rot 30) '(10 20 30))  ==>  (23.66 20 20.98)

    (vertxform (z-rot 30) '(10 20 30))  ==>  (-1.34 22.32 30)

    (vertxform (scale 1 0.25 3) '(10 20 30))  ==>  (10 5 90)

    (vertxform (compose (translate 10 0 0) (z-rot 30)) '(10 20 30)) ==>
                     (7.32 27.32 30)
    (polyxform (identity) '((0 0 10) (10 0 10) (0 10 10)))  ==>
           ((0 0 10) (10 0 10) (0 10 10))

    (polyxform (translate 10 -20 5) '((0 0 10) (10 10 10) (0 10 10))) ==>
           ((10 -20 15) (20 -20 15) (10 -10 15))

    (polyxform (x-rot 30) '((0 0 10) (10 0 10) (0 10 10)))  ==>
           ((0 -5 8.66) (10 -5 8.66) (0 3.66 13.66))

    (polyxform (y-rot 30) '((0 0 10) (10 0 10) (0 10 10)))  ==> 
           ((5 0 8.66) (13.66 0 3.66) (5 10 8.66))

    (polyxform (z-rot 30) '((0 0 10) (10 0 10) (0 10 10)))  ==>
           ((0 0 10) (8.66 5 10) (-5 8.66 10))

    (polyxform (scale 1 0.25 3) '((0 0 10) (10 0 10) (0 10 10)))  ==>
           ((0 0 30) (10 0 30) (0 2.5 30))

    (polyxform (compose (translate 10 0 0) (z-rot 30))
                  '((0 0 10) (10 0 10) (0 10 10)))  ==>
                   ((8.66 5 10) (17.32 10 10) (3.66 13.66 10))

Colors

Colors are specified using Scheme's list structure. They are used in defining the colors of lights, backgrounds and foregrounds, and in defining the surface colors of materials. The conventions for defining colors within Jabka are listed below.

definitions

conversion procedures

All routines in Jabka that expect a color as an argument require that color to be specified in the RGB system. The following procedures provide the color system conversions required if you want to work in either the HSV or HLS system.

interactively picking colors

predefined colors

The following named colors are predefined in Jabka. You can use these names wherever an rgb-color is called for.