Lect11 clipping in3d

Post on 19-May-2015

227 views 0 download

description

created by Sudipta mandal

transcript

Sudipta Mondal

Computer Graphics 9:Clipping In 3D

2of24

3-D Clipping

Just like the case in two dimensions,clipping removes objects that will not bevisible from the sceneThe point of this is to remove computationaleffort3-D clipping is achieved in two basic steps

– Discard objects that can’t be viewed• i.e. objects that are behind the camera, outside

the field of view, or too far away– Clip objects that intersect with any clipping

plane

3of24

Discard Objects

Discarding objects that cannot possibly beseen involves comparing an objectsbounding box/sphere against thedimensions of the view volume

– Can be done before or after projection

4of24

Clipping Objects

Objects that are partially within the viewingvolume need to be clipped – just like the 2Dcase

5of24

The Clipping Volume

After the perspective transformation iscomplete the frustum shaped viewingvolume has been converted to aparallelopiped - remember we preserved allz coordinate depth information

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

6of24

Normalisation

The transformed volume is then normalisedaround position (0, 0, 0) and the z axis isreversed

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

7of24

When Do We Clip?

We perform clipping after the projectiontransformation and normalisation arecompleteSo, we have the following:

We apply all clipping to these homogeneouscoordinates

úúúú

û

ù

êêêê

ë

é

×=

úúúú

û

ù

êêêê

ë

é

1zyx

M

hzyx

h

h

h

8of24

Dividing Up The World

Similar to the case in two dimensions, wedivide the world into regionsThis time we use a 6-bit region code to giveus 27 different region codesThe bits in these regions codes are asfollows:

bit 6Far

bit 5Near

bit 4Top

bit 3Bottom

bit 2Right

bit 1Left

9of24

Dividing Up The World (cont..)

Because we have a normalised clippingvolume we can test for these regions asfollows:

Rearranging these we get:

11 ££-hxh 11 ££-

hyh 11 ££-

hzh

hxh h ££- hyh h ££- hzh h ££- 0>hif

hxh h -££ hyh h -££ hzh h -££ 0<hif

10of24

Region CodesIm

ages

take

n fro

m H

earn

& B

aker

, “C

ompu

ter G

raph

ics

with

Ope

nGL”

(200

4)

11of24

Point Clipping

Point clipping is trivial so we won’t spendany time on it

12of24

Line Clipping

To clip lines we first label all end points withthe appropriate region codesWe can trivially accept all lines with bothend-points in the [000000] regionWe can trivially reject all lines whose endpoints share a common bit in any position

– This is just like the 2 dimensional case asthese lines can never cross the viewingvolume

– In the example that follows the line fromP3[010101] to P4[100110] can be rejected

13of24

Line Clipping ExampleIm

ages

take

n fro

m H

earn

& B

aker

, “C

ompu

ter G

raph

ics

with

Ope

nGL”

(200

4)

14of24

The Equation Of The Line For 3DClipping

For clipping equations for three dimensionalline segments are given in their parametricformFor a line segment with end points P1(x1h,y1h, z1h, h1) and P2(x2h, y2h, z2h, h2) theparametric equation describing any point onthe line is:

uPPPP )( 121 -+= 10 ££ u

15of24

The Equation Of The Line For 3DClipping (cont…)

From this parametric equation of a line wecan generate the equations for thehomogeneous coordinates:

uhhhhuzzzzuyyyyuxxxx

hhhh

hhhh

hhhh

)12(1)12(1)12(1)12(1

-+=-+=-+=-+=

16of24

3D Line Clipping Example

Consider the line P1[000010] to P2[001001]Because the lines have different values in bit2 we know the line crosses the right boundary

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

17of24

3D Line Clipping Example (cont…)

Since the right boundary is at x = 1 we nowknow the following holds:

which we can solve for u as follows:

using this value for u we can then solve for ypand zp similarly

1)12(1

)12(1=

-+-+

==uhhh

uxxxhxx hhhh

p

)22()11(11

hxhxhxu

hh

h

----

=

18of24

3D Line Clipping Example (cont…)

When then simply continue as per the twodimensional line clipping algorithm

19of24

3D Polygon Clipping

However the most common case in 3Dclipping is that we are clipping graphicsobjects made up of polygons

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

20of24

3D Polygon Clipping (cont…)

In this case we first try to eliminate the entireobject using its bounding volumeNext we perform clipping on the individualpolygons using the Sutherland-Hodgmanalgorithm we studied previously

21of24

Cheating with Clipping Planes

For far clipping plane introduce something toobscure far away objects – fogMake objects very near the cameratransparent