Você está na página 1de 20

CSC 307 1.

Graphics Programming

Budditha Hettige Department of Statistics and Computer Science

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

Viewing and Modeling Transformations


Rotating First or Translating First

Budditha Hettige

Viewpoint
Object and Viewpoint at the Origin

Budditha Hettige

Viewpoint and the Object


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

Budditha Hettige

Using the gluLookAt()


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

Budditha Hettige

Default Camera Position


gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);

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

The Transformed Depth Coordinate


void glDepthRange(GLclampd near, GLclampd far);

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

Building a Solar System


planet example (planet.cpp)

Budditha Hettige

19

Building an Articulated Robot Arm


robotArm.cpp

Budditha Hettige

20

Você também pode gostar