Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

OpenGL Course Notes Chapter 3: Viewing Jim Mims, Spring 2009.
Hwk1- A Tutorial of OPENGL ver2.0. We will introduce… Draw a window by OpenGL Draw one/many polygons by OpenGL Rotate/Translate Matrix Push/PopMatrix.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
Based on slides created by Edward Angel
Viewing and Transformation
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL and Projections
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
GRAFIKA KOMPUTER ~ M. Ali Fauzi. Drawing 2 D Graphics.
Geometric transformations The Pipeline
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
Modeling with OpenGL Practice with OpenGL transformations.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall 2010 OpenGL Transformations.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
CSC Graphics Programming
Advanced Graphics Algorithms Ying Zhu Georgia State University
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lecture 08 and 09 View & Projection
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics, KKU. Lecture 13
Type of View Perspective View COP(Center of Plane) Diminution of size
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Presentation transcript:

Viewing and Transformation

Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending Per Fragment operations Buffer operations Rasterizer setup Framebuffer We are here!

OpenGL program 1/7 #include "glut.h" #include static GLfloat year=0.0f, day=0.0f; int time1,time2; int width, height; void display(); void reshape(GLsizei, GLsizei ); void idle(); void keyboard(unsigned char, int, int);

OpenGL program 2/7 void display() { // clear the buffer glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

OpenGL program 3/7 // viewing and modeling transformation glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 3.0, 5.0, // eye 0.0, 0.0, 0.0, // center 0.0, 1.0, 0.0); // up // projection transformation glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (float)width/height, 1.0, 20.0); // viewport transformation glViewport(0, 0, width, height);

OpenGL program 4/7 glMatrixMode(GL_MODELVIEW); glColor3f(1.0, 1.0, 1.0); glutWireSphere(1.0, 20, 16);// the Sun glPushMatrix(); glRotatef(year, 0.0, 1.0, 0.0); glTranslatef(3.0, 0.0, 0.0); glRotatef(day, 0.0, 1.0, 0.0); glutWireSphere(0.5, 10, 8); glPopMatrix();

OpenGL program 5/7 glPushMatrix(); glRotatef(year*2.0, 0.0, 1.0, 0.0); glTranslatef(1.5, 0.0, 0.0); glRotatef(day*2.0, 0.0, 1.0, 0.0); glutWireSphere(0.2, 10, 8); // the Planet 2 glPopMatrix(); // swap the front and back buffers glutSwapBuffers(); } void reshape(GLsizei w, GLsizei h) { width = w; height = h; }

OpenGL program 6/7 // GLUT idle function void idle() { time2 = clock(); day += 100.0*(time2-time1)/CLK_TCK; if(day > 360.0) day -= 360.0; year += 10.0*(time2-time1)/CLK_TCK; if(year > 360.0) year -= 360.0; time1 = time2; // recall GL_display() function glutPostRedisplay(); }

OpenGL program 7/7 void keyboard(unsigned char key, int x, int y) { switch(key) { case 'd': day += 10.0; if(day > 360.0) day -= 360.0; glutPostRedisplay(); break; case 'y': year += 1.0; if(year > 360.0) year -= 360.0; glutPostRedisplay(); break; case 'a': // assign idle function time1 = clock(); glutIdleFunc(idle); break; case 'A': glutIdleFunc(NULL); break; case 27: exit(0); }

OpenGL program 6/7 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("Planet"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }

OpenGL program

The camera analogy 1/2 Set up tripod and pointing the camera at the scene (viewing transformation) Arrange the scene to be photographed into the desired composition (modeling transformation)

The camera analogy 2/2 Choose a camera lens or adjust the zoom (projection transformation). Determine how large you want the final photograph to be (viewport transformation).

Overview Modelview Matrix Modelview Matrix Viewport Transformation Viewport Transformation Projection Matrix Projection Matrix Perspective Division eye coordinates clip coordinates normalized device coordinates window coordinates XYZWXYZW Object coordinates Vertex TODO: 1. Switch matrix mode to GL_MODELVIEW and call glLoadIdentity(). 2. Call gluLookAt(). 3. Your own modeling transformations. TODO: 1. Switch matrix mode to GL_PROJECTION and call glLoadIdentity(). 2. Call gluPerspective() if you want perspective projection. 3. Call gluOrtho2D() if you want orthogonal projection. TODO: 1. Call glViewport(). XYXY

Matrix in OpenGL Consider a transformation (T 1 T 2 … T n ). To build the transformation matrix, we shall multiply identity matrix by T 1 then T 2 … until T n, The order of issuing commands shall be inversed. Ex: rotate then translate glTranslatef(1,0,0); glRotatef(45.0, 0, 0, 1);

Viewing transformations 1/2 gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdoubpe upz ); eyex, eyey, eyez is where the camera is positioned. centerx, centery, centerz is where the camera looks at. Upx, upy, upz is the up-vector of the camera.

Viewing transformations 2/2 Use gluLookAt() to indicate where the camera is placed and aimed. If not called, the camera has a default position at the origin, points down the negative Z-axis, and an up-vector of positive Y-axis.

Modeling transformation 1/4 Perform rotate, translate, scale and combinations of these transformations In OpenGL, modeling and viewing transformation are combined into the modelview matrix before the transformation are applied.

Modeling transformation 2/4 glTranslate{fd}( TYPE x,TYPE y,TYPE z ); Multiplies current matrix by a matrix that moves an object by x,y,z glTranslatef( 0, 0, -1 );

Modeling transformation 3/4 glRotate{fd}( TYPR angle,TYPE x,TYPR y,TYPE z ); Multiplies current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from origin to (x,y,z) with angle as the degrees. glRotatef( 45.0, 0, 0, 1);

Modeling transformation 4/4 glScale{fd}( TYPE x,TYPE y,TYPE z ); Multiplies current matrix by a matrix that scales an object along axes. glScalef( 2.0, -0.5, 1.0 );

Projection transformation 1/5 Determine what the field of view (or viewing volume) is and how objects are projected onto the screen.

Projection transformation 2/5 Perspective Projection glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );

Projection transformation 3/5 gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far );

Projection transformation 4/5 Orthographic projection glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );

Projection transformation 5/5 gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top); Equal to calling glOrtho with near = 1 and far = 1.

Viewport transformations void glViewport( GLint x, GLint y, GLsizei width, GLsizei height ); Transform the final image into some region of the window x, y :The lower-left corner of the viewport rectangle, in pixels. The default is (0,0). width, height :The width and height of the viewport. The default is set to the dimensions of that window

Matrix Manipulation 1/4 void glMatrixMode( GLenum mode ); Switch between three modes GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE Each matrix mode has its own matrix stack. void glLoadIdentity(); Set current matrix to the 4x4 identity matrix

Matrix Manipulation 2/4 glLoadMatrix{f,d}( const TYPE* m ); Replaces current matrix by a user defined matrix The user defined matrix m is a 4x4 array

Matrix Manipulation 3/4 glMultMatrix{f,d}( const TYPE* m ); Multiplies current matrix by a user defined matrix The user defined matrix m is a 4x4 array.

Matrix Manipulation 4/4 void glPushMatrix(); Push current matrix into matrix stack. Void glPopMatrix(); Pop matrix from matrix stack These stack operations of matrix is very useful for constructing a hierarchical structure.