CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 3: Viewing Jim Mims, Spring 2009.
Advertisements

The View Frustum and the Camera Lecture 19 Fri, Oct 10, 2003.
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.
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.
Development of Interactive 3D Virtual World Applications
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
Introduction to 3D viewing 3D is just like taking a photograph!
2002 by Jim X. Chen: 2D viewing –Window –Viewport 3D viewing –Projection methods and viewing volumes –Normalization –Clipping.
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.
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 The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
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.
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
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.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
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
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Advanced Graphics Algorithms Ying Zhu Georgia State University
Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin
Reference1. [OpenGL course slides by Rasmus Stenholt]
Projection v VP u VPN n.
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
Computer Graphics, KKU. Lecture 13
Type of View Perspective View COP(Center of Plane) Diminution of size
Advanced Graphics Algorithms Ying Zhu Georgia State University
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Projection v VP u VPN n.
HW-swgl-1 transformation & projection
Presentation transcript:

CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation

CGGM Lab. Tan-Chi Ho 2001 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).

CGGM Lab. Tan-Chi Ho 2001 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).

CGGM Lab. Tan-Chi Ho 2001 Overview Modelview Matrix Modelview Matrix View Transformation View Transformation Modelview Matrix Modelview Matrix Perspective Division eye coordinates clip coordinates normalized device coordinates window coordinates XYZWXYZW Object coordinates Vertex

CGGM Lab. Tan-Chi Ho 2001 Transformations 1/12 The Viewing Transformation To positioning and aiming the camera. Use gluLookAt() to indicate where the camera is placed and aimed. If gluLookAt() was not called, the camera has a default position at the origin, points down the negative Z-axis, and an up- vector of (0, 1, 0).

CGGM Lab. Tan-Chi Ho 2001 Transformations 2/12 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 look at. Upx, upy, upz is the up-vector of the camera.

CGGM Lab. Tan-Chi Ho 2001 Transformations 3/12 The Modeling Transformation To position and orient the models. Rotate, translate, scale and some combination of these operations. In OpenGL, modeling and viewing transformation are combined into the modelview matrix before the transformation are applied.

CGGM Lab. Tan-Chi Ho 2001 Transformations 4/12 glTranslate{fd}(TYPE x,TYPE y,TYPE z); Multiplies current matrix by a matrix that moves an object by x,y,z 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.

CGGM Lab. Tan-Chi Ho 2001 Transformations 5/12 glScale{fd}(TYPE x,TYPE y,TYPE z); Multiplies current matrix by a matrix that scales an object along axes.

CGGM Lab. Tan-Chi Ho 2001 Transformations 6/12 The Projection Transformation Determine what the field of view(or viewing volume) is and how objects are projected onto the screen. Two types of projections are provided: Perspective projection Orthographic projection

CGGM Lab. Tan-Chi Ho 2001 Transformations 7/12 Perspective Projection glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

CGGM Lab. Tan-Chi Ho 2001 Transformations 8/12 gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far);

CGGM Lab. Tan-Chi Ho 2001 Transformations 9/12 Orthographic Projection glOrtho(Gldouble left, Gldouble right, Gldouble bottom, Gldouble top, Gldouble near, Gldouble far); gluOrtho2D(Gldouble left, Gldouble right, Gldouble bottom, Gldouble top); For 2D projection matrix The Z coordinates for objects are assumed to lie between – 1.0 and 1.0.

CGGM Lab. Tan-Chi Ho 2001 Transformations 10/12

CGGM Lab. Tan-Chi Ho 2001 Transformations 11/12 The Viewport Transformation Transform the final image into some region of the window. The viewport is measured in window coordinates. glViewport(GLint x, GLint y, GLsizei width, GLsizei height); Initial values are (0, 0, winWidth, winHeight).

CGGM Lab. Tan-Chi Ho 2001 Transformations 12/12 Switch between matrix modes glMatrixMode(GLenum mode); Switch between modelview, projection, tecture matrix mode.(GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE) Current matrix mode is a state variable. glLoadIdentity(); Set current matrix to the 4x4 identity matrix. Always call this after change matrix mode.

CGGM Lab. Tan-Chi Ho 2001 The Matrix Manipulation glLoadIdentity(); glLoadMatrix{f,d}( const TYPE* m ); glMultMatrix{f,d}( const TYPE* m ); glPushMatrix(); glPopMatrix(); Stack operation of matrix is very useful for constructing a hierarchical structures. Ex: a car with four wheels.

CGGM Lab. Tan-Chi Ho 2001 Transformation Program 1/5 #include static GLfloat year=0.0f, day=0.0f; void init() { glClearColor(0.0, 0.0, 0.0, 0.0); } void GL_display() { // clear the buffer glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glutWireSphere(1.0, 20, 16);// the Sun glRotatef(year, 0.0, 1.0, 0.0);

CGGM Lab. Tan-Chi Ho 2001 Transformation Program 2/5 glTranslatef(3.0, 0.0, 0.0); glRotatef(day, 0.0, 1.0, 0.0); glutWireSphere(0.5, 10, 8);// the Planet glPopMatrix(); // swap the front and back buffers glutSwapBuffers(); } void GL_reshape(GLsizei w, GLsizei h) { // viewport transformation glViewport(0, 0, w, h); // projection transformation glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 20.0);

CGGM Lab. Tan-Chi Ho 2001 Transformation Program 3/5 // 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 } // GLUT idle function void GL_idle() { day += 10.0; if(day > 360.0) day -= 360.0; year += 1.0; if(year > 360.0) year -= 360.0; // recall GL_display() function glutPostRedisplay(); }

CGGM Lab. Tan-Chi Ho 2001 Transformation Program 4/5 // GLUT keyboard function void GL_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 glutIdleFunc(GL_idle); break; case 'A':glutIdleFunc(NULL); break; case 27:exit(0); }

CGGM Lab. Tan-Chi Ho 2001 Transformation Program 5/5 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("Planet"); init(); glutDisplayFunc(GL_display); glutReshapeFunc(GL_reshape); glutKeyboardFunc(GL_keyboard); glutMainLoop(); }

CGGM Lab. Tan-Chi Ho 2001 Any Question? ?