Download presentation
Presentation is loading. Please wait.
Published byAnnice O’Connor’ Modified over 6 years ago
1
Introduction of OpenGL - 3D Graphic and Animation
2
3D Graphic Projections – Getting 3D to 2D
3
Two Projections Orthographic Projection Perspective Projection
4
Orthographic Projections
Command glOrtho ( double left, double right, double bottom, double top, double near, double far);
5
Perspective Projection
Command gluPerspective ( double angle, double aspect, double near, double far);
6
Draw a 3D Model Object Composition Polygon 3D Model
7
Object Composition Use Transformation glPushMatrix ( );
glPopMatrix ( ); Save the current transformation state and then restore it after some objects have been placed
8
The Matrix Stack Ex. Draw a car use transformation
The car body and four wheeles Transformation state Wheele 4 The Car Body Wheele 1 Wheele 2 Wheele 3 Wheele 4
9
Hidden Surface Removal
Enable Depth Testing glEnable (GL_DEPTH_TEST); Hidden Surface
10
Light and Surface Normal
A Normal Vector V3 = V1 X V2 Normal Vector P3 V2 P1 V1 P2
11
Draw Quadrics (1) Rendering Spheres, Cylinders, and Disks
1. Declare a quadrics pointer GLUquadricObj *qobj; 2. Create a quadrics object qobj = gluNewQuadric ( );
12
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);
13
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);
14
Draw Quadrics (4) Rendering Spheres, Cylinders, and Disks
Slices and stacks Cylinder slices = 6 stacks = 6 Cylinder slices = 30 stacks = 30
15
Draw Quadrics (5) Rendering Spheres, Cylinders, and Disks
5. When you’re completely finished with drawing, destory this object gluDeleteQuadric ( );
16
Animation A Rotating Square Frame 0 Frame 1 Frame 2 Frame 3
17
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 ( );
18
Animation with OpenGL and GLUT
Rotation glRotatef( angle, 0.0, 0.0, 1.0) - rotate about the x-axis
19
Animation with OpenGL and GLUT
Rotation - delay the rotation #include <time.h> void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.