CS 455 - Programming Assignment 5

This assignment is about using nested, hierarchical models in OpenGL. There are two problems.

Download this zip file. In the zip file you will find a skeleton OpenGL program called problem1.c. Your program should redo the "Pythagoras Tree" from homework assignment 1, but this time using OpenGL, nested transformations, and a couple of extra sliders. The first slider, as before, determines the height of the roof in the basic polygon. The second slider determines the horizontal placement of the roof peek. The third slider scales the whole picture, so that you can see all of the image even when it grows very large. You need to complete the recursive function drawShape() so that it (1) draws the basic polygon in the current coordinate system, then (2) translates, rotates, scales the coordinate system and then calls itself recursively, and then (3) translates, rotates, scales the coordinate system again and then calls itself recursively once more. Here is an example of what your program should look like.

problem 1

When you need to compute the angles for your rotations, the following function should be useful.

atan2()

For the second problem, write an OpenGL program called problem2.c that draws six "bricks", each of a different color, that are stacked on top of each other as shown in the following image. The user can click on a brick and move it horizontally. As a brick moves, the bricks on top of it move with it. When a brick hits a brick next to it, or the edge of the window, the brick cannot be moved any more in that direction.

problem 2

When a user clicks on a brick, there is a trick to make it easy to figure out which brick they clicked on. (The hard way is to convert the mouse pointer coordinates into world coordinates and then try to figure out, in world coordinates, which brick contains the mouse pointer,) The easy way is to ask OpenGL for the color of the pixel that the mouse clicked on. Since every brick has a different color, knowing the color of the pixel determines which brick was chosen. You ask OpenGL for the color of a pixel by using the glReadPixels() function. There is a demonstration program in the zip file showing you how to use this function. Here is the function's documentation.

glReadPixels()

Turn in a zip file called CS455Hw5Surname.zip containing your versions of the two C programs problem1.c, problem2.c, and problem3.c. Please remember to put your name inside of each of your source files. This assignment is due Monday, March 21.


Return to the main homework page.
Return to the CS 45500 home page.


compliments and criticisms