• Save
OpenGL Transformation
Upcoming SlideShare
Loading in...5
×
 

OpenGL Transformation

on

  • 2,026 views

OpenGL Transformation

OpenGL Transformation

Statistics

Views

Total Views
2,026
Views on SlideShare
1,814
Embed Views
212

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 212

http://cctech.co.in 212

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OpenGL Transformation OpenGL Transformation Presentation Transcript

  • OpenGL Transformation http://www.learncax.com/ Centre for Computational TechnologiesCCTech Recruitment Brochure Simulation is The Future!
  • Outline1. Transformation2. Viewing Transformation3. Projection Matrix4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • Geometric Objects and Operations• Primitive types: scalars, vectors, points• Primitive operations: dot product, cross product• Representations: coordinate systems, frames• Implementations: matrices, homogeneous coor.• Transformations: rotation, scaling, translation• Composition of transformations• OpenGL transformation matrices Centre for Computational Technologies OpenGL Simulation is The Future!
  • Current Transformation Matrix• Model-view matrix (usually affine)• Projection matrix (usually not affine)• Manipulated separately glMatrixMode (GL_MODELVIEW); glMatrixMode (GL_PROJECTION); Centre for Computational Technologies OpenGL Simulation is The Future!
  • Manipulating the Current Matrix• Load or postmultiply glLoadIdentity(); glLoadMatrixf(*m); glMultMatrixf(*m);• Library functions to compute matrices glTranslatef (dx, dy, dz); glRotatef (angle, vx, vy, vz); glScalef (sx, sy, sz);• Recall: last transformation is applied first! Centre for Computational Technologies OpenGL Simulation is The Future!
  • Transformation Matrices in OpenGL• Transformation matrices in OpenGl are vectors of 16 values (column-major matrices) m = {m1, m2, ..., m16} represents• In glLoadMatrixf(GLfloat *m);• Some books transpose all matrices! Centre for Computational Technologies OpenGL Simulation is The Future!
  • Camera in Modeling Coordinates• Camera position is identified with a frame• Either move and rotate the objects• Or move and rotate the camera• Initially, pointing in negative z-direction• Initially, camera at origin Centre for Computational Technologies OpenGL Simulation is The Future!
  • Moving Camera and World Frame• Move world frame relative to camera frame• glTranslatef(0.0, 0.0, -d); moves world frame Centre for Computational Technologies OpenGL Simulation is The Future!
  • Order of Viewing Transformations• Think of moving the world frame• Viewing transfn. is inverse of object transfn.• Order opposite to object transformationsglMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0, 0.0, -d); /*T*/glRotatef(-90.0, 0.0, 1.0, 0.0); /*R*/ Centre for Computational Technologies OpenGL Simulation is The Future!
  • Viewing Functions• Roll (about z), pitch (about x), yaw (about y) Centre for Computational Technologies OpenGL Simulation is The Future!
  • Outline1. Transformation2. Viewing Transformation3. Projection Matrix4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • Viewing and Projection• In OpenGL we distinguish between: – Viewing: placing the camera – Projection: describing the viewing frustum of the camera (and thereby the projection transformation) – Perspective divide: computing homogeneous points Centre for Computational Technologies OpenGL Simulation is The Future!
  • OpenGL Transformations• The viewing transformation V transforms a point from world space to eye space: Centre for Computational Technologies OpenGL Simulation is The Future!
  • Placing the Camera• It is most natural to position the camera in world space as if it were a real camera• Identify the eye point where the camera is located• Identify the look-at point that we wish to appear in the center of our view• Identify an up-vector vector that we wish to be oriented upwards in our final image Centre for Computational Technologies OpenGL Simulation is The Future!
  • Look-At Positioning• We specify the view frame using the look-at vector a and the camera up vector up• The vector a points in the negative viewing direction• In 3D, we need a third vector that is perpendicular to both up and a to specify the view frame Centre for Computational Technologies OpenGL Simulation is The Future!
  • Constructing a Frame• The cross product between the up and the look-at vector a will get a vector that points to the right.• Finally, using the vector a and the vector r we can synthesize a new vector u in the up direction: Centre for Computational Technologies OpenGL Simulation is The Future!
  • gluLookAt()• OpenGL provides a very helpful utility function that implements the look-at viewing specification: gluLookAt ( eyex, eyey, eyez, // eye point atx, aty, atz, // lookat point upx, upy, upz ); // up vector• These parameters are expressed in world coordinates Centre for Computational Technologies OpenGL Simulation is The Future!
  • Outline1. Transformation2. Viewing Transformation3. Projection Matrix4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • OpenGL Transformations• The projection transformation P transforms a point from eye space to clip space: Centre for Computational Technologies OpenGL Simulation is The Future!
  • Projection Transformations• Projections fall into two categories: – Parallel projections: Lines of projection are parallel to each other – Perspective projections: Lines of projection converge at a point Centre for Computational Technologies OpenGL Simulation is The Future!
  • Parallel Projections• The simplest form of parallel projection is simply along lines parallel to the z-axis onto the xy-plane• This form of projection is called orthographic Centre for Computational Technologies OpenGL Simulation is The Future!
  • Orthographic Frustum• The user specifies the orthographic viewing frustum by specifying minimum and maximum x/y coordinates• It is necessary to indicate a range of distances along the z- axis by specifying near and far planes Centre for Computational Technologies OpenGL Simulation is The Future!
  • Orthographic Projection in OpenGL• This matrix is constructed with the following OpenGL call: glOrtho(left, right, bottom, top, near, far);• And the 2D version (another GL utility function): gluOrtho2D(left, right, bottom, top); – Just a call to glOrtho() with near = -1 and far = +1 Centre for Computational Technologies OpenGL Simulation is The Future!
  • Properties of Parallel Projections• Not realistic looking• Good for exact measurements• A kind of affine transformation – Parallel lines remain parallel – Ratios are preserved – Angles (in general) not preserved• Most often used in CAD, architectural drawings, etc., where taking exact measurement is important Centre for Computational Technologies OpenGL Simulation is The Future!
  • Isometric Games• A special kind of parallel projection called isometric projection is often used in games• It’s essentially a shear and an orthographic projection• Easier to compute than a full perspective transformation Centre for Computational Technologies OpenGL Simulation is The Future!
  • Perspective Projections• Artists (Donatello, Brunelleschi, and Da Vinci) during the renaissance discovered the importance of perspective for making images appear realistic• Parallel lines intersect at a point Centre for Computational Technologies OpenGL Simulation is The Future!
  • Perspective Viewing Frustum• Just as in the orthographic case, we specify a perspective viewing frustum• Values for left, right, top, and bottom are specified at the near depth Centre for Computational Technologies OpenGL Simulation is The Future!
  • Perspective Viewing Frustum• OpenGL provides a function to set up this perspective transformation: glFrustum(left, right, bottom, top, near, far);• There is also a simpler OpenGL utility function: gluPerspective(fov, aspect, near, far); – fov = vertical field of view in degrees – aspect = image width / height at near depth• Can only specify symmetric viewing frustums where the viewing window is centered around the –z axis. Centre for Computational Technologies OpenGL Simulation is The Future!
  • gluPerspective()• Here are the parameters of gluPerspective() Centre for Computational Technologies OpenGL Simulation is The Future!
  • Properties of Perspective Projections• The perspective projection is an example of a projective transformation• Here are some properties of projective transformations: – Lines map to lines – Parallel lines do not necessarily remain parallel – Ratios are not preserved• One of the advantages of perspective projection is that size varies inversely with distance – looks realistic• A disadvantage is that we cant judge distances as exactly as we can with parallel projections Centre for Computational Technologies OpenGL Simulation is The Future!
  • Outline1. Transformation2. Viewing Transformation3. Projection Matrix4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • OpenGL Transformations• The rest of the OpenGL transformation pipeline: Centre for Computational Technologies OpenGL Simulation is The Future!
  • Clipping & Perspective Division• The scenes objects are clipped against the clip space bounding box• This step eliminates any objects (and pieces of objects) that are not visible in the image• Hill describes an efficient clipping algorithm for homogeneous clip space• Perspective division divides all homogeneous coordinates through w• Clip space becomes Normalized Device Coordinate (NDC) space after the perspective division Centre for Computational Technologies OpenGL Simulation is The Future!
  • Viewport Transformation• OpenGL provides a function to set up the viewport transformation: glViewport(x, y, width, height); Centre for Computational Technologies OpenGL Simulation is The Future!
  • Screen Coordinate Systems Centre for Computational TechnologiesOpenGL Simulation is The Future!
  • 3D Graphics Pipeline• The rasterization step scan converts the object into pixels Centre for Computational Technologies OpenGL Simulation is The Future!
  • 3D Graphics Pipeline• A z-buffer depth test resolves visibility of the objects on a per-pixel basis and writes the pixels to the frame buffer Centre for Computational Technologies OpenGL Simulation is The Future!
  • Thank You Mail Us @ sandip@cctech.co.in Visit Us @ www.cctech.co.in @ www.learncax.com Call Us @ +91 20 4009 8381/82 Centre for Computational Technologies Pvt. Ltd. 1, Akshay Residancy, 50 Anand Park, Aundh, Pune -7 Centre for Computational TechnologiesOpenGL Simulation is The Future!