230 likes | 243 Views
This article provides a review of trigonometry concepts and explains how to draw curves on curved surfaces using the depth buffer technique. It also includes examples of parametric equations for circles and helixes. The article demonstrates how to indicate depth in pictures using the glFrustum function.
E N D
Class 3:Chaps 2 cont. trig review drawing curves depth buffer perspective drawing curved surfaces
Trig Review: Definition of sine and cosine (Unit circle, radius=1) (cos sin ) (cos sin ) From Wikipedia, modified
1.0 0.0 cos(0) = sin(0) = (cos(0), sin(0))
0.0 1.0 cos(PI/2) = sin(PI/2) = (cos(PI/2), sin(PI/2))
-1.0 0.0 cos(PI) = sin(PI) = (cos(PI), sin(PI))
Change the radius from 1 to R (Rcos(), Rsin()) R
Move the center from (0,0) to (X,Y) (X+Rcos(), Y+Rsin()) R (X,Y) Y X (0,0)
Curved Objects • Run the program circle.cpp. Observe • instructions in comment and console screen • global variables • new version of color: glColor3ub • use of rand() • glutPostRedisplay in keyInput
The book also has parabola.cpp, another example of a curve described parametrically. Run it on your own.
Overwritten void drawDisc(float R, float X, float Y, float Z); glColor3f(0.0, 0.0, 1.0); drawDisc(20.0, 25.0, 75.0, 0.0); glColor3f(1.0, 1.0, 1.0); drawDisc(10.0, 25.0, 75.0, 0.0);
The real deal if (isWire) glPolygonMode(GL_FRONT, GL_LINE); else glPolygonMode(GL_FRONT, GL_FILL); glColor3f(1.0, 0.0, 0.0); glBegin(GL_TRIANGLE_STRIP); for(i = 0; i <= N; ++i) { angle = 2 * PI * i / N; glVertex3f(50 + cos(angle) * 10.0, 30 + sin(angle) * 10.0, 0.0); glVertex3f(50 + cos(angle) * 20.0, 30 + sin(angle) * 20.0, 0.0); } glEnd();
Floating glEnable(GL_DEPTH_TEST); // Enable depth testing. glColor3f(0.0, 1.0, 0.0); drawDisc(20.0, 75.0, 75.0, 0.0); glColor3f(1.0, 1.0, 1.0); drawDisc(10.0, 75.0, 75.0, 0.5); // Compare this z-value with that of the green disc. glDisable(GL_DEPTH_TEST);// Disable depth testing.
To use the depth buffer, you must initialize it in main. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); And clear it glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Hidden surface removal. glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
What is it? x = Rcos(t) y = Rsin(t) z = t - 60.0 -10*PI <= t <= 10*PI
Helix.cpp x = Rcos(t) y = Rsin(t) z = t - 60.0 -10*PI <= t <= 10*PI -31.4 31.4 -60 -60 _____ _____ z: -91.4 -28.6
Helixmod.cpp cont after a modification of view