Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Computer Graphics 2D & 3D Transformation.
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
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?
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.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Chapter 4 10 February Agenda Program 2 – Due 2/17 Chapter 4 – transformations GLUT solids.
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.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
Computer Graphics I, Fall 2010 Computer Viewing.
Modeling with OpenGL Practice with OpenGL transformations.
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.
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.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
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.
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
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Chap 3 Viewing and Transformation
Honours Graphics 2008 Session 3. Today’s focus Perspective and orthogonal projection Quaternions Graphics camera.
CS 4731: Computer Graphics Lecture 12: More 3D Viewing Emmanuel Agu.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
GL transformations-models. x' = x+t x y' = y+t y z' = z+t z t x t y s x =s y =s z t z uniform nonuniform?!!?? x' = x·s x y' =
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.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
OpenGL LAB III.
Computer Graphics Lecture 42 Viewing Using OpenGL II Taqdees A. Siddiqi
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Reference1. [OpenGL course slides by Rasmus Stenholt]
VIEWING 2D viewing Window Viewport
CSC461: Lecture 19 Computer Viewing
Computer Graphics, KKU. Lecture 13
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Objects and Transformations (II)
University of New Mexico
Chapter 3 Viewing.
Presentation transcript:

Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied by the coordinates of each vertex v in the scene to accomplish the transformation v'=Mv Remember that vertices always have four coordinates (x,y, z, w), though in most cases w is 1 and for two-dimensional data z is 0. The viewing and modeling transformations you specify are combined to form the modelview matrix, which is applied to the incoming object coordinates to yield eye coordinates.

Eye Coordinates (a) The eye coordinates are represented as seen by the observer of the scene (that is, perpendicular to the monitor). (b) The eye coordinate system is rotated slightly so you can better see the relation of the z-axis. When you draw in 3D with OpenGL, you use the Cartesian coordinate system. In the absence of any transformations, the system in use is identical to the eye coordinate system.

The Viewing Transformation The viewing transformation allows you to place the point of observation anywhere you want and look in any direction. Determining the viewing transformation is like placing and pointing a camera at the scene. The current matrix is set to the identity matrix with glLoadIdentity().

By default, the camera as well as any objects in the scene are originally situated at the origin; also, the camera initially points down the negative z-axis. If the camera needed to be pointed in another direction, you could have used the glRotatef() command to change its orientation.

Modeling Transformation Modeling transformations move objects into place, rotate them, and scale them. Rotating and translating are performed using the commands already mentioned - glRotatef() and glTranslatef(). Note that instead of pulling the camera back away from the cube (with a viewing transformation) so that it could be viewed, you could have moved the cube away from the camera (with a modeling transformation).

The order of transformations is critical

Each successive glMultMatrix*() or transformation command multiplies a new 4 × 4 matrix M by the current modelview matrix C to yield CM. Vertices v are multiplied by the current modelview matrix: CMv. Example glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(N); /* apply transformation N */ glMultMatrixf(M); /* apply transformation M */ glMultMatrixf(L); /* apply transformation L */ glBegin(GL_POINTS); glVertex3f(v); /* draw transformed vertex v */ glEnd(); The transformed vertex is NMLv

glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(T); /* translation */ glMultMatrixf(R); /* rotation */ draw_the_object(); The three OpenGL routines for modeling transformations are glTranslate*(), glRotate*(), and glScale*(). All three commands are equivalent to producing an appropriate translation, rotation, or scaling matrix, and then calling glMultMatrix*() with that matrix as the argument. void glTranslate{fd}(TYPEx, TYPE y, TYPEz); x y z

// Translate up the y-axis 10 units glTranslatef(0.0f, 10.0f, 0.0f); // Draw the cube glutWireCube(10.0f);

void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); x^2(1−c)+c xy(1−c)−zs xz(1−c)+ys 0 yx(1−c)+zs y^2(1−c)+c yz(1−c)−xs 0 xz(1−c)−ys yz(1−c)+xs z^2(1−c)+c Where c=cos(angle), s=sin(angle), and ||(xyz)||=1 (if not, the GL will normalize this vector).

// Perform the transformation glRotatef(45.0f, 1.0f, 1.0f, 1.0f); // Draw the cube glutWireCube(10.0f);

void glScale{fd} (GLdouble x, GLdouble y, GLdouble z ); x y z

The effect of glRotatef(45.0, 0.0, 0.0, 1.0), which is a rotation of 45 degrees about the z- axis. the effect of glScalef(2.0, -0.5, 1.0). –Scaling with a -1.0 value reflects an object across an axis.

OpenGL represents a 4×4 matrix not as a two-dimensional array of floating-point values, but as a single array of 16 floating-point values. GLfloat matrix[16]; // Nice OpenGL friendly matrix GLfloat matrix[4][4]; // Popular, but not as efficient for OpenGL The first three elements of the first three columns are just directional vectors that represent the orientation (vectors here are used to represent a direction) of the x-, y-, and z-axes in space. For most purposes, these three vectors are always at 90° angles from each other, and are usually each of unit length (unless you are also applying a scale or shear). –The mathematical term for this is orthonormal when the vectors are unit length, and –orthogonal when they are not.

// Load an identity matrix GLfloat m[] = { 1.0f, 0.0f, 0.0f, 0.0f, // X Column 0.0f, 1.0f, 0.0f, 0.0f, // Y Column 0.0f, 0.0f, 1.0f, 0.0f, // Z Column 0.0f, 0.0f, 0.0f, 1.0f }; // Translation glMatrixMode(GL_MODELVIEW); glLoadMatrixf(m); Although OpenGL implementations use column-major ordering, OpenGL (versions 1.2 and later) does provide functions to load a matrix in row-major ordering. The following two functions perform the transpose operation on the matrix when loading it on the matrix stack: void glLoadTransposeMatrixf(Glfloat* m); and void glLoadTransposeMatrixd(Gldouble* m);

Cube2.cpp void displayCallbackProc (void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -10.0); glRotatef(x_Angle, 1.0, 0.0, 0.0); glRotatef(y_Angle, 0.0, 1.0, 0.0); glRotatef(z_Angle, 0.0, 0.0, 1.0); drawCube(); glutSwapBuffers(); }

Duality of Modeling and Viewing Transformation Translating an object by (0,0,-5) has the same effect as translating camera by (0,0,5). Viewing trans + Modeling trans => model- view transformation

gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); –eyeX, eyeY, eyeZ Specifies the position of the eye point. –centerX, centerY, centerZ Specifies the position of the reference point. –upX, upY, upZ Specifies the direction of the up vector.

cube3.cpp glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if(bGlulookat){ glTranslatef(0, 0, -10.0); // Translate the object by 10 units in -ve z-direction. printf("\n Using glTranslate()."); } else { gluLookAt(0, 0, 10, 0, 0, -1, 0, 1, 0); // Specify the same camera position //and orientation as above using gluLookAt() printf("\n Using gluLookAt()."); }

pilotView.c Suppose you're writing a flight simulator and you'd like to display the world from the point of view of the pilot of a plane. The world is described in a coordinate system with the origin on the runway and the plane at coordinates (x, y, z). Suppose further that the plane has some roll, pitch, and heading (these are rotation angles of the plane relative to its center of gravity).

void pilotView(GLdouble planex, GLdouble planey, GLdouble planez, GLdouble roll, GLdouble pitch, GLdouble yaw) // Used to capture transformations for the pilot view camera. { glRotated(roll, 0.0, 0.0, 1.0); glRotated(pitch, 0.0, 1.0, 0.0); glRotated(yaw, 1.0, 0.0, 0.0); glTranslated(-planex, -planey, -planez); }