3D viewing -b.pdf

Embed Size (px)

Citation preview

  • 7/27/2019 3D viewing -b.pdf

    1/26

    '

    &

    $

    %

    3D Viewing

    Chapter 7

    Projections

    3D clipping

    OpenGL viewing functions and clipping planes

    1

  • 7/27/2019 3D viewing -b.pdf

    2/26

    '

    &

    $

    %

    Projections

    Parallel

    Coordinates are transformed

    along parallel lines

    Relative sizes are preserved

    Parallel lines remain parallel

    Perspective

    Projection lines converge at a

    point

    More distant objects are rela-

    tively smaller

    Closer to the way we actually see

    things

    2

  • 7/27/2019 3D viewing -b.pdf

    3/26

    '

    &

    $

    %

    Orthogonal Projections

    An orthogonal projection is a parallel projection where the transformation

    lines are perpendicular to the view plane.

    Orthogonal projections are used for engineering drawings front and side

    elevations and plan view.

    Axonometricprojection lets you see multiple faces of an object at once.

    An isometricprojection has the view direction along a (1,1,1) direction of the

    world coordinate system.

    3

  • 7/27/2019 3D viewing -b.pdf

    4/26

    '

    &

    $

    %

    Orthogonal Projections

    If the view plane is perpendicular to the z-axis,

    xp = x

    yp = y

    The z coordinate is used only for visibility calculations.

    4

  • 7/27/2019 3D viewing -b.pdf

    5/26

    '

    &

    $

    %

    Clipping

    The view volume for an orthogonal projection is a rectangular parallelepiped

    with a cross-section the same size as the clipping window.

    This will be normalized to a cube.

    5

  • 7/27/2019 3D viewing -b.pdf

    6/26

    '

    &

    $

    %

    Normalization

    The normalization transformation involves translation and scaling in all 3directions.

    M ortho,norm

    2xwmaxxwmin

    0 0 xwmax+xwminxwmaxxwmin

    0 2xwmaxxwmin

    0 xwmax+xwminxwmaxxwmin

    0 0 2znearzfar

    znear+zfarznearzfar

    0 0 0 1

    6

  • 7/27/2019 3D viewing -b.pdf

    7/26

    '

    &

    $

    %

    Oblique Parallel Projections

    For this kind of projection, projection paths are not perpendicular to the view

    plane.

    Use two angles to specify the projection.

    Point (x,y,z) projects to (xp,yp, zvp).

    xp = x + L cos

    yp = y + L sin

    7

  • 7/27/2019 3D viewing -b.pdf

    8/26

    '

    &

    $

    %

    Oblique Parallel Projections

    the projection line makes an angle with the line between the projected point

    and the orthogonal projection point.

    tan =zvp z

    Lx

    An orthogonal projection has = 90.

    Oblique projections correspond to a shearing transformation.

    Can use a projection vector to specify the projection.

    8

  • 7/27/2019 3D viewing -b.pdf

    9/26

    '

    &

    $

    %

    Cabinet and Cavalier Projections

    Typical choices for are 30 and 45.

    A cavalier projection has = 45

    A cabinet projection has tan = 2 so 63.4.

    9

  • 7/27/2019 3D viewing -b.pdf

    10/26

    '

    &

    $

    %

    Oblique Transformations

    The view volume is a parallelepiped.

    Use a shear transformation to convert this volume into a rectangular paral-

    lelepiped.

    Moblique =

    1 0 V pxVpz

    zvpVpxVpz

    0 1 V pyVpz

    zvpVpyVpz

    0 0 1 0

    0 0 0 1

    Then transform as for an orthogonal projection.

    M oblique, norm = Mortho,norm Moblique

    This is applied after MWC, V C.

    10

  • 7/27/2019 3D viewing -b.pdf

    11/26

    '

    &

    $

    %

    Perspective Projections

    Parallel projections are easy but not very realistic looking.

    Perspective transformations are more realistic.

    Points are projected along lines that meet at a reference point.

    P1

    P2

    (xprp, yprp, zprp)

    ProjectionReferencePoint

    yview

    zview

    More distant objects appear relatively smaller in a perspective projection.

    11

  • 7/27/2019 3D viewing -b.pdf

    12/26

    '

    &

    $

    %

    Transformations for Perspective Projections

    Use parametric equations for positions along a projection line.

    x = x (x xprp )u

    y = y (y yprp)u

    z = z (z zprp)u

    At (x,y,z), u = 0 and at (xprp, yprp , zprp), u = 1.

    If the view plane is at z = zvp, then

    u =zvp z

    zprp z

    Then, x and y can be calculated from u.

    Graphics packages often restrict the projection point to either be at the origin

    or along the zview axis which makes the expressions for x and y simpler.

    12

  • 7/27/2019 3D viewing -b.pdf

    13/26

    '

    &

    $

    %

    Vanishing Points

    In a perspective projection, parallel lines that arent parallel to the view point

    converge at a vanishing point.

    Each direction has its own vanishing point; principal vanishing points are for

    lines parallel to one of the coordinate axes.

    Depending on the orientation of the view plane, there may be 1, 2 or 3 principal

    vanishing points.

    13

  • 7/27/2019 3D viewing -b.pdf

    14/26

    '

    &

    $

    %

    View Volumes

    The view volume for perspective projections is an infinite pyramid formed

    from lines starting at the perspective reference point and going through the

    corners of the view plane.

    Adding near and far clipping planes reduces this to a frustum.

    14

  • 7/27/2019 3D viewing -b.pdf

    15/26

    '

    &

    $

    %

    Perspective Transformations

    The values of xp and yp calculated earlier have coefficients that depend on z.

    Need to use a transformation to homogeneous coordinates of the form

    xp =x(zprpzvp)+xprp(zvpz)

    zprpz

    yp =y(zprpzvp)+yprp(zvpz)

    zprpz

    This converts the description to homogeneous parallel-projection coordinates.

    15

  • 7/27/2019 3D viewing -b.pdf

    16/26

    '

    &

    $

    %

    Viewport Transformation

    A perspective transformation can be either symmetric or oblique.

    Use a shear transformation to convert an oblique perspective to a symmetric

    one.

    16

  • 7/27/2019 3D viewing -b.pdf

    17/26

    '

    &

    $

    %

    OpenGL Viewing Functions

    Specify viewing parameters with

    gluLookAt( x0, y0, z0, xref, yref, zref, vx, vy, vx)

    where

    P0 = (x0, y0, z0) is the viewing origin

    Pref = (xref, yref, zref) is the look-at point

    V = (V x, vy , Vz) is the view-up vector

    The positive zview-axis is in the di-

    rection

    N = P0 Pref

    Default parameters are

    P0 = (x0, y0, z0) = (0, 0, 0)

    Pref = (0, 0,1)

    V = (0, 1, 0)

    17

  • 7/27/2019 3D viewing -b.pdf

    18/26

    '

    &

    $

    %

    Orthogonal Projections

    An orthogonal projection is specified with

    glMatrixMode( GLPROJECTION);

    glOrtho( xwmin, xwmax, ywmin, ywmax, dnear, dfar);

    Default parameters are

    xwmin = ywmin = dnear = -1

    xwmax = ywmax = dfar = 1

    Note that znear is behind the viewing position.

    gluOrtho2D is equivalent to gluOrtho with dnear = -1.0 and dfar = 1.0.

    To do oblique parallel projections you need to either rotate the scene to get

    the effect you want or set up the matrices manually.

    18

  • 7/27/2019 3D viewing -b.pdf

    19/26

    '

    &

    $

    %

    Field of View

    19

  • 7/27/2019 3D viewing -b.pdf

    20/26

    '

    &

    $

    %

    Perspective Transformations

    For a symmetric perspective transformation, use

    gluPerspective( theta, aspect, dnear, dfar)

    For a general perspective transformation, use

    glFrustum( xwmin, xwmax, ywmin, ywmax, dnear, dfar);

    20

  • 7/27/2019 3D viewing -b.pdf

    21/26

    '

    &

    $

    %

    3D Clipping Algorithms

    Often do the clipping after normalization to make it more efficient. This also

    allows clipping to be done in hardware.

    Several algorithms

    Region Clipping

    Polygon clipping

    Arbitrary Clip planes

    21

  • 7/27/2019 3D viewing -b.pdf

    22/26

    '

    &

    $

    %

    3D Region Codes

    Now have clipping planes instead of lines.

    Extend the region codes to have two extra bits.

    bit 6 bit 5 bit 4 bit 3 bit 2 bit 1

    Far Near Top Bottom Right Left

    22

  • 7/27/2019 3D viewing -b.pdf

    23/26

    '

    &

    $

    %

    3D Region Codes

    Then use the same basic rules as in the 2D algorithm for elimination and calcu-

    lating intersections.

    011001 011000 011010

    010001 010000 010010

    010101 010100 010110

    001001 001000 001010

    000001 000000 000010

    000101 000100 000110

    101001 101000 101010

    100001 100000 100010

    100101 100100 100110

    23

  • 7/27/2019 3D viewing -b.pdf

    24/26

    '

    &

    $

    %

    Polygon Clipping

    Since most graphics packages deal with objects constructed from polygons,

    clipping is basically a problem of clipping polygons in 3D.

    Coordinate extents (bounding boxes) can be used for trivial rejection or ac-

    ceptance.

    Then clip edges to modify and create new vertex lists.

    24

  • 7/27/2019 3D viewing -b.pdf

    25/26

    '

    &

    $

    %25

  • 7/27/2019 3D viewing -b.pdf

    26/26

    '

    &

    $

    %

    OpenGL Clipping Planes

    Sometimes need to specify additional clipping planes. Use

    glClipPlane( id, planeParameters);

    glEnable( id);

    The values of id are GLCLIP_PLANE0, GL_CLIP_PLANE1

    The plane parameters are given as a vector with the 4 coefficients from the

    equation of the plane.

    26