Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC Graphics Programming

Similar presentations


Presentation on theme: "CSC Graphics Programming"— Presentation transcript:

1 CSC 307 1.0 Graphics Programming
Budditha Hettige Department of Statistics and Computer Science

2 Graphics Programming Viewing
07 Graphics Programming Viewing

3 Translate void glTranslate{fd}(TYPE x, TYPE y, TYPE z);

4 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

5 Scale void glScale{fd}(TYPE x, TYPE y, TYPE z); Example: glScalef(2.0, –0.5, 1.0)

6 Viewing and Modeling Transformations
Rotating First or Translating First

7 Viewpoint Object and Viewpoint at the Origin

8 Viewpoint and the Object
Separating the Viewpoint and the Object glTranslatef(0.0, 0.0, -5.0);

9 Using the gluLookAt() void gluLookAt (
GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz );

10 Default Camera Position
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, , 0.0, 1.0, 0.0);

11 Using gluLookAt() gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0);

12 Projection Transformations
Perspective Projection void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

13 Orthographic Projection
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

14 Viewport Transformation
Defining the Viewport void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

15 The Transformed Depth Coordinate
void glDepthRange(GLclampd near, GLclampd far);

16 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);

17 Example # include <windows.h> #include <GL/glut.h>
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); # include <windows.h> #include <GL/glut.h> #include <stdlib.h> static GLfloat spin = 0.0; void spinDisplay(void) { spin = spin ; if (spin > 360.0) spin = spin ; glutPostRedisplay(); }

18 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; }

19 Building a Solar System
planet example (planet.cpp)

20 Building an Articulated Robot Arm
robotArm.cpp


Download ppt "CSC Graphics Programming"

Similar presentations


Ads by Google