230 likes | 235 Vues
On to 3D. Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast. Experiment 6.1. Run circularAnnuluses.cpp , three identical-looking circular annuluses are drawn in three different ways: Upper-left: the black disc overwrites the red disc
E N D
On to 3D Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast
Experiment 6.1 • Run circularAnnuluses.cpp, three identical-looking circular annuluses are drawn in three different ways: • Upper-left: the black disc overwrites the red disc • Upper-right: the black disc is draw closer to the viewer • Lower: a true circular annulus. • Interchange the drawing orders of the red and black discs in either of the top two annuluses. • Try to comment out glEnable(GL_DEPTH_TEST);andglDisable(GL_DEPTH_TEST);of the upper-right annulus.
The Depth (z) Buffer • Eliminate prior to rendering parts of objects that are obscured by others. • Hidden surface removal • Depth testing • Visibility determination
Enabling Hidden Surface Removal • glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);in main(). • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); in the main drawing routine. • glEnable(GL_DEPTH_TEST);andglDisable(GL_DEPTH_TEST);in the main drawing routine.
Experiment 6.2 • Run helix.cpp • x = Rcos(t), • y = Rsin(t), • z = t – 60.0, • -10p£ t £ 10p
Experiment 6.2 • Try to modify helix.cpp, so that the helix spirals up the y-axis, and x-axis. • Modify the code to make the helix to coil more and less round about its axis.
Perspective Projection • Frustum
Frustum • glFrustum (left, right, bottom, top, near, far) ((far/near) left, (far/near) top, -far) ((far/near) right, (far/near) top, -far) ((far/near) left, (far/near) bottom, -far) (left, top, -near) (right, top, -near) ((far/near) right, (far/near) bottom, -far) (left, bottom, -near) (right, bottom, -near) (0,0,0)
Experiment 6.3 • Modify helix.cpp, by replacing glOrtho(-50.0, 50.0, -50.0, 50.0, 0.0, 100.0) withglFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0) • Compute the co-ordinates of the frustum • Try with the y-axis and x-axis versions of the helix • Replace the glfrustum() with • glFrustum(-5.0, 5.0, -5.0, 5.0, 10.0, 100.0) • glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 120.0) • glFrustum(-10.0, 10.0, -10.0, 10.0, 10.0, 100.0)
Experiment 6.4 • Run moveSphere.cpp, press left, right, up, and down keys to move the sphere, the space bar to rotate it, and the ‘r’ to reset.
gluPerspective() • gluPerspective(fovy, aspect, near, far) • Calls a utility library routine built on top of glFrustum() • fovy – field of view angle • aspect – aspect ratio (width/height) • near, far – same as in glFrustum()
Experiment 6.5 • The projection statement of helix.cpp is the sysmetric • glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0); • Determine the equivalent gluPerspective() call. • Change the near value to 10.0 as • glFrustum(-5.0, 5.0, -5.0, 5.0, 10.0, 100.0); • Determine the equivalent gluPerspective() call. • Determine the equivalent glFrustum() call of • gluPerspective(60.0, 2.0, 10.0, 100.0); • gluPerspective(60.0, 1.0, 5.0, 100.0);
Experiment 6.6 • Run helix.cpp. • Drag a corner to change its size. • Replace the perspective projection with • gluPerspective(90.0, 1.0, 10.0, 100.0); • Try to change window size • Replace the perspective projection with • gluPerspective(90.0, (float)w/(float)h, 10.0, 100.0); • Try to change window size
Assignment 3 • Draw a red box and a blue pyramid using perspective projection. • Draw a cone and a cylinder using perspective projection. You can freely color your objects. • Draw two lampshades as in the figures. Color them as you like.
Assignment 3 • Note on assignment 3 • Make sure you have your shapes valid triangulation • Allow the user to toggle between the filled rendering and wireframe by pressing the space bar. • Instructions for user interaction should always be output to the main C++ Window and also be written as comments at the top of your program file.