Project 6: Bezier Curves
In this project you will need to implement functionality to generate surfaces of revolution using Bezier curves. This project is due on Friday, November 12th. The project will be introduced in the lab by Iman on Monday, November 8th.
1. Surface of Revolution using Bezier Curves (60 points)
Sample Bezier Curve Applet
Try out this interactive Java applet which will let you play with control points and see what the curves they produce look like. You can even turn on the C1 continuity hint to see where your next control point should go to have C1 continuity.
Algorithm (60 Points)
Implement a function that generates a surface of revolution using a Bezier curve. You can read up on surfaces of revolution on Mathworld or on Wikipedia. The main idea to generate a surface of revolution is to define a 2D curve in the xy plane, called the generatrix, which is then rotated around the y axis to produce the surface. DO NOT use any of the curve generating OpenGL routines for this part of the assignment (i.e., glMap, glEvalCoord, glMapGrid, glEvalMesh, gluNurbsCurve).
You should use a piecewise cubic Bezier curve as the generatrix. To produce a mesh of triangles or quads:
- Create a set of control points for the cubic Bezier generatrix that will create the object outline. Depending on how continuous you can make the curve you will get different numbers of points: C0 continuous: 5 points; C1 continuous: 10 points.
- Evaluate a number of sample points along the curve in the xy plane. (15 points)
- Rotate the points around the y axis at a set of angles, and connect the resulting points to a mesh of triangles or quads (10 points). The mesh needs to be closed (no gaps) (5 points). All visible surfaces need to pass backface culling (i.e., there should not be a visible difference between backface culling enabled and disabled) (5 points).
- Generate normals and texture coordinates at the mesh vertices. (15 points)
You can compute normals as follows: Given the generatrix curve
in the xy plane, you first compute the tangent vector
. The corresponding 3D normal vector is then
, which you rotate around the y axis similar as the vertices. Don't forget to normalize the normal vectors. For the uv texture coordinates, you can use the curve parameter at each vertex as the u parameter. The v parameter at each vertex is given by the rotation angle around the y axis you applied to get the vertex, divided by 360.
Your function to produce the surface of revolution should have the following input and output parameters:
Input:
- Number
of Bezier segments
- Array of Bezier control points in the xy plane, i.e.
. For
cubic segments, you will need
control points.
- Number of points to evaluate along the curve.
- Angle increment for a full 360 degree rotation.
Output:
- Array of vertices
- Array of normal vectors
- Array of texture coordinates
- Index array for triangle/quad vertices
2. Demo Scene (40 points)
Model a scene using surfaces of revolution, using the algorithm from part 1. Your scene should consist of at least three different objects. We propose you model a still life that consists of a round table with a few objects on it (if generated by the algorithm from part 1, the table counts as an object). You could model a wine bottle, a candle, a wine glass, a vase, an apple, a donut, a pen, or any other object you can think of, which can be created by a surface of revolution. Assign appropriate normals, textures, material properties, and colors to your objects. Use at least one light source to light your scene. All objects need to be textured to get full credit.
- First object: 5 points for texture, 5 points for normals/colors/material
- Second and third object: 5 points for control points, 5 points for texture, and 5 points for normals/colors/material
Note that you will only get the points for normals/colors/material if lighting is correctly set up with at least one light source.
3. Extra Credit (10 points)
Implement code to generate an animated flag:
- Create a cubic Bezier surface patch. Use uniform tessellation to produce the triangle mesh, and compute the normals as the cross product of the partial derivatives at each vertex (4 points).
- Assign texture coordinates to the mesh vertices using the parameter values. Choose a country's flag, coat of arms or other suitable image. Feel free to download it from the internet, for example flags for for: USA, Mexico, Canada. Make sure that your image has a resolution of at least 256x256 pixels so that it does not look fuzzy. If you need a tool to resize the image, we recommend IrfanView for Windows or ImageMagick for Linux. Map the texture to the Bezier patch. (3 points)
- Make sure that at least one OpenGL light source is enabled and configured to make the flag look nice and emphasize the curvature of its surface. (1 point)
- Use simple functions (e.g., linear, sin, cos) to move the control points in order to make the flag wave in the wind. Try using random numbers where appropriate to make the motion more realistic. Do not move the two interpolating control points at one end as this is where the flag is attached to the flag pole. (2 points)