Lect25 Projections 2

Embed Size (px)

Citation preview

  • 7/27/2019 Lect25 Projections 2

    1/33

    159.235 Graphics 1

    159.235 Graphics & Graphical

    Programming

    Lecture - Projections - Part 2

  • 7/27/2019 Lect25 Projections 2

    2/33

    159.235 Graphics 2

    Projections Part 2 - Outline

    Mathematics of Projections

    Perspective Transforms

    Stereo

    Orthographic

    3D Clipping Homogeneous Coordinates (again)

  • 7/27/2019 Lect25 Projections 2

    3/33

    159.235 Graphics 3

    Mathematics of Viewing

    Need to generate the transformation

    matrices for perspective and parallel

    projections

    Should be 4x4 matrices to allow general

    concatenation

  • 7/27/2019 Lect25 Projections 2

    4/33

    159.235 Graphics 4

    Perspective ProjectionSimplest

    Case

    d

    x

    y

    z

    Projection

    Plane.

    P(x,y,z)

    Pp(xp,yp,d)

    Centre of projection at the origin,

    Projection plane at z=d.

  • 7/27/2019 Lect25 Projections 2

    5/33

    159.235 Graphics 5

    Perspective ProjectionSimplest

    Case

    d

    x

    y

    z

    P(x,y,z)

    Pp(xp,yp,d)

    z

    P(x,y,z)

    d

    z

    P(x,y,z)

    d

    y

    x

    xp

    yp

    dz

    y

    z

    ydy

    dz

    x

    z

    xdx

    z

    y

    d

    y

    z

    x

    d

    x

    pp

    pp

    /;

    /

    ;

    :trianglessimilarFrom

  • 7/27/2019 Lect25 Projections 2

    6/33

    159.235 Graphics 6

    Perspective Projection

    01/d00

    0100

    0010

    0001

    :matrix4x4aasdrepresentebecanationtransformThe

    perM

    TT

    T

    pp dzzyxd

    zyd

    zxddyx

    1..1

  • 7/27/2019 Lect25 Projections 2

    7/33

    159.235 Graphics 7

    Perspective Projection

    TT

    perp

    T

    p

    dzzyxWZYX

    z

    y

    x

    PMP

    WZYXP

    /

    101/d00

    0100

    0010

    0001

    pointprojectedgeneraltheRepresent

  • 7/27/2019 Lect25 Projections 2

    8/33

    159.235 Graphics 8

    Perspective Projection

    ddz

    y

    dz

    x

    W

    Z

    W

    Y

    W

    X

    dzzyxPT

    p

    ,/,/,,

    :3Dback tocomeW toDropping

    /Trouble with this formulation :

    Centre of projection fixed at

    the origin.

  • 7/27/2019 Lect25 Projections 2

    9/33

    159.235 Graphics 9

    Finding Vanishing Points

    Recall : An axis vanishingpoint is the point wherethe axis intercepts the

    projection plane point atinfinity.

    Tvpxp 0001

    :pointby themultiply

    point,vanishingaxisxfindtoE.g

    e.perspectivpoint1ahaveweSo

    00

    01/d00

    0100

    0010

    0001

    :nformulatioFor this

    dP

    P

    P

    M

    zvp

    yvp

    xvp

    per

  • 7/27/2019 Lect25 Projections 2

    10/33

    159.235 Graphics 10

    Alternative Formulation

    z

    P(x,y,z)

    d

    x

    xp

    z

    P(x,y,z)

    d

    y

    yp

    Projection plane at z = 0

    Centre of projection at

    z = -d

    1)/(;

    1)/(

    dbyMultiply

    ;

    :trianglessimilarFrom

    dz

    y

    dz

    ydy

    dz

    x

    dz

    xdx

    dz

    y

    d

    y

    dz

    x

    d

    x

    pp

    pp

  • 7/27/2019 Lect25 Projections 2

    11/33

    159.235 Graphics 11

    Alternative Formulation

    11/d00

    00000010

    0001

    perM

    z

    P(x,y,z)

    d

    x

    xp

    z

    P(x,y,z)

    d

    y

    yp

    Projection plane at z = 0,

    Centre of projection at

    z = -d

    Now we can allow d

  • 7/27/2019 Lect25 Projections 2

    12/33

    159.235 Graphics 12

    Stereo Projection

    Stereo projection is just two perspective projections :

    object

    Left eye

    Right eye

    z

    x

    r

    r

    l

    l

    display screen

    Max effect at 50cm

    E

    E

  • 7/27/2019 Lect25 Projections 2

    13/33

    159.235 Graphics 13

    Stereo Projection

    E is the interocular separation, typically 2.5cm to 3cm.d is the distance of viewer from display, typically 50cm.

    Let 2E = 5cm:

    1100

    0000

    0010

    20001

    :

    1100

    0000

    0010

    20001

    :

    d

    d

    eyeRight

    d

    d

    eyeLef t

    .10

    2:

    71.5505

    tan2tan

    11

    anglepreservetodEthus

    dEanglestereoo

  • 7/27/2019 Lect25 Projections 2

    14/33

    159.235 Graphics 14

    View as an Anaglyph (Red/Green)

  • 7/27/2019 Lect25 Projections 2

    15/33

    159.235 Graphics 15

    Orthographic Projection

    1000

    0000

    0010

    0001

    orthM

    Orthographic Projection onto a plane at z = 0.

    xp = x , yp = y , z = 0.

  • 7/27/2019 Lect25 Projections 2

    16/33

    159.235 Graphics 16

    Implementation of Viewing

    Transform into world coordinates.

    Perform projection into view volume oreyecoordinates.

    Clip geometry outside the view volume.

    Perform projection into screen coordinates. Remove hidden lines.

  • 7/27/2019 Lect25 Projections 2

    17/33

    159.235 Graphics 17

    3D Clipping

    For orthographic projection, view volume is

    a box.

    For perspective projection, view volume is afrustrum.

    Far c lipping plane.

    Near clipping plane

    left

    right

    Need to calculate intersection

    With 6 planes.

  • 7/27/2019 Lect25 Projections 2

    18/33

    159.235 Graphics 18

    Speeding up Projection

    Can always place camera at origin !

    OpenGL , Renderman.

    Much easier to clip lines to unit cube

    Define canonicalview volumes.

    Define normalising transformations that project

    view volume into canonical view volume.

    Clip, transform to screen coordinates.

  • 7/27/2019 Lect25 Projections 2

    19/33

    159.235 Graphics 19

    3D Clipping

    Can use Cohen-Sutherland algorithm.

    Now 6-bit outcode.

    Trivial acceptance where both endpointoutcodes are all zero.

    Perform logical AND, reject if non-zero.

    Find intersect with a bounding plane and addthe two new lines to the line queue.

    Line-primitive algorithm.

  • 7/27/2019 Lect25 Projections 2

    20/33

    159.235 Graphics 20

    3D Polygon Clipping

    Sutherland-Hodgman extends easily to 3D.

    Call CLIP procedure 6 times rather than 4

    Polygon-primitive algorithm.

  • 7/27/2019 Lect25 Projections 2

    21/33

    159.235 Graphics 21

    Sutherland-Hodgman Algorithm

    Four cases of polygon clipping :

    Inside Outside Inside Outside Inside Outside Inside Outside

    Case 3

    No

    output.Case 1

    Output

    Vertex

    Case 2.

    Output

    Intersection

    Case 4

    Second

    Output

    First

    Output

  • 7/27/2019 Lect25 Projections 2

    22/33

    159.235 Graphics 22

    Clipping and Homogeneous

    Coordinates

    Efficient to transform frustrum into perspective

    canonical view volumeunit slope planes. Even better to transform to parallel canonical view

    volume

    Clipping must be done in homogeneous coordinates.

    Points can appear withve W and cannot be

    clipped properly in 3D.

  • 7/27/2019 Lect25 Projections 2

    23/33

    159.235 Graphics 23

    Transforming between canonical

    view-volumes

    The perspective canonical view-volume can be transformedto the parallel canonical view-volume with the following

    matrix:

    0100)1()1(

    1

    00

    0010

    0001

    ]1,[

    d

    d

    d

    TthendzIf ppcv

    Derivation left as an exercise :-)

  • 7/27/2019 Lect25 Projections 2

    24/33

    159.235 Graphics 24

    Clipping in 3D.

    3D parallel projection volume is defined by:

    -1x1, -1 y1 , -1 z0

    Replace by X/W,Y/W,Z/W:

    -1X/W1, -1 Y/W1 , -1 Z/W0

    Corresponding plane equations are :

    X= -W, X=W, Y=-W, Y=W, Z=-W, Z=0

  • 7/27/2019 Lect25 Projections 2

    25/33

    159.235 Graphics 25

    Clipping in W

    If W>0 , multiplication by W doesnt

    change sign.

    W>0: -W X W, -W Y W, -W Z 0

    However if W

  • 7/27/2019 Lect25 Projections 2

    26/33

    159.235 Graphics 26

    Points in Homogeneous

    Coordinates

    X or Y

    W

    W=1

    P1=[1 2 3 4]T

    P2=[-1 2 3 4]T

    Projection of P1 and P2 onto W=1 plane

  • 7/27/2019 Lect25 Projections 2

    27/33

    159.235 Graphics 27

    Points in Homogeneous Coordinates

    X or Y

    W

    W=1

    P1=[1 2 3 4]T

    P2=[-1 2 3 4]T

    Projection of P1 and P2 onto W=1 planeRegion A

    Region B

    Need to consider both regions when

    Performing clipping.

  • 7/27/2019 Lect25 Projections 2

    28/33

    159.235 Graphics 28

    Clipping in Homogeneous

    Coordinates

    Could clip twiceonce for region B, once

    for region A.Expensive.

    Check for negative W values and negate

    points before clipping. What about lines with endpoints in each

    region ?

  • 7/27/2019 Lect25 Projections 2

    29/33

    159.235 Graphics 29

    Lines in Homogeneous Coordinates

    X

    WP1

    P2

    W=1

    Projection of points.

  • 7/27/2019 Lect25 Projections 2

    30/33

    159.235 Graphics 30

    Lines in Homogeneous Coordinates

    X

    WP1

    P2

    W=1

    W=-X

    W=XClipped lines

    Solution : Clip linesegments, negate both

    endpoints, clip again.

  • 7/27/2019 Lect25 Projections 2

    31/33

    159.235 Graphics 31

    Final Step

    Divide by W to get back to 3-D

    Divide by z.

    Where the perspective projection actually getsdoneperspective foreshortening.

    Now we have a view volume.

    Dont flatten z due to hidden line calculations.

  • 7/27/2019 Lect25 Projections 2

    32/33

    159.235 Graphics 32

    Projections in Java

    Use Java 3D package

    Or can DIY!

  • 7/27/2019 Lect25 Projections 2

    33/33

    159 235 Graphics 33

    Projections - Summary

    Orthographic matrix - replace (z) axis withpoint.

    Perspective matrixmultiply w by z.Clip in homogeneous coordinates.

    Preserve z for hidden surface calculations.

    Can find number of vanishing points

    Acknowledgments - thanks to Eric McKenzie, Edinburgh, from whoseGraphics Course some of these slides were adapted.