190 likes | 448 Views
Introduction of OpenGL - 3D Graphic and Animation. Luke Yulu Chen. 3D Graphic. Projections – Getting 3D to 2D. Two Projections. Orthographic Projection Perspective Projection. Orthographic. Perspective. Orthographic Projections. Command
E N D
Introduction of OpenGL- 3D Graphic and Animation Luke Yulu Chen
3D Graphic • Projections – Getting 3D to 2D
Two Projections • Orthographic Projection • Perspective Projection Orthographic Perspective
Orthographic Projections • Command • glOrtho ( double left, double right, double bottom, double top, double near, double far);
Perspective Projection • Command • gluPerspective ( double angle, double aspect, double near, double far);
Draw a 3D Model • Object Composition Polygon 3D Model
Object Composition • Use Transformation • glPushMatrix ( ); • glPopMatrix ( ); • Save the current transformation state and then restore it after some objects have been placed
Wheele 4 Wheele 3 Wheele 2 Wheele 1 The Car Body The Matrix Stack • Ex. Draw a car use transformation • The car body and four wheeles Transformation state Wheele 4
Hidden Surface Hidden Surface Removal • Enable Depth Testing • glEnable (GL_DEPTH_TEST);
Light and Surface Normal • A Normal Vector V3 = V1 X V2 Normal Vector P3 V2 P1 V1 P2
Draw Quadrics (1) • Rendering Spheres, Cylinders, and Disks • 1. Declare a quadrics pointer • GLUquadricObj *qobj; • 2. Create a quadrics object • qobj = gluNewQuadric ( );
Draw Quadrics (2) • Rendering Spheres, Cylinders, and Disks • 3. Specify the rendering attributes for the quadrics object • gluDrawStyle (qobj, GLU_FILL); • gluQuadricOrientation (qobj, GLU_OUTSIDE); • gluQuadricNormals (qobj, GLU_SMOOTH);
Draw Quadrics (3) • Rendering Spheres, Cylinders, and Disks • 4. Draw quadrics object • gluSphere (qobj, radius, slices, stacks); • gluCylinder (qobj, baseRadius, topRadius, height, slices, stacks); • gluDisk (qobj, innerRadius, outerRadius, slices, rings);
Draw Quadrics (4) • Rendering Spheres, Cylinders, and Disks • Slices and stacks Cylinder slices = 6 stacks = 6 Cylinder slices = 30 stacks = 30
Draw Quadrics (5) • Rendering Spheres, Cylinders, and Disks • 5. When you’re completely finished with drawing, destory this object • gluDeleteQuadric ( );
Animation • A Rotating Square Frame 0 Frame 1 Frame 2 Frame 3
Animation with OpenGL and GLUT • Motion = Redraw + Swap • Double Buffering • One is displayed while the other is being drawing. When the drawing of a frame is complete, the two buffers are swapped • glutSwapBuffers ( );