Docstoc

Viewing It works

Document Sample
Viewing It works Powered By Docstoc
					           Computer Graphics Viewing

                        Shmuel Wimer
             Bar Ilan Univ., School of Engineering




May 2010                                             1
             Clipping Window
   ywmax
                                           World Coordinates


                                          The clipping window is
   ywmin
                                          mapped into a viewport.

            xwmin        xwmax
                                          Viewing world has its own
                       Viewport
                                          coordinates, which may be
    yvmax
                                          a non-uniform scaling of
                                          world coordinates.

   yvmin
                                          Viewport Coordinates

            xvmin                 xvmax
May 2010                                                            2
           2D viewing transformation pipeline


              Construct World-
 Modeling                              World         Convert World-
              Coordinate Scene
Coordinates                          Coordinates     Coordinates to
               From Modeling-
                                                       Viewing-
                 Coordinate
                                                      Coordinates
               Transformations


                                   Viewing Coordinates



              Transform Viewing-     Normalized                         Device
                                     Coordinates    Map Normalized-   Coordinates
                Coordinates to
                                                     Coordinates to
                 Normalized-
                                                   Device-Coordinates
                 Coordinates


May 2010                                                                        3
Normalization and Viewport Transformations

• First approach:
    – Normalization and window-to-viewport transformations are
      combined into one operation.
    – Viewport range can be in [0,1] x [0,1].
    – Clipping takes place in [0,1] x [0,1].
    – Viewport is then mapped to display device.
• Second approach:
    – Normalization and clipping take place before viewport
      transformation.
    – Viewport coordinates are specified in screen coordinates.



May 2010                                                          4
                                            1
            Clipping Window
ywmax                                                   Normalized Viewport
                                     yvmax

               xw, yw
                                                          xv, yv 
ywmin                               yvmin

                                         0
           xwmin          xwmax                 xvmin                     xvmax1

   Maintain relative size and position between clipping window and viewport.


    xv  xvmin    xw  xwmin                 yv  yvmin    yw  ywmin
                                                        
   xvmax  xvmin xwmax  xwmin              yvmax  yvmin ywmax  ywmin


May 2010                                                                           5
  Solving for  xv, yv  obtains:

  xv  sx xw  t x , yv  s y yw  t y , where
                                     xvmax  xvmin                    yvmax  yvmin
  Scaling factors:              sx                ,             sy 
                                     xwmax  xwmin                    ywmax  ywmin
  Translation factors:
       xwmax xvmin  xwmin xvmax                       ywmax yvmin  ywmin yvmax
  tx                            ,                ty 
            xwmax  xwmin                                   ywmax  ywmin
  This can also be obtained by composing transformations:
   M window,          
      norm_viewport


                                                                     sx   0    tx 
   T  xvmin , yvmin   S  sx , s y   T   xwmin ,  ywmin    0
                                                                          sy   ty 
                                                                                   
                                                                    0
                                                                          0    1 
May 2010                                                                               6
 World clipping window can be first mapped to normalized square between -1
 and +1, where clipping algorithm takes place, and then transform the scene
 into viewport given in display coordinates.

                           2                                          xwmax  xwmin 
                       xw  xw                      0               
                                                                       xwmax  xwmin 
                       max    min
                                                                                     
                                                  2                   yw  ywmin 
                                                                    max
                                                                       ywmax  ywmin 
    M window,               0
       norm_square
                                            ywmax  ywmin                           
                           0                        0                      1        
                                                                                    
                                                                                    

                       xvmax  xvmin  2            0               xvmax  xvmin    2
                                                                                         
     M norm_square,           0             yvmax  yvmin    2    yvmax  yvmin    2
                                                                                         
       viewport
                               0                     0                       1           

May 2010                                                                                      7
                         Clipping Algorithms
  p9
                Before Clipping                             After Clipping

 p4                                         p10
                       p2                                          p2
           p1                                          p1
                                       p8
                            p6                                            p6   p
                                                  p
                                                                                8
p3 p5                                              5


                 p7                                                  p
                                                                      7

   Parametric equations of line segment from  x0 , y0  to  xend , yend 

   x  x0  u  xend  x0  , y  y0  u  yend  y0  , 0  u  1, can be used

   to determine the parts contained in clipping window.
 Intersection calculations are expensive. Find first lines completely inside or
 certainly outside clipping window. Apply intersection only to undecided lines.

May 2010                                                                            8
  Cohen-Sutherland Line Clipping Algorithm
• Perform cheaper tests before proceeding to expensive
  intersection calculations.
• Assign code to every endpoint of line segment.
    – Borderlines of clipping window divide the plane into two halves.
    – A point can be characterized by 4-bit code according to its
      location in half planes.
    – Location bit is 0 if the point is in the positive half plane, 1
      otherwise.
    – Code assignment involves comparisons or subtractions
• Completely inside / certainly outside tests involve only
  logic operations of bits.
May 2010                                                                 9
                   Top bit   Bottom bit       Right bit   Left bit


                    x  xwmin                       xwmax  x

     1     0   0   1             1   0    0     0              1     0   1    0

                                                                             ywmax  y


     0     0   0   1             0   0    0     0              0     0   1    0


                                                                             y  ywmin

     0     1   0   1             0   1    0     0              0     1   1    0


           Endpoint codes are 0000 for both iff line is completely inside.

           If endpoint codes has 1 in same bit, line is certainly outside.
May 2010                                                                                 10
    Lines that cannot be decided are intersected with window border lines.

    Each test clips the line and the remaining is tested again for full inclusion
    or certain exclusion, until remaining is either empty or fully contained.

                  p2
                                                            Endpoints of lines are
1    0        0   1                  1    0   0   0         examined against left,
                       p 2
                                   p 
                                     2
                                                            right, bottom and top
                                                            borders (can be any
                                                            order).
0    0        0   1                  0    0   0   0

         p3
                                                   
                                                  p1
                      p
                       3
0    1        0   1           p4     0    1   0   0    p1

May 2010                                                                             11
       Liang-Barsky Line Clipping Algorithm
  Undecided lines in Cohen-Sutherland Alg. can be treated more efficiently.

  Clipping window is defined by intersections of four half-planes.

                                                      xend , yend 
                              xwmin        xwmax


                                                          ywmax

                                                            
                 x0 , y0                                ywmin



                                      
May 2010                                                                      12
 Parametric presentation:

 x  x0  u  xend  x0  , y  y0  u  yend  y0  , 0  u  1.

 A point on the line is cotained in the clipping window iff:

 xwmin  x0  u  xend  x0   xwmax , ywmin  y0  u  yend  y0   ywmax .

 It can be expressed by: upk  qk , k  1, 2,3, 4, where

 p1  x0  xend , q1  x0  xwmin ; p2  xend  x0 , q2  xwmax  x0 .

 p3  y0  yend , q3  y0  ywmin ; p4  yend  y0 , q4  ywmax  y0 .

In the inequality upk  qk if pk  0 (pk  0), the traversal from  x0 , y0 

to  xend , yend  by incrasing u from   to + proceeds the line from

the  () half-plane to  () one (with respect to the k -th border).

May 2010                                                                         13
   Intersection of  ,   extension with k -th border occurs at

   u  qk pk .

   We calculate and update u0 and uend progressively for k  1, 2,3, 4

   borders (left, right, bottom, top). If pk  0 u0 is calculated since

   progression is from  to  half planes. Similarly, if pk  0 uend

   is calculated.

   u0 is the maximum among 0 and all qk pk . uend is the minimum

   among 1 and all qk pk . The feasibility condition uend  u0 is

   progressively checked. The line is completely outside if uend  u0 .


May 2010                                                                  14
 Notice that qk pk doesn't need actual division since comparison of

 q p with q p can be done by comparison of qp with qp, and

 the quotient q p can be stored as a pair  q, p  .


  Only if uend  u0 (given by pairs  q0 , p0  and  qend , pend  ), the actual

  ends of the clipped portion are calculated.


  This is more efficient than Cohen-Sutherland algorithm, which

  computes intersection with clipping window borders for each
  undecided line, as a part of the feasibility tests.


May 2010                                                                            15
 Nicholl-Lee-Nicholl Line Clipping Algorithm

• Create more regions around clipping window to avoid
   multiple line intersection calculations.

• Perform fewer comparisons and divisions than Cohen-
   Sutherland and Liang-Barsky, but cannot be extended to
   3D, while they can.

• For complete inclusion in clipping window or certain
   exclusion we’ll use Cohen-Sutherland.


May 2010                                                 16
                                                      P0


           P0                 P0




    Examine first where the starting point P0 is located. Only three regions

    are considered. Location in any of the other six regions can be handled

    by symmety transformation.
                                                               T
    The location of Pend in each region
                                                        R               L
    defines what edge the line  P0 , Pend 
                                                              P0

    is intersecting.                                           B

May 2010                                                                       17
                                      Detection of whether Pend is in any of
            Pend
                       LT             regions L is immediate. Else, Pend is

              L                      detected for being positioned in any
                   L
                                     of LB, LR or LT, case where  P0 , Pend 
 P0                         LR
              L

                       LB            is clipped with left border and bottom,
       Pend
                                      right or top border, respectively.

 The slope of  P0 , Pend  is compared to  P0 , Pcorner  for each corner to

 find the region of Pend . Once one of LT, LR or LB regions is found,

 intersection point with appropriate border is calculated.

P0 , Pend  is entierely clipped if Pend is positioned outside the regions.
 May 2010                                                                        18
 P0                                 P0
                                                         T
                                                    L             TR

                                                L            LR
                   T                                LB
               T
                        TR
           L
           LB      TB

                         There are two cases, depending on whether

                         P0 is closer to left or top borders.

   Notice that simple inclusion test of P end i n clipping rectangle is not

   enough since there are both T and L labe ls for the regions inside.

   Testing of the angular regions is a must .
May 2010                                                                      19
     Sutherland-Hodgman Polygon Clipping
           1
                         1’’                                        1’’
               1’                    3’’                  1’                    3’’
                                               Clipping
           Clipping Window                 3

                                     3’                                         3’
                    2’         2’’                             2’         2’’
                      2
     Efficient algorithm for clipping convex polygons.

     Edges are clipped against every border line of clipping window. Edges
     are processed successively.

     Allows pipelining of edge clipping of polygons, as well as pipelining of
     different polygons.

May 2010                                                                              20
      The four possible outputs generated by the left clipper, depending on
      the relative position of pair of edge endpoints.


  out          in                            in      in
                                                                v2
             
   output: v 1 v 2                           output: v 2

                                        v2                           v1
                               
                              v1
                    v1
                                             out      out
                                   v1
                          
                         v1                  output: none
                v2                                  v1
    in        out
    output:    
              v1
                                                           v2
May 2010                                                                      21
                                                             2
                             2’

                  3                  2”

                                                        1’
                              3’
                                                    1
  Input      Left Clipper          Right Clipper             Bottom Clipper         Top Clipper

 [1,2]:    (in-in)>{2}

 [2,3]:    (in-out)>{2’}     [2,2’]:(in-in)>{2’}
 [3,1]:    (out-in)>{3’,1}   [2’,3’]:(in-in)>{3’}       [2’,3’]:(in-out)>{2”}
                             [3’,1]:(in-in)>{1}         [3’,1]:(out-out)>{}
                             [1,2]:(in-in)>{2}          [1,2]:(out-in)>{1’,2}   [2”,1’]:(in-in)>1’}
                                                        [2,2’]:(in-in)>{2’}     [1’,2]:(in-in)>{2}
                                                                                [2,2’]:(in-in)>{2’}
                                                                                [2’,2”]:(in-in)>{2”}

May 2010                                                                                               22
• The four clippers can work in parallel.
    – Once a pair of endpoints it output by the first clipper, the second
      clipper can start working.
    – The more edges in a polygon, the more effective parallelism is.
• Processing of a new polygon can start once first clipper
  finished processing.
    – No need to wait for polygon completion.




May 2010                                                                23
               Convex Polygon Intersection
           P


                                                       P∩Q



                        Q

  Theorem: The intersection of an L-vertex convex polygon and an M-vertex
  convex polygon is a convex polygon of L+M vertices at most.

  Proof: P∩Q is an intersection of L+M interior half planes determined by the
  two polygons.
  Intersection of convex polygons can answer the question of whether two
  sets of points can be separated by a line.
May 2010                                                                        24
  Theorem: The intersection of an L-vertex convex polygon and an M-vertex
  convex polygon can be found in θ(L+M) time.

   Proof: Polygons are given in cyclic order of vertices. We start from the
   leftmost vertex of both polygons and progress along the border of both
   in a left-to-right fashion, defining O(L+M) slabs.

   Inside a slab each polygon forms a trapezoid. The intersection of two
   trapezoids can be calculated in constant time.
May 2010                                                                      25
   Another solution: The non empty intersection of two convex polygon
   forms a sequence of “sickles” enclosing the intersection. The border of a
   sickle comprises internal and external sequence of vertices originating
   from P and Q, which are alternating in every sickle.



                                                            sickle


                                     R=P∩Q
                  P



                                 Q
 Let P: (p1,p2,…,pL) and Q: (q1,q2,…,qM) be counterclockwise cyclically
 ordered. The algorithm advances such that ∂P and ∂Q are “chasing” one
 another, adjusting their speeds so that they meet at every intersection.
May 2010                                                                       26
 Let pi and q j be the vertices where the traversal is. pi 1 pi and q j 1q j are

 the current edges, defining the half planes h  pi  and h  q j  , containing P

 and Q, respectively. Clearly R  h  pi  h  q j  . There are four possible

 situations of pi and q j with respect to R. For each an advancing rule is in

 order. The idea to progress along boundary of the "lagging" polygon.


      qj              Advance is from pi since there's no chance for a future

                (a)   intersection point in the edge pi 1 pi . Edge q j 1q j may

      pi              have a future intersection with the boundary of P.


May 2010                                                                             27
                        Edge pi 1 pi may still be intersected later by Q,
            pi
                 (b)    while edge q j 1q j have already exahusted its
            qj
                        intersections. Hence advance is from q j .

       qj
                        Edge q j 1q j may still be intersected later by P,
            pi
                 (c)    while edge pi 1 pi have already exahusted its

                        intersections. Hence advance is from pi .


                        Arbitrary choice. Advancing from q j yields
                  (d)
       pi   qj          (a), while advancing from pi yields (b).


May 2010                                                                      28
 void CONVEX_POLYGON_INTERSECTION (polygon P, polygon Q) {
     i  1; j  1; k  1; // initialization
     while ( k  2  L  M  ) {
         if ( pi 1 pi and q j 1q j intersect) { report intersection }
         ADVANCE; // apply one of (a), (b), (c) or (d) cases
          k ;
     }
     if (no intersection reported) {
         if ( pi  Q ) { P  Q }
         elseif ( q j  P ) { Q  P }
         else { Q     P }
     }
 }


May 2010                                                                  29
May 2010   30
 Correcness of algorithm : If pi and q j belong to the same sickle, the

 intersection point terminating the sickle must be found since algorithm

 never ADVANCE along the polygon whose current edge may contain

 a sought intersection point.

 This in turn guarantees that once an intersection point of a sickle is found,
 all the others will be constructed successively.


 To complete the proof we must show that an intersection point must be

 found if P Q  . Let edge pi 1 pi , the current edge on P, contain an

 intersection point v with edge qr 1qr on Q, so v  h  pi  .


May 2010                                                                         31
                              pi
                                       qr 1
                         qr
                                   v
                                          pi 1



           Cs
                                                  Cr
                qs

           farthest vertex



May 2010                                               32
Let q j 1q j be current edge and q j  Cr . Sequence of cases (a), (c), (d) and (b)

(possibly empty) result in, while pi 1 pi remains stationary, until v is found.


                                   pi
                                    v qr 1
                              qr
                                          pi 1    case (d)
                               case (b)




               Cs                                                          case (c)
                                                                  Cr
                                   case (a)
                     qs

                farthest vertex
May 2010                                                                           33
Let q j  Cs , l be a line determined by q j 1q j and l  l supporting P at pm ,

the first support reached when traversing from pi along P. A sequence of

cases (a) starts at pi and will stay so until crossing l where case (c) hold up

to pm (may be empty). q j 1q j remains stationary.
                                                               l          l
                                                                   qj
                                                                        q j 1
If pm  h  qi  ADVANCE

continues marching along                                                         p
                                                                                     m

P with cases (d) and (b) until

first point pt  h  qi  is found.               pi 1
                                                          qr
                                          qr 1
                                                      pi
May 2010                                                                                 34
 If an edge like pi 1 pi exists, L  M steps must reach it since the boundary

 of at least one polygon must be consumed. Additional L  M ADVANCE

 steps suffice to obtain all the intersection points in cyclic order, yielding

 2  L  M  total steps of ADVANCE. If no intersection was found then the

 realtios P  Q, Q  P or P Q   can be resolved in O  L  M  time.




May 2010                                                                         35
                   3D Viewing Concepts

       World Coordinate System   Viewing Coordinate System




May 2010                                                     36
            3D viewing transformation pipeline
 Modeling                        World                 Viewing
Coordinates                    Coordinates            Coordinates

            Construct World-
            Coordinate Scene             Convert World-
                                         Coordinates to               Projection
             From Modeling-
               Coordinate                  Viewing-                 Transformation
             Transformations              Coordinates



                                  Projection Coordinates


                Transform Projection-   Normalized                         Device
                                        Coordinates    Map Normalized-   Coordinates
                   Coordinates to
                                                        Coordinates to
                    Normalized-
                                                      Device-Coordinates
                    Coordinates


 May 2010                                                                              37
          World to Viewing 3D Transformation
                                                                 n : viewing directionon
            yworld
                                                 yview           u  v : viewing plane

                                                                 u   ux , u y , uz 
                                                     v
                                            p0                   v   vx , v y , vz 
                     xworld                              u
                                        n                        n   nx , n y , nz 
                              z view                     xview
 zworld                                                          p 0   x0 , y0 , z0 

                      u x      uy     uz   0  1       0 0  x0 
                      v        vy     vz   0 0        1 0  y0 
           M WC,VC    x                                      
                       nx      ny     nz   0 0        0 1  z0 
                                                               
                      0        0      0    1  0       0 0 1 
May 2010                                                                                  38
                Projection Transformations
   Parallel Projection                Perspective Projection




Coordinate are transferred to          Projection lines converge in a point
viewing plane along parallel lines.    behind viewing plane.

Preserves Relative size of object’s    Parallel projection can be
portions.                              perpendicular or oblique to viewing
                                       plane.
Projection can be perpendicular or
                                       Doesn’t preserve relative size but
oblique to viewing plane.
                                       looks more realistic.
May 2010                                                                      39
             Plane View




 Front                                                           Side
 Elevation                                                       Elevation
 View                                                            View




   Orthogonal (orthographic) projections are used in engineering and
   architecture. Length and angles can be measured directly from drawings.


May 2010                                                                     40
           Clipping Window and View Volume
                                                        View
                                Orthogonal Projection
                                View Volume             Plane




      Far
      Clipping
      Plane
                 Near
                 Clipping   yview
                 Plane
                                                  Clipping window

                                         xview
                                      z view
May 2010                                                            41
           Normalizing Orthogonal Projection
  Orthogonal Projection                            ynorm
  View Volume


                                     xw                     znorm         1,1,1
 xwmin , ywmin , znear                                    xnorm


        yview


                            xview
                      z view                 1, 1, 1             Normalized View
     Display coordinate system is usually left-handed.                Volume

May 2010                                                                              42
      M ortho,norm 

           2                                            xwmax  xwmin 
       xw  xw               0               0         
                                                         xwmax  xwmin 
       max    min
                                                                       
                             2                          yw  ywmin 
                                                        max
                                                         ywmax  ywmin 
            0                                 0
                       ywmax  ywmin                                  
                                            2           znear  zfar 
           0                 0                                        
                                        znear  zfar     znear  zfar 
      
           0                 0               0                1       
                                                                       

   The complete transformation from world coordinated to normalized
   orthogonal-projection coordinates is obtained by M ortho,norm  M WC,VC .


May 2010                                                                       43
                   Oblique Parallel Projections
   Projection is defined by a
   viewing vector Vp .                           x , y
                                                   p      p   , zvp 

                                                                        L
   xp  x        V px       yp  y        V py
                       ,             
   zvp  z       V pz       zvp  z       V pz

  x p  x   zvp  z V px V pz                                           x, y, z 
                                                                                   vp




   y p  y   zvp  z V py V pz 
                                                    x, y, z 
   The above is called shear transformation, where the displacement in x
   and y linearly increases with z.

May 2010                                                                                  44
           View Volume of Parallel Oblique Projection
               View Plane




                       Clipping
                       Window                  View
                                              Volume
                                              (Side)


                                      Near     Vp
                                      Plane
                             View
                            Volume   Vp
                             (Top)              Far
                                               Plane

May 2010                                                45
                         V px        V px 
               1   0            zvp      
                          V pz        V pz        This is a 3D shear transformation.
               
                         V py        V py        x and y are displaced by amount
 M oblique    0   1            zvp             proportional to z.
                         V pz        V pz 
                                          
               0   0     1           0 
               0
                   0     0           1   



  Normalization oblique projection is similar to orthogonal projection. The
  composite transformation is obtained by the product of the two.

                        M oblique,norm  M ortho,norm  M oblique


May 2010                                                                             46
                    Perspective Projections
                                                 View Plane
    Closer objects look larger.
                                                                       Projection
                                                                       Reference
                                                                       Point




  p   x, y, z 
                                       Projection Point
                       x , y , z 
                          p   p   vp                                yview
                                                          p prp   x prp , y prp , z prp 


                          View Plane                                           xview
                                                           z view
May 2010                                                                                      47
 A point on the line connecting P   x, y, z  with Pprp   x prp , y prp , z prp  :

 x  x   x  x prp  u , y  y   y  y prp  u , z   z   z  z prp  u , 0  u  1.


 At viewing plane: u   zvp  z                 z   prp    z .

 Substitution for the point on viewing plane:

  x p  x  z prp  zvp    z   prp    z   x prp  zvp  z       z   prp    z

  y p  y  z prp  zvp    z   prp    z   y prp  zvp  z       z   prp    z


The problem with the above representation is that Z appears in denominator,
so matrix multiplication representation of X and Y on view plane as a function
of Z is not straight forward.

May 2010                                                                                        48
                          Vanishing Points
 Vanishing points occur when the viewing plane intersects with the axes of
 viewing coordinate system.
                  y                                        Vanishing Point




                                 x


           z
    Principle Axes for Cube                One-Point perspective Projection

  View plane is parallel to xy plane, intersecting with z axis. When the viewer
  is located at the perspective projection points, all parallel lines of xz and yz
  planes converge at the vanishing point.
May 2010                                                                             49
      Viewing plane is parallel to y-axis,      z-axis vanishing point
      intersecting both x-axis and z-axis




                 x-axis vanishing point




           Vanishing points of all three axes occur when viewing plane
           intersects all three axes.

May 2010                                                                 50
                        Transformation Matrix
To get rid of z in denominator we define parameter h  z prp  z and new

homogeneous coordinates  xh ,yh , zh , h  , x p  xh h , y p  yh h , yielding:

xh  x  z prp  zvp   x prp  zvp  z  , yh  y  z prp  zvp   y prp  zvp  z  .


                      P   x, y, z ,1 , Ph   xh , yh , zh , h  , Ph  M pers  P,

                                  z prp  zvp           0            x prp     x prp z prp 
                                       0           z prp  zvp       y prp     y prp z prp 
 Matrix
                      M pers                                                               
 Representation:                       0                0             sz            tz 
                                                                                            
                                 
                                       0                0            1            z prp   

May 2010                                                                                         51
 It happens that zh  zsz  t z . sz is a scaling factor and t z is translation.

 They can be set arbitrarily. We'll set their value to satisfy desired

 normalization.

  Transformed z coordinate is very useful for deciding later on the
  hidden parts of the scene.


  Notice that drawing the perspective point requires a division by h.

  h depends on z coordinate, hence evey point must be divided by a
  different number, which is very expensive!


May 2010                                                                           52
       Perspective-Projection View Volume

                                                View
   Rectangular Frustum
                                                Plane
   View Volume



           Far                                          Clipping Window
           Clipping
           Plane

                Near         yview
                                                  
                Clipping
                Plane

                                        xview
       Field-of-view Angle                      Projection
                                     z view     Reference Point


May 2010                                                                  53
     Symmetric Frustum                        Parallel Piped
     View Volume                              View Volume
                             Far Plane



                                Perspective
                                Mapping

                         Near Plane
                            View Plane

                 Clipping Window


               Projection
               Reference Point


May 2010                                                       54
           Oblique Frustum                 Parallel Piped
           View Volume                     View Volume




                             Perspective
                             Mapping




 xwmin            xwmax




May 2010                                                    55
    Oblique Perspective-Projection Frustum
We'll take the projection reference point to be the origin of viewing

coordinate system  x prp , y prp , z prp    0, 0, 0  and viewing plane at near

clipping plane. Oblique projection results shear transformation. It

transforms the intersection point of center-line with clipping window

 xwmin  xwmax ywmin  ywmax         
              ,              , znear  to  0, 0, znear  .
       2             2               

             1   0 sh zx    0      0                       xwmin  xwmax  2 
             0              0                              
M z shear   
                  1 sh zy     
                                     0 
                                              M z shear    ywmin  ywmax  2
             0   0    1     0      Z naer                         Z naer      
                                                                              
             0   0    0     1      1                                1         
May 2010                                                                               56
                           xwmin  xwmax               ywmin  ywmax
 which solves to sh zx                 and sh zy                 .
                                 2                           2
  Substituting  x prp , y prp , z prp    0, 0, 0  in the perspective-projection

  matrix and positioning the viewing near z cliipping plane at the view
  plane simplifies it to

              znear     0       0    0
             0          znear   0    0
  M pers                                
             0           0       sz   tz 
                                         
             0           0       1   0

   The z coordinate scaling factor sz and the translation t z will be

   determined by the normalization requirements.
May 2010                                                                               57
  The complete oblique perspective-projection is obtained by

  concatenating the perspective and shear matrices.

                                          znear     0            xwmin  xwmax    2 0
                                                                                          
  M obliquepers  M pers  M z shear     0         znear        ywmin  ywmax    2 0
                                          0            0                 sz            tz 
                                                                                          
                                          0            0                 1            0

    For symmetric viewing volume  xwmin   xwmax , ywmin   ywmax  .

    Transformation is simplified to:

                                              znear         0       0  0
                                             0              znear   0  0
    M symmetricpers  M pers  M z shear                                   
                                             0               0       sz t z 
                                                                            
                                             0               0       1 0 
May 2010                                                                                       58
           Normalized Perspective-Projection
 Normalization is obtained by multiplying with standard scaling matrix.

 M normpers  M xy scale  M obliquepers

    znear sx        0         sx  xwmin  xwmax  2    0
                                                            
    0             znear s y   s y  ywmin  ywmax    2 0
 
    0                0                    sz             tz 
                                                            
    0                0                    1             0

                                             xh               x
   Homogenous coordinates                   y                 y
                                             h   M normpers  
  are obtained as follows:                   zh              z
                                                              
                                             h               1
May 2010                                                              59
 Projection coordinates are:

 x p  xh h    znear sx x  sx  xwmin  xwmax  2   z ,
                                                     

 y p  yh h    znear s y y  s y  ywmin  ywmax  2   z ,
                                                       
 z p  zh h   sz z  t z   z .

We'd like normalization transform to result:

 xwmin , ywmin , znear    1, 1, 1 and  xwmax , ywmax , zfar   1,1,1 .
Substitution in above equations yields:

sx  2  xwmax  xwmin  , s y  2  ywmax  ywmin  ,

sz   znear  zfar   znear  zfar  , t z  2 znear zfar    znear  zfar  .
May 2010                                                                             60
Back substitution in the normalized perspectivetransformation yields:

               2 znear                       xwmin  xvmax                   
               xw  xw             0                                 0        
                                               xwmax  xwmin
               max      min
                                                                               
                                2 znear      ywmin  ywmax                   
                   0
                               ywmax  ywmin   ywmax  ywmin
                                                                      0        
M normpers                                                                   
                                                znear  zfar     2 znear zfar 
                   0               0                                         
                                                znear  zfar     znear  zfar 
              
                   0               0                1               0        
                                                                               




May 2010                                                                       61
                   3D Viewport Transformation
 The normalized view volume cube extending from  1, 1, 1 to

 1,1,1 is mapped to a screen viewport, extending from  xvmin , yvmin 
 to  xvmax , yvmax  . z information is stored for depth calculations. z is

 often renormalized to the range from 0 to 1.0, yielding:

                    xvmax  xvmin                       xvmax  xvmin 
                                         0          0                 
                           2                                   2
                                                                      
                                    yvmax  yvmin       yvmax  yvmin 
                           0                         0
 M normviewvol,                          2                   2       
                                                                      
    3D screen
                                                    1         1       
                           0              0
                                                    2         2       
                                                                      
                          0              0          0         1       

May 2010                                                                       62
           Settings of Perspective Projection
• Perspective projection point
    – Where the viewer (camera, eye) is positioned in the world.
• Positioning viewing plane with respect to viewing
  coordinates
    – Results vanishing points, one, two or three.
• Clipping window on viewing plane
    – Defines the infinite pyramid view volume.
• Near and far clipping planes (parallel to view plane)
    – Define the rectangular frustum view volume.
• Scale and translation parameters of perspective matrix
    – Define the normalization range.

May 2010                                                           63
                              3D Clipping
   Clipping can take place on normalized cube:

   xwmin  1, ywmin  1, zwmin  1, xwmax  1, ywmax  1, zwmax  1.

   Similar to 2D, we add two bits to code the far and near planes.

    Far bit   Near bit   Top bit   Bottom bit     Right bit      Left bit



    Recall that in 3D point is represented in homogeneous form. Hence

    P   xh , yh , zh , h  is inside the normalized cube iff

    h  xh  h, h  yh  h, h  zh  h if h  0

    h  xh  h, h  yh  h, h  zh  h if h  0

May 2010                                                                    64
           Top
                                                                      y
                                                   Far
                                   Near
    Bottom

           Left
                                                                                   x
                        Right
                                                         z


011001     011000   011010      001001    001000    001010   101001       101000   101010


010001     010000   010010      000001    000000    000010   100001       100000   100010


010101     010100   010110      000101    000100    000110   100101       100100   100110


May 2010                                                                               65
  A line is completely accepted if the codes of its ends are both 000000, or
  equivalently, if the logical OR between codes is zero.



  A line is rejected if the codes of its ends has at least one 1 in same bit, or
  equivalently, if the logical AND between codes is nonzero.


 Otherwise, the line is tested against each of the planes and the 2D Liang-
 Barsky algorithm can be extended to 3D.


                                                                
 A point P of a line segment P1P2 extending from P1  xh1 , yh1 , zh1 , h1         
                          
 to P2  xh2 , yh2 , zh2 , h2 is given by P  P1   P2  P1  u, 0  u  1.


May 2010                                                                               66
If for instance the codes of the two end points of P1P2 w.r.t the right

clipping plane xmax  1 are different, the intersection point is derived

                                    
from x p  xh h   xh1  xh2  xh1 u   h1   h2  h1  u   1.
                                                          

                                                
Solving for u yields u   xh1  h1   xh1  h1  xh2  h2  .
                                                              
Such calculation proceeds for each upk  qk , 1  k  6, while

updating u0 and u1. If at some iteration u1  u0 , line segment is

completely clipped. If upon termination u1  u0 , the end points

of the clipped line segment are obtained.


May 2010                                                                   67

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:3
posted:4/4/2011
language:English
pages:67