SlideShare a Scribd company logo
1 of 38
OpenGL Transformation




                         http://www.learncax.com/



                                        Centre for Computational Technologies
CCTech Recruitment Brochure                             Simulation is The Future!
Outline
1.   Transformation
2.   Viewing Transformation
3.   Projection Matrix
4.   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 transformations

glMatrixMode(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!
Outline
1.   Transformation
2.   Viewing Transformation
3.   Projection Matrix
4.   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!
Outline
1.   Transformation
2.   Viewing Transformation
3.   Projection Matrix
4.   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 can't judge distances as exactly
  as we can with parallel projections



                                          Centre for Computational Technologies
    OpenGL                                                Simulation is The Future!
Outline
1.   Transformation
2.   Viewing Transformation
3.   Projection Matrix
4.   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 scene's 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 Technologies
OpenGL                       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 Technologies
OpenGL                                                Simulation is The Future!

More Related Content

What's hot

OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
Girish Ghate
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
simpleok
 

What's hot (20)

OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Open gl
Open glOpen gl
Open gl
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 Introduction
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
Open gl
Open glOpen gl
Open gl
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
Bai 1
Bai 1Bai 1
Bai 1
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
 
Cross Platform Qt
Cross Platform QtCross Platform Qt
Cross Platform Qt
 
Animation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsAnimation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIs
 

Viewers also liked

2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates
Tarun Gehlot
 

Viewers also liked (7)

Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
 
Homogeneous coordinate
Homogeneous coordinateHomogeneous coordinate
Homogeneous coordinate
 
3D transformation
3D transformation3D transformation
3D transformation
 
Secrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologySecrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics Technology
 
2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates
 
2d/3D transformations in computer graphics(Computer graphics Tutorials)
2d/3D transformations in computer graphics(Computer graphics Tutorials)2d/3D transformations in computer graphics(Computer graphics Tutorials)
2d/3D transformations in computer graphics(Computer graphics Tutorials)
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
 

Similar to OpenGL Transformation

Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
Droidcon Berlin
 

Similar to OpenGL Transformation (20)

GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Computer Viewing
Computer ViewingComputer Viewing
Computer Viewing
 
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
 
Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With Unity
 
Realizing OpenGL
Realizing OpenGLRealizing OpenGL
Realizing OpenGL
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
 
Introduction to OpenGL.ppt
Introduction to OpenGL.pptIntroduction to OpenGL.ppt
Introduction to OpenGL.ppt
 
CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6
 
UML for Aspect Oriented Design
UML for Aspect Oriented DesignUML for Aspect Oriented Design
UML for Aspect Oriented Design
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Chapter-3.pdf
 
Python image processing_Python image processing.pptx
Python image processing_Python image processing.pptxPython image processing_Python image processing.pptx
Python image processing_Python image processing.pptx
 
UNIT-III
UNIT-IIIUNIT-III
UNIT-III
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
2D graphics
2D graphics2D graphics
2D graphics
 
OpenGL Transformations
OpenGL TransformationsOpenGL Transformations
OpenGL Transformations
 
Clipping
ClippingClipping
Clipping
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

OpenGL Transformation

  • 1. OpenGL Transformation http://www.learncax.com/ Centre for Computational Technologies CCTech Recruitment Brochure Simulation is The Future!
  • 2. Outline 1. Transformation 2. Viewing Transformation 3. Projection Matrix 4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • 3. 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!
  • 4. 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!
  • 5. 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!
  • 6. 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!
  • 7. 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!
  • 8. 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!
  • 9. Order of Viewing Transformations • Think of moving the world frame • Viewing transfn. is inverse of object transfn. • Order opposite to object transformations glMatrixMode(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!
  • 10. Viewing Functions • Roll (about z), pitch (about x), yaw (about y) Centre for Computational Technologies OpenGL Simulation is The Future!
  • 11. Outline 1. Transformation 2. Viewing Transformation 3. Projection Matrix 4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • 12. 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!
  • 13. OpenGL Transformations • The viewing transformation V transforms a point from world space to eye space: Centre for Computational Technologies OpenGL Simulation is The Future!
  • 14. 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!
  • 15. 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!
  • 16. 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!
  • 17. 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!
  • 18. Outline 1. Transformation 2. Viewing Transformation 3. Projection Matrix 4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • 19. OpenGL Transformations • The projection transformation P transforms a point from eye space to clip space: Centre for Computational Technologies OpenGL Simulation is The Future!
  • 20. 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!
  • 21. 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!
  • 22. 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!
  • 23. 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!
  • 24. 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!
  • 25. 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!
  • 26. 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!
  • 27. 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!
  • 28. 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!
  • 29. gluPerspective() • Here are the parameters of gluPerspective() Centre for Computational Technologies OpenGL Simulation is The Future!
  • 30. 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 can't judge distances as exactly as we can with parallel projections Centre for Computational Technologies OpenGL Simulation is The Future!
  • 31. Outline 1. Transformation 2. Viewing Transformation 3. Projection Matrix 4. OpenGL Transformation Pipeline Centre for Computational Technologies OpenGL Simulation is The Future!
  • 32. OpenGL Transformations • The rest of the OpenGL transformation pipeline: Centre for Computational Technologies OpenGL Simulation is The Future!
  • 33. Clipping & Perspective Division • The scene's 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!
  • 34. 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!
  • 35. Screen Coordinate Systems Centre for Computational Technologies OpenGL Simulation is The Future!
  • 36. 3D Graphics Pipeline • The rasterization step scan converts the object into pixels Centre for Computational Technologies OpenGL Simulation is The Future!
  • 37. 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!
  • 38. 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 Technologies OpenGL Simulation is The Future!