CMSC 435/634: Introduction to Computer Graphics

Your program should support the following NFF commands

In the format descriptions, %g denotes a floating point number and %d denotes an integer. Coordinates are given in world space.

b
Background color.  A color is simply RGB with values between 0 and 1:
    "b" R G B

Format:
    b %g %g %g

    If no background color is set, assume RGB = {0,0,0}.
v
Viewpoint location.  Description:
    "v"
    "from" Fx Fy Fz
    "at" Ax Ay Az
    "up" Ux Uy Uz
    "angle" angle
    "hither" hither
    "resolution" xres yres

Format:
    v
    from %g %g %g
    at %g %g %g
    up %g %g %g
    angle %g
    hither %g
    resolution %d %d

The parameters are:

    From:  the eye location in XYZ.
    At:    a position to be at the center of the image, in XYZ world
           coordinates.  A.k.a. "lookat".
    Up:    a vector defining which direction is up, as an XYZ vector.
    Angle: in degrees, defined as from the center of top pixel row to
           bottom pixel row and left column to right column.
    Hither: distance of the hither [near] plane (if any) from the eye.  Mostly
           needed for hidden surface algorithms.
    Resolution: in pixels, in x and in y.
  Note that no assumptions are made about normalizing the data (e.g. the
  from-at distance does not have to be 1).  Also, vectors are not
  required to be perpendicular to each other.
  For all databases some viewing parameters are always the same:
    Yon is "at infinity."
    Aspect ratio is 1.0.

  A view entity must be defined before any objects are defined (this
  requirement is so that NFF files can be displayed on the fly by hidden
  surface machines).
f
Fill color and shading parameters.  Description:
    "f" red green blue Kd Ks Shine T index_of_refraction

Format:
    f %g %g %g %g %g %g %g %g

    RGB is in terms of 0.0 to 1.0.

    Kd is the diffuse component, Ks the specular, Shine is the Phong cosine
    power for highlights, T is transmittance (fraction of contribution of the
    transmitting ray).  Usually, 0 <= Kd <= 1 and 0 <= Ks <= 1, though it is
    not required that Kd + Ks == 1.  Note that transmitting objects ( T > 0 )
    are considered to have two sides for algorithms that need these (normally
    objects have one side).

    The fill color is used to color the objects following it until a new color
    is assigned.
Note - for this project, you are only concerned with the first three arguments: red, green, and blue. We will revisit the other arguments in project 5.
p
Polygon.  A polygon is defined as shown below:
    "p" total_vertices
    vert1.x vert1.y vert1.z
    [etc. for total_vertices vertices]

Format:
    p %d
    [ %g %g %g ] <- for total_vertices vertices

    A polygon is defined by a set of vertices. With these databases, a polygon 
    is defined to have all points coplanar. A polygon has only one side; the 
    order of the vertices is counterclockwise as you face the polygon 
    (right-handed coordinate system). The first two edges must form a non-zero 
    convex angle, so that the normal and side visibility can be determined by 
    using just the first three vertices.
s
Sphere.  A sphere is defined by a radius and center position:
    "s" center.x center.y center.z radius

Format:
    s %g %g %g %g

    If the radius is negative, then only the sphere's inside is visible
    (objects are normally considered one sided, with the outside visible).
    Currently none of the SPD scenes make use of negative radii.
    NOTE: Spheres are optional in this assignment.