CMSC 435/634: Introduction to Computer Graphics

Assignment 4

Modeling

Due November 9, 2011

The Assignment

For this assignment, you will write a C++ program to create and render a 3D tree using an L-system and OpenGL. Your program should be based on either the assignment 3 starter code, your assignment 3 solution, or the assignment 4 starter code I provide (copies in ~olano/public/samples). You should read a text file to define the L-system. The first line should give a starting symbol or string. The remaining lines should define production rules for each non-terminal, so "A=A[+B]" would be a rule to replace A with A[+B]. Your grammar should use symbols for branch segments, to push and pop the transformation stack, and for various rotations. You should intially render the start string, but include keyboard controls, '+' to increase or '-' to decrease the number of generations of substitution to create your tree.

Your tree should be rendered using a collection of hexagonal cylinders. You should create the triangles for your cylinder branshes yourself with a vertex array and normal arra, all connected together with a triangle index array. The terrain example should help in seeing how to create the necessary arrays. For the lighting to work, you will need to compute a surface normal for each vertex, pointing outward from the branch axis. You can set the color of your branches with glColor3f(). The branches can just intersect through each other where branching occurs.

634 students (only): Include at least two different appearing symbols, for example branches and leaves.

Extra credit

Hammersley points
x (binary) z (binary) position   point distribution
000 000 (0,0)   X              
001 100 (1,4)           X      
010 010 (2,2)       X          
011 110 (3,6)               X  
100 001 (4,1)     X            
101 101 (5,5)             X    
110 011 (6,3)         X        
111 111 (7,7)                 X

There are three options for extra credit this assignment, for a possible total of 30 points. Since the extra credit is more than the late penalty, you are only eligible for extra credit if you use your free late or turn the assignment in on time.

The first option, for 5 possible points, is to keep the same cross sectional area before and after each branch point. In other words, a trunk of radius r has area proportional to r2, so if it splits into two branches, their radii should be chosen to also give a total area proportional to r2. So r2 = r12 + r22. There are physical reasons that trees generally follow this ratio, so using it will make your trees look more realistic.

The second option, for 10 possible points, is to include randomization of all aspects of the L-system: branch length, branching angle, and selection among alternate substitution rules. Use a hash-based random number generator (like the TEA generator provided in my sample code), or re-seed your random number generator for each tree or frame to make sure you get the same tree every frame.

The third option, for 15 possible points, is to place a forest of trees on your the terrain. The x/z position should use a Hammersley distribution. The elevation should interpolate the triangle position to place the trees on top of the terrain. The Hammersley sequence is a quasi-random sequence, that gives a set of well spaced points (as compared to random sequences that can have clumping). For each point in the Hammersley sequence, one coordinate is the index of the point, and the second coordinate is the index with the bits reversed. See the 8-point example in the table above.

Strategy

Think first, then take an incremental approach to your development so you can check your code along the way. I would suggest starting with just text-based testing of your L-system grammar reading and L-system evolution. Then make your basic branch rendering. Extend to parse through the string and render the entire tree.

What to turn in

Turn in this assignment electronically by checking your source code into your assn4 CVS directory by 11:59 PM on the day of the deadline. Do your development in the assn4 directory so we can find it, and tag your submitted version with the 'submit' tag. As always, double check that you have submitted everything we need to build and run your submission. Be sure to include a Makefile that will build your project when we run 'make', and a readme.txt file telling us about your assignment. Do not forget to tell us what (if any) help did you receive from books, web sites or people other than the instructor and TA, details about how you implemented the extra credit (if attempted).