RWORD – TECHNICAL BLOG

Get the Rhema’s Word on the vast world of technology!

Making a Tree in Open GL

leave a comment »

Computer graphics, though flashy and amazing, are all based off of mathematical formulas and algorithms. 3d graphics, in general, are all based off of polygons and verteces. In programming, I have found that once I can draw something, a huge amount of possible applications arise. In this tree example, I started by making a function that could draw a rectangle with any length, width, and angle. My rectangle function has 5 parameters, x, y, width, height, and angle. The x and y parameters represent the bottom of the rectangle.

By using recursion, I was able to start at the trunk of the tree and branch outward. Each limb, including the trunk, makes two other limbs that are smaller at different angles(so that the limbs fork). I use some randomization to make the tree look more natural. When the limbs stop spawning, they make some leaves. Here is the code and a picture.

Written by rhemalinder

April 18, 2008 at 9:35 pm

Leave a Reply