SimpleNurbs
A program that draws a rational Bezier patch.
SimpleNurbs is a C program illustrating the use of OpenGL. It
is intended to accompany the book 3D Computer Graphics: A mathematical
approach with OpenGL, by S. Buss, Cambridge University Press, 2003.
However, it can be used independently as well.
SimpleNurbs draws a single rational Bezier patch. As such, it is
somewhat misleadingly named: it might have better been called
"SimpleRationalBezier", but that seemed to be too awkawrd a name.
The C code consists of two source files, SimpleNurbs.c and SimpleNurbs.h.
There are several options available for downloading this program:
Things to try out:
- Compile and run the program. There a number of keyboard controls:
- Press arrow keys (left, right, up and down) to make the patch rotate.
- Press "s" to single step the animation,
- Press "a" to start the animation running again without stopping. (Undoes
the "s" effect.)
- Press "r" to reset the patch back to its original orientation with no
velocity.
- Press "0" (zero) to zero the velocity of the patch, but leave its position
fixed.
- Press "p" to toggle between rendering in filled polygon mode, and in wireframe
mode.
- Press "f" to toggle between flat shading and smooth shading.
- Press "U" to increase the patch resolution in the "u" direction.
- Press "u" to decrease the patch resolution in the "u" direction.
- Press "V" to increase the patch resolution in the "v" direction.
- Press "v" to decrease the patch resolution in the "v" direction.
- Experiment with increasing the resolution of the mesh (controls "U" and
V"). Note how the specular highlights become better defined as the resolution
increases. Examine the code and see how the patch resolution is increased and
decreased.
- The crosssections of the Bezier patch are perfectly circular. This is possible
only with rational Bezier patches: review the theory in Chapter 7, and compare to how it
is implemented in the program.
- The program uses Bezier patches of order 4x4 or of order 3x4. As initially setup,
it uses order 4x4. Thus, its circular cross sections are defined with four control
points: the middle control points have weight 1/3.
- Try changing the variable USE_CNTLPT_AT_INFINITY to have value 1 instead of 0.
This changes the program so that it uses a Bezier patch of order 3x4 (order 3 in u,
order v in v). Now the circular crosssections are semicircles defined with order
three Bezier curves, and thus use control points which are points at infinity.
- You should be able to see specular highlights and other Phong lighting effects on both
sides of the Bezier patch. Is this true for you? I had to set the "Front
Face" option to "clockwise", with glFrontFace(GL_CW).
This doesn't seem like it should have been necessary --- is this a standard
OpenGL feature or a bug in OpenGL on my PC? (Any experts out there? Please let
me know.)