CMPS164, Spring 2012, Section 01: Minigolf Level Rendering






The first few lab assignments in this year's CMPS 164 will combine to form a fully functional minigolf game. Each assignment will ask you to add a new engine component to your minigolf project. This will include:


  • rendering individual minigolf hole layouts defined using a simple, extensible, exchangeable file format,
  • implementing ball physics to allow players to hit the ball and move it from the tee to the cup,
  • designing a user-interface layer, including options to load courses, user interactivity within and between holes, spash screens, high score tables, support for multiplayer games, and the ability to take screen shots, and
  • external objects within a minigolf hole layout (i.e., 3D models that can interact with the ball).

Development Environment


All programming for the assignments will be done in C++. Graphics will be implemented with OpenGL. The initial user interface could be implemented with the GL Utility Toolkit (GLUT) or QT, although many people will want to switch to another UI API (e.g., GLUI or Tcl/tk and TOGL) when the full user interface is designed.


Below are pointers to reference material that may be useful for completing the assignments. In particular, I strongly recommend you obtain access to a copy of the OpenGL Programming Guide (or equivalent), particularly if you've never programmed in OpenGL.


The TAs and I are happy to answer specific questions, and to offer basic suggestions on how to implement your assignments. However, we will not be teaching C/C++,OpenGL, GLUT, GLUI, linear algebra, or how to use the Visual C++ compiler and debugger. We expect you will either have these skills as

prerequisites to this course (i.e., C/C++, programming knowledge, linear algebra), or will learn the necessary material as part of completing your assignments.


Minigolf Hole Layout Definition


In Assignment #1 you will implement an OpenGL program that reads a minigolf hole layout and renders the hole as a 3D model with lighting and basic scene interaction.

A simple input language is used to define minigolf hole layouts. For this assignment the input language is restricted to the commands needed to specify a single minigolf hole. The input language will be extended in later assignments

to support a full course of minigolf holes and associated external objects.

A minigolf hole is constructed from a collection of one or more tiles. A tile is a planar, convex surface with three or more edges. An n-sided tile is specified as:

tile tile-ID n v1,x v1,y v1,z ... vn,x vn,y vn,z neighbour1 ... neighbourn 


  • tile is a keyword denoting that this line contains a tile definition,
  • tile-ID is a positive integer value that uniquely identifies the tile,
  • n is the number of edges in the tile,
  • vi,x vi,y vi,z is the (x,y,z) position of vertex i on the tile's boundary, and
  • neighbouri is the tile ID of a neighbouring tile that connects to this tile across edge i; if no neighbour exists (i.e., the tile edge represents a physical edge of the minigolf hole), the neighbour ID is less than or equal to 0.

For example, the following set of tile definitions:

tile 1 4 -0.5 0 1 0.5 0 1 0.5 0 0 -0.5 0 0 0 0 3 0
tile 2 4 -1.5 0 0 -0.5 0 0 -0.5 0 -1 -1.5 0 -1 0 3 0 0
tile 3 4 -0.5 0 0 0.5 0 0 0.5 0 -1 -0.5 0 -1 1 4 0 2
tile 4 4 0.5 0 0 1.5 0 0 1.5 0 -1 0.5 0 -1 0 0 0 3

would produce the following minigolf hole (shown both in geometric representation, and as a rendered 3D model). 



tiles (a) render (b)
Figure 1: (a) the geometric layout produced by the four tile definitions in the example text; (b) a representation of the same hole rendered with OpenGL


To simplify processing, you can assume the following about each tile definition:

  • vertices are specified in counterclockwise order,
  • tiles are convex,
  • no two edges of a tile are colinear,
  • height corresponds to the Y-direction, and
  • tiles in a minigolf hole will always maintain a consistent up-direction (i.e., a minigolf hole cannot "wrap around" in the Y-direction).

Two other commands complete the definition of a minigolf hole:

tee tile-ID teex teey teez

cup tile-ID cupx cupy cupz


  • tee is a keyword denoting that this line contains a tee definition,
  • cup is a keyword denoting that this line contains a cup definition,
  • tile-ID is a positive integer value that identifies which tile contains the tee (or cup)
  • teex teey teez is the (x,y,z) position of the tee, and
  • cupx cupy cupz is the (x,y,z) position of the cup.

tee represents the position where the ball starts. cup represents the location of the cup where the player is trying to put the ball.


Implementation Requirements

Your assignment must support the ability to read, parse, and render an arbitrary input stream that meets the above definitions. Your program will be executed from the command line as:

minigolf input_filename

where input_filename is the name of a file containing a minigolf hole layout.

Your completed assignment must include: 

  • Rendering: You must render each tile as a polygon with width, height, and depth (i.e., an n+2-sided "slab"). The tiles must fit together to form a seamless representation of the minigolf hole. Physical edges of the hole must be displayed with appropriate visual feedback (i.e., a border or edge). The position of the tee and the cup should also be displayed in an appropriate fashion.
  • Lighting:You must light the minigolf hole using OpenGL's lighting functions. You can choose either local or infinite lights sources, although we recommend using infinite light sources, since they are more efficient and should help you maintain an acceptable rendering rate. See Chapter 5 in the OpenGL Programming Guide (pp. 173 to 217) for a detailed description of how to implement lighting.
  • Interactivity:You must provide basic user interface operations (via GLUT/QT) to allow a viewer to translate the minigolf hole in X, Y, and Z, to rotate the hole about the X and Y-axes, and to quit the program.