SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
CS 543 - Computer Graphics:
              Projection


                                         by
                             Robert W. Lindeman
                               gogo@wpi.edu
                          (with help from Emmanuel Agu ;-)




3D Viewing and View Volume
 Recall: 3D viewing set up




R.W. Lindeman - WPI Dept. of Computer Science                2




                                                                 1
Projection Transformation
 View volume can have different shapes
   Parallel, perspective, isometric

 Different types of projection
   Parallel (orthographic), perspective, etc.

 Important to control
    Projection type: perspective or orthographic,
     etc.
    Field of view and image aspect ratio
    Near and far clipping planes


R.W. Lindeman - WPI Dept. of Computer Science                           3




Perspective Projection
 Similar to real world
 Characterized by object foreshortening
   Objects appear larger if they are closer to
    camera
                                                camera
 Need to define
   Center of projection (COP)
   Projection (view) plane
                                                     projection plane
 Projection
    Connecting the object to the center of
     projection

R.W. Lindeman - WPI Dept. of Computer Science                           4




                                                                            2
Why is it Called Projection?




                                         View plane


R.W. Lindeman - WPI Dept. of Computer Science         5




Orthographic (Parallel) Projection
 No foreshortening effect
   Distance from camera does not matter

 The center of projection is at infinity
 Projection calculation
    Just choose equal z coordinates




R.W. Lindeman - WPI Dept. of Computer Science         6




                                                          3
Field of View
 Determine how much of the world is
  taken into the picture
 Larger field of view = smaller object-
  projection size
                                          center of projection
                          field of view
                          (view angle)
            y                                   y

       z                   θ          z

                                                    x

R.W. Lindeman - WPI Dept. of Computer Science                         7




Near and Far Clipping Planes
 Only objects between near and far planes
  are drawn
 Near plane + far plane + field of view =
  View Frustum

                     Near plane                           Far plane
                      y

                z

                           x


R.W. Lindeman - WPI Dept. of Computer Science                         8




                                                                          4
View Frustum
 3D counterpart of 2D-world clip window
 Objects outside the frustum are clipped


                     Near plane                      Far plane
                      y

                z

                           x

                                                View Frustum


R.W. Lindeman - WPI Dept. of Computer Science                    9




Projection Transformation
 In OpenGL
    Set the matrix mode to GL_PROJECTION
    For perspective projection, use
        gluPerspective( fovy, aspect, near, far );
           or
        glFrustum( left, right, bottom, top,
                   near, far );
     For orthographic projection, use
       glOrtho( left, right, bottom, top,
                  near, far );

R.W. Lindeman - WPI Dept. of Computer Science                    10




                                                                      5
gluPerspective( fovy, aspect, near, far )

Aspect ratio is used to calculate
   the window width

          y               fovy                   y               w
      z               θ
                                         z
                                                                     h
                                              eye
                                                       x
              Aspect = w / h                                 near        far




R.W. Lindeman - WPI Dept. of Computer Science                                  11




glFrustum(                       left, right, bottom, top,
                                 near, far )

Can use this function in place of
   gluPerspective( )
                              left     top

                          y

                  z

                                 x
                                               right
                                     bottom

                                        near               far


R.W. Lindeman - WPI Dept. of Computer Science                                  12




                                                                                    6
glOrtho( left, right, bottom, top,
         near, far )

For orthographic projection
                                      top
                    left
                      y

                z


                           x

                                 bottom                right

                                                near
                                                               far


R.W. Lindeman - WPI Dept. of Computer Science                        13




Example: Projection
Transformation
void display( ) {
  glClear( GL_COLOR_BUFFER_BIT );
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity( );
  gluPerspective( FovY, Aspect, Near, Far );
  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity( );
  gluLookAt( 0, 0, 1, 0, 0, 0, 0, 1, 0 );
  myDisplay( );    // your display routine
}


R.W. Lindeman - WPI Dept. of Computer Science                        14




                                                                          7
Projection Transformation
 Projection
    Map the object from 3D space to 2D screen



          y                                         y

    z                                           z

              x                                           x

   Perspective: gluPerspective( )                             Parallel: glOrtho( )



R.W. Lindeman - WPI Dept. of Computer Science                                       15




Parallel Projection (The Math)
 After transforming the object to eye space,
   parallel projection is relatively easy: we could
   just set all Z to the same value
     Xp = x                                            (Xp, Yp)
     Yp = y
     Zp = -d
                                                                   y
                                                                          (x,y,z)
                                                              z
                                                                  x

 We actually want to remember Z
        – why?
R.W. Lindeman - WPI Dept. of Computer Science                                       16




                                                                                         8
Parallel Projection
   OpenGL maps (projects) everything in
      the visible volume into a canonical view
      volume (CVV)
                         (xmax, ymax, far)                      (1, 1, -1)




(xmin, ymin, near)                           (-1, -1, 1)

 glOrtho( xmin, xmax, ymin,                       Canonical View Volume
          ymax, near, far )
                                       Projection: Need to build 4x4 matrix to do
                                        mapping from actual view volume to CVV

  R.W. Lindeman - WPI Dept. of Computer Science                              17




  Parallel Projection: glOrtho
   Parallel projection can be broken down
      into two parts
        Translation, which centers view volume at
         origin
        Scaling, which reduces cuboid of arbitrary
         dimensions to canonical cube
            Dimension 2, centered at origin




  R.W. Lindeman - WPI Dept. of Computer Science                              18




                                                                                    9
Parallel Projection: glOrtho
(cont.)
 Translation sequence moves midpoint of view
   volume to coincide with origin
      e.g., midpoint of x = (xmax + xmin)/2
 Thus, translation factors are
   -(xmax+xmin)/2, -(ymax+ymin)/2, -(far+near)/2
 So, translation matrix M1:
                 #1     0     0    "(x max+ x min) /2&
                 %                                    (
                 %0     1     0    "(y max+ y min) /2(
                 %0     0     1    "(z max+ z min) /2 (
                 %                                    (
                 $0     0     0           1           '

R.W. Lindeman - WPI Dept. of Computer Science                       19


 !



Parallel Projection: glOrtho
(cont.)
 Scaling factor is ratio of cube dimension
  to Ortho view volume dimension
 Scaling factors
   2/(xmax-xmin), 2/(ymax-ymin), 2/(zmax-zmin)
 So, scaling matrix M2:
                 #      2                                       &
                 % x max" x min          0            0        0(
                 %                      2                       (
                 %      0                              0       0(
                 %                 y max" y min                 (
                 %                                     2
                        0                0                     0(
                 %                                z max" z min (
                 %                                              (
                 $      0                0             0       1'

R.W. Lindeman - WPI Dept. of Computer Science                       20


       !



                                                                         10
Parallel Projection: glOrtho()
        (cont.)
         Concatenating M1xM2, we get transform
           matrix used by glOrtho
          #      2                                      &                   #1   0   0   "(x max+ x min) /2&
          % x max" x min        0             0        0(
          %                                             (                   %                               (
                                2
                                                                            %0   1   0   "(y max+ y min) /2(
                                                                X
          %      0                             0       0(
          %                y max" y min                 (
          %                                    2                            %0   0   1   "(z max+ z min) /2 (
                 0              0                      0(                   %                               (
          %                               z max" z min (
          %
                 0              0              0
                                                        (
                                                       1'
                                                                            $0   0   0          1           '
          $



    !
                  $2 /(x max# x min)         0                 0         #(x max+ x min) /(x max# x min)'
                  &
                           0
                                                   !
                                     2 /(y max# y min)         0         #(y max+ y min) /(y max# y min))
                                                                                                         )
        M2 " M1 = &
                  &        0                 0         2 /(z max# z min) #(z max+ z min) /(z max# z min) )
                  &                                                                                      )
                  %        0                 0                 0                       1                 (


                                                                                     Refer to: Hill, 7.6.2
!
        R.W. Lindeman - WPI Dept. of Computer Science                                                     21




        Perspective Projection: Classical
         Side view
                                                                    y
                                                                z
                                                                        x
                     Projection plane
                                    y          (x,y,z)
                                                                             Based on similar triangles:
                      (x’,y’,z’)
          (0,0,0)                                                                    y    -z
                                                                                        =
                                                            z                        y’    d
                       d
                                                                                                d
                               -z                                                    y’ = y *
                                                                                                -z
            Eye (center of projection )

        R.W. Lindeman - WPI Dept. of Computer Science                                                     22




                                                                                                                11
Perspective Projection:
Classical (cont.)
 So (x*, y*), the projection of point, (x, y, z)
   onto the near plane N, is given as
                                        # Px    P &
                            ( x*, y *) = % N ,N y (
                                        $ "Pz "Pz '

     Similar triangles
 Numerical example
         !
Q: Where on the viewplane does P = (1, 0.5, -
  1.5) lie for a near plane at N = 1?

(x*, y*) = (1 x 1/1.5, 1 x 0.5/1.5) = (0.666, 0.333)
R.W. Lindeman - WPI Dept. of Computer Science                                          23




Pseudo Depth Checking
 Classical perspective projection drops z coordinates
 But we need z to find closest object (depth testing)
 Keeping actual distance of P from eye is
   cumbersome and slow
                                            distance =   (P
                                                          x
                                                              2         2
                                                                  + Py + Pz
                                                                               2
                                                                                   )
 Introduce pseudodepth: all we need is a measure
   of which objects are further if two points project to
                     !
   the same (x, y)              # P     Py aPz + b &
                                     x
                                 ( x*, y*,z *) = % N     ,N         ,           (
                                                 $ "Pz        "Pz           "Pz '
 Choose a, b so that pseudodepth varies from –1 to
   1 (canonical cube)
                       !
R.W. Lindeman - WPI Dept. of Computer Science                                          24




                                                                                            12
Pseudo Depth Checking (cont.)
 Solving:
                             aPz + b
                      z* =
                              "Pz


 For two conditions, z* = -1 when Pz = -N
      !
  and z* = 1 when Pz = -F, we can set up
  two simultaneous equations
 Solving for a and b, we get
                             "(F + N)                "2FN
                       a=                       b=
                              F "N                   F "N
R.W. Lindeman - WPI Dept. of Computer Science               25


            !                           !




Homogenous Coordinates
 Would like to express projection as 4x4 transform
  matrix
 Previously, homogeneous coordinates for the point P =
  (Px, Py, Pz) was (Px, Py, Pz, 1)
 Introduce arbitrary scaling factor, w, so that P = (wPx,
  wPy, wPz, w) (Note: w is non-zero)
 For example, the point P = (2, 4, 6) can be expressed
  as
     (2, 4, 6, 1)
     or (4, 8, 12, 2) where w=2
     or (6, 12, 18, 3) where w = 3
 So, to convert from homogeneous back to ordinary
   coordinates, divide all four terms by last component and
   discard 4th term
R.W. Lindeman - WPI Dept. of Computer Science               26




                                                                 13
Perspective Projection
 Same for x, so we have
      x’ = x * d / -z
      y’ = y * d / -z
      z’ = -d
 Put in a matrix form
                                                     #     x &
                  #1
                  %
                       0      0      0&# x & # x'&
                                      (% ( % (
                                                        ( )
                                                     % "d z (
                  %0   1      0      0( y            % #     &(
                                       % ( = % y'( ) % "d% y ((
                  %0   0      1      0(% z ( % z' (      $ z'
                  %                   (              % "d (
                  $0   0   ( 1"d)    1'% 1 ( % w (
                                       $ ' $ '       %        (
                                                     $    1   '

OpenGL assumes d = 1, i.e., the image plane is at z = -1
R.W. Lindeman - WPI Dept. of Computer Science
       !                                                                      27




Perspective Projection (cont.)
 We are not done yet!


 Need to modify the projection matrix to
   include a and b
    x’        1   0      0          0           x
                                                            y
    y’ =      0   1      0          0           y
                                                        z
    z’        0   0      a          b           z
                                                                x
    w         0   0    (1/-d)       0           1
                                                                    Z=1   z = -1
 We have already solved a and b

R.W. Lindeman - WPI Dept. of Computer Science                                 28




                                                                                   14
Perspective Projection (cont.)
 Not done yet! OpenGL also normalizes
  the x and y ranges of the view frustum
  to [-1, 1] (translate and scale)
 So, as in ortho, to arrive at final
  projection matrix
       We translate by
          –(xmax + xmin)/2 in x
          -(ymax + ymin)/2 in y
       And scale by
          2/(xmax – xmin) in x
          2/(ymax – ymin) in y

R.W. Lindeman - WPI Dept. of Computer Science                           29




Perspective Projection (cont.)
 Final projection matrix
glFrustum( xmin, xmax, ymin, ymax, N, F )
    N = near plane, F = far plane


             #     2N                           x max+ x min        &
             % x max" x min          0                           0 (
                                                x max" x min
             %                     2N           y max+ y min        (
             %      0                                            0 (
             %                 y max" y min     y max" y min        (
             %                                    "(F + N)     "2FN (
                    0                0
             %                                     F "N        F "N(
             %                                                      (
             $      0                0               "1          0 '

R.W. Lindeman - WPI Dept. of Computer Science                           30


  !



                                                                             15
Perspective Projection (cont.)
 After perspective projection, viewing
     frustum is also projected into a canonical
     view volume (like in parallel projection)

                                                                (1, 1, -1)
      y

 z

          x                                (-1, -1, 1)

                                                Canonical View Volume


R.W. Lindeman - WPI Dept. of Computer Science                                31




References
 Hill, Chapter 7




R.W. Lindeman - WPI Dept. of Computer Science                                32




                                                                                  16

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Kürzlich hochgeladen (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
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...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
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_...
 
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
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Cs543 15 projection

  • 1. CS 543 - Computer Graphics: Projection by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) 3D Viewing and View Volume  Recall: 3D viewing set up R.W. Lindeman - WPI Dept. of Computer Science 2 1
  • 2. Projection Transformation  View volume can have different shapes  Parallel, perspective, isometric  Different types of projection  Parallel (orthographic), perspective, etc.  Important to control  Projection type: perspective or orthographic, etc.  Field of view and image aspect ratio  Near and far clipping planes R.W. Lindeman - WPI Dept. of Computer Science 3 Perspective Projection  Similar to real world  Characterized by object foreshortening  Objects appear larger if they are closer to camera camera  Need to define  Center of projection (COP)  Projection (view) plane projection plane  Projection  Connecting the object to the center of projection R.W. Lindeman - WPI Dept. of Computer Science 4 2
  • 3. Why is it Called Projection? View plane R.W. Lindeman - WPI Dept. of Computer Science 5 Orthographic (Parallel) Projection  No foreshortening effect  Distance from camera does not matter  The center of projection is at infinity  Projection calculation  Just choose equal z coordinates R.W. Lindeman - WPI Dept. of Computer Science 6 3
  • 4. Field of View  Determine how much of the world is taken into the picture  Larger field of view = smaller object- projection size center of projection field of view (view angle) y y z θ z x R.W. Lindeman - WPI Dept. of Computer Science 7 Near and Far Clipping Planes  Only objects between near and far planes are drawn  Near plane + far plane + field of view = View Frustum Near plane Far plane y z x R.W. Lindeman - WPI Dept. of Computer Science 8 4
  • 5. View Frustum  3D counterpart of 2D-world clip window  Objects outside the frustum are clipped Near plane Far plane y z x View Frustum R.W. Lindeman - WPI Dept. of Computer Science 9 Projection Transformation  In OpenGL  Set the matrix mode to GL_PROJECTION  For perspective projection, use gluPerspective( fovy, aspect, near, far ); or glFrustum( left, right, bottom, top, near, far );  For orthographic projection, use glOrtho( left, right, bottom, top, near, far ); R.W. Lindeman - WPI Dept. of Computer Science 10 5
  • 6. gluPerspective( fovy, aspect, near, far ) Aspect ratio is used to calculate the window width y fovy y w z θ z h eye x Aspect = w / h near far R.W. Lindeman - WPI Dept. of Computer Science 11 glFrustum( left, right, bottom, top, near, far ) Can use this function in place of gluPerspective( ) left top y z x right bottom near far R.W. Lindeman - WPI Dept. of Computer Science 12 6
  • 7. glOrtho( left, right, bottom, top, near, far ) For orthographic projection top left y z x bottom right near far R.W. Lindeman - WPI Dept. of Computer Science 13 Example: Projection Transformation void display( ) { glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); gluPerspective( FovY, Aspect, Near, Far ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); gluLookAt( 0, 0, 1, 0, 0, 0, 0, 1, 0 ); myDisplay( ); // your display routine } R.W. Lindeman - WPI Dept. of Computer Science 14 7
  • 8. Projection Transformation  Projection  Map the object from 3D space to 2D screen y y z z x x Perspective: gluPerspective( ) Parallel: glOrtho( ) R.W. Lindeman - WPI Dept. of Computer Science 15 Parallel Projection (The Math)  After transforming the object to eye space, parallel projection is relatively easy: we could just set all Z to the same value  Xp = x (Xp, Yp)  Yp = y  Zp = -d y (x,y,z) z x  We actually want to remember Z – why? R.W. Lindeman - WPI Dept. of Computer Science 16 8
  • 9. Parallel Projection  OpenGL maps (projects) everything in the visible volume into a canonical view volume (CVV) (xmax, ymax, far) (1, 1, -1) (xmin, ymin, near) (-1, -1, 1) glOrtho( xmin, xmax, ymin, Canonical View Volume ymax, near, far ) Projection: Need to build 4x4 matrix to do mapping from actual view volume to CVV R.W. Lindeman - WPI Dept. of Computer Science 17 Parallel Projection: glOrtho  Parallel projection can be broken down into two parts  Translation, which centers view volume at origin  Scaling, which reduces cuboid of arbitrary dimensions to canonical cube  Dimension 2, centered at origin R.W. Lindeman - WPI Dept. of Computer Science 18 9
  • 10. Parallel Projection: glOrtho (cont.)  Translation sequence moves midpoint of view volume to coincide with origin  e.g., midpoint of x = (xmax + xmin)/2  Thus, translation factors are -(xmax+xmin)/2, -(ymax+ymin)/2, -(far+near)/2  So, translation matrix M1: #1 0 0 "(x max+ x min) /2& % ( %0 1 0 "(y max+ y min) /2( %0 0 1 "(z max+ z min) /2 ( % ( $0 0 0 1 ' R.W. Lindeman - WPI Dept. of Computer Science 19 ! Parallel Projection: glOrtho (cont.)  Scaling factor is ratio of cube dimension to Ortho view volume dimension  Scaling factors 2/(xmax-xmin), 2/(ymax-ymin), 2/(zmax-zmin)  So, scaling matrix M2: # 2 & % x max" x min 0 0 0( % 2 ( % 0 0 0( % y max" y min ( % 2 0 0 0( % z max" z min ( % ( $ 0 0 0 1' R.W. Lindeman - WPI Dept. of Computer Science 20 ! 10
  • 11. Parallel Projection: glOrtho() (cont.)  Concatenating M1xM2, we get transform matrix used by glOrtho # 2 & #1 0 0 "(x max+ x min) /2& % x max" x min 0 0 0( % ( % ( 2 %0 1 0 "(y max+ y min) /2( X % 0 0 0( % y max" y min ( % 2 %0 0 1 "(z max+ z min) /2 ( 0 0 0( % ( % z max" z min ( % 0 0 0 ( 1' $0 0 0 1 ' $ ! $2 /(x max# x min) 0 0 #(x max+ x min) /(x max# x min)' & 0 ! 2 /(y max# y min) 0 #(y max+ y min) /(y max# y min)) ) M2 " M1 = & & 0 0 2 /(z max# z min) #(z max+ z min) /(z max# z min) ) & ) % 0 0 0 1 ( Refer to: Hill, 7.6.2 ! R.W. Lindeman - WPI Dept. of Computer Science 21 Perspective Projection: Classical  Side view y z x Projection plane y (x,y,z) Based on similar triangles: (x’,y’,z’) (0,0,0) y -z = z y’ d d d -z y’ = y * -z Eye (center of projection ) R.W. Lindeman - WPI Dept. of Computer Science 22 11
  • 12. Perspective Projection: Classical (cont.)  So (x*, y*), the projection of point, (x, y, z) onto the near plane N, is given as # Px P & ( x*, y *) = % N ,N y ( $ "Pz "Pz '  Similar triangles  Numerical example ! Q: Where on the viewplane does P = (1, 0.5, - 1.5) lie for a near plane at N = 1? (x*, y*) = (1 x 1/1.5, 1 x 0.5/1.5) = (0.666, 0.333) R.W. Lindeman - WPI Dept. of Computer Science 23 Pseudo Depth Checking  Classical perspective projection drops z coordinates  But we need z to find closest object (depth testing)  Keeping actual distance of P from eye is cumbersome and slow distance = (P x 2 2 + Py + Pz 2 )  Introduce pseudodepth: all we need is a measure of which objects are further if two points project to ! the same (x, y) # P Py aPz + b & x ( x*, y*,z *) = % N ,N , ( $ "Pz "Pz "Pz '  Choose a, b so that pseudodepth varies from –1 to 1 (canonical cube) ! R.W. Lindeman - WPI Dept. of Computer Science 24 12
  • 13. Pseudo Depth Checking (cont.)  Solving: aPz + b z* = "Pz  For two conditions, z* = -1 when Pz = -N ! and z* = 1 when Pz = -F, we can set up two simultaneous equations  Solving for a and b, we get "(F + N) "2FN a= b= F "N F "N R.W. Lindeman - WPI Dept. of Computer Science 25 ! ! Homogenous Coordinates  Would like to express projection as 4x4 transform matrix  Previously, homogeneous coordinates for the point P = (Px, Py, Pz) was (Px, Py, Pz, 1)  Introduce arbitrary scaling factor, w, so that P = (wPx, wPy, wPz, w) (Note: w is non-zero)  For example, the point P = (2, 4, 6) can be expressed as  (2, 4, 6, 1)  or (4, 8, 12, 2) where w=2  or (6, 12, 18, 3) where w = 3  So, to convert from homogeneous back to ordinary coordinates, divide all four terms by last component and discard 4th term R.W. Lindeman - WPI Dept. of Computer Science 26 13
  • 14. Perspective Projection  Same for x, so we have x’ = x * d / -z y’ = y * d / -z z’ = -d  Put in a matrix form # x & #1 % 0 0 0&# x & # x'& (% ( % ( ( ) % "d z ( %0 1 0 0( y % # &( % ( = % y'( ) % "d% y (( %0 0 1 0(% z ( % z' ( $ z' % ( % "d ( $0 0 ( 1"d) 1'% 1 ( % w ( $ ' $ ' % ( $ 1 ' OpenGL assumes d = 1, i.e., the image plane is at z = -1 R.W. Lindeman - WPI Dept. of Computer Science ! 27 Perspective Projection (cont.)  We are not done yet!  Need to modify the projection matrix to include a and b x’ 1 0 0 0 x y y’ = 0 1 0 0 y z z’ 0 0 a b z x w 0 0 (1/-d) 0 1 Z=1 z = -1  We have already solved a and b R.W. Lindeman - WPI Dept. of Computer Science 28 14
  • 15. Perspective Projection (cont.)  Not done yet! OpenGL also normalizes the x and y ranges of the view frustum to [-1, 1] (translate and scale)  So, as in ortho, to arrive at final projection matrix  We translate by  –(xmax + xmin)/2 in x  -(ymax + ymin)/2 in y  And scale by  2/(xmax – xmin) in x  2/(ymax – ymin) in y R.W. Lindeman - WPI Dept. of Computer Science 29 Perspective Projection (cont.)  Final projection matrix glFrustum( xmin, xmax, ymin, ymax, N, F )  N = near plane, F = far plane # 2N x max+ x min & % x max" x min 0 0 ( x max" x min % 2N y max+ y min ( % 0 0 ( % y max" y min y max" y min ( % "(F + N) "2FN ( 0 0 % F "N F "N( % ( $ 0 0 "1 0 ' R.W. Lindeman - WPI Dept. of Computer Science 30 ! 15
  • 16. Perspective Projection (cont.)  After perspective projection, viewing frustum is also projected into a canonical view volume (like in parallel projection) (1, 1, -1) y z x (-1, -1, 1) Canonical View Volume R.W. Lindeman - WPI Dept. of Computer Science 31 References  Hill, Chapter 7 R.W. Lindeman - WPI Dept. of Computer Science 32 16