Escolar Documentos
Profissional Documentos
Cultura Documentos
Graphics Programming
Graphics Programming
Viewing
Budditha Hettige
Translate
void glTranslate{fd}(TYPE x, TYPE y, TYPE z);
Budditha Hettige
Rotate
void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); glRotatef(45.0, 0.0, 0.0, 1.0) - rotation of 45 degrees about the z-axis
Budditha Hettige
Scale
void glScale{fd}(TYPE x, TYPE y, TYPE z); Example: glScalef(2.0, 0.5, 1.0)
Budditha Hettige
Budditha Hettige
Viewpoint
Object and Viewpoint at the Origin
Budditha Hettige
Budditha Hettige
Budditha Hettige
Budditha Hettige
10
Using gluLookAt()
gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0);
Budditha Hettige
11
Projection Transformations
Perspective Projection
void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
Budditha Hettige
12
Orthographic Projection
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
Budditha Hettige
13
Viewport Transformation
Defining the Viewport void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
Budditha Hettige
14
Budditha Hettige
15
Animation
Is an important part of computer graphics Taking a sequence of pictures and projecting them at 24 frames per second on the screen void glutSwapBuffers(void);
Budditha Hettige
16
Example
# include <windows.h> #include <GL/glut.h> #include <stdlib.h> static GLfloat spin = 0.0;
void spinDisplay(void) { spin = spin + 0.05; if (spin > 360.0) spin = spin - 360.0; glutPostRedisplay(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(spin, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glRectf(-25.0, -25.0, 25.0, 25.0); glPopMatrix(); glutSwapBuffers(); spinDisplay(); }
void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } Budditha Hettige
17
Example
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(250, 250); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }
Budditha Hettige
18
Budditha Hettige
19
Budditha Hettige
20