Sei sulla pagina 1di 24

Course Website: http://www.comp.dit.

ie/bmacnamee
Computer Graphics 9:
Clipping In 3D
2
of
24
Contents
In todays lecture we are going to have a
look at some perspective view demos and
investigate how clipping works in 3-D
Nate Robins OpenGL tutorials
The clipping volume
The zone labelling scheme
3-D clipping
Point clipping
Line clipping
Polygon clipping

3
of
24
Nate Robins OpenGL Tutorials
Nate Robins has a number of great OpenGL
tutorial applications posted on his website
Nate Robins OpenGL Tutorials available at: http://www.xmission.com/~nate/tutors.html
4
of
24
3-D Clipping
Just like the case in two dimensions,
clipping removes objects that will not be
visible from the scene
The point of this is to remove computational
effort
3-D clipping is achieved in two basic steps
Discard objects that cant 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
5
of
24
Discard Objects
Discarding objects that cannot possibly be
seen involves comparing an objects
bounding box/sphere against the
dimensions of the view volume
Can be done before or after projection
6
of
24
Clipping Objects
Objects that are partially within the viewing
volume need to be clipped just like the 2D
case
7
of
24
The Clipping Volume
After the perspective transformation is
complete the frustum shaped viewing
volume has been converted to a
parallelopiped - remember we preserved all
z coordinate depth information

I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

8
of
24
Normalisation
The transformed volume is then normalised
around position (0, 0, 0) and the z axis is
reversed
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

9
of
24
When Do We Clip?
We perform clipping after the projection
transformation and normalisation are
complete
So, we have the following:





We apply all clipping to these homogeneous
coordinates
(
(
(
(

=
(
(
(
(

1
z
y
x
M
h
z
y
x
h
h
h
10
of
24
Dividing Up The World
Similar to the case in two dimensions, we
divide the world into regions
This time we use a 6-bit region code to give
us 27 different region codes
The bits in these regions codes are as
follows:
bit 6
Far
bit 5
Near
bit 4
Top
bit 3
Bottom
bit 2
Right
bit 1
Left
11
of
24
Dividing Up The World (cont..)
Because we have a normalised clipping
volume we can test for these regions as
follows:


Rearranging these we get:
1 1 s s
h
x
h
1 1 s s
h
y
h
1 1 s s
h
z
h
h x h
h
s s h y h
h
s s h z h
h
s s
0 > h if
h x h
h
s s h y h
h
s s h z h
h
s s
0 < h if
12
of
24
Region Codes
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

13
of
24
Point Clipping
Point clipping is trivial so we wont spend
any time on it
14
of
24
Line Clipping
To clip lines we first label all end points with
the appropriate region codes
We can trivially accept all lines with both
end-points in the [000000] region
We can trivially reject all lines whose end
points share a common bit in any position
This is just like the 2 dimensional case as
these lines can never cross the viewing
volume
In the example that follows the line from
P
3
[010101] to P
4
[100110] can be rejected
15
of
24
Line Clipping Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

16
of
24
The Equation Of The Line For 3D
Clipping
For clipping equations for three dimensional
line segments are given in their parametric
form
For a line segment with end points P
1
(x1
h
,
y1
h
, z1
h
, h1) and P
2
(x2
h
, y2
h
, z2
h
, h2) the
parametric equation describing any point on
the line is:
u P P P P ) (
1 2 1
+ =
1 0 s su
17
of
24
The Equation Of The Line For 3D
Clipping (cont)
From this parametric equation of a line we
can generate the equations for the
homogeneous coordinates:
u h h h h
u z z z z
u y y y y
u x x x x
h h h h
h h h h
h h h h
) 1 2 ( 1
) 1 2 ( 1
) 1 2 ( 1
) 1 2 ( 1
+ =
+ =
+ =
+ =
18
of
24
3D Line Clipping Example
Consider the line P
1
[000010] to P
2
[001001]
Because the lines have different values in bit
2 we know the line crosses the right boundary
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

19
of
24
3D Line Clipping Example (cont)
Since the right boundary is at x = 1 we now
know the following holds:


which we can solve for u as follows:


using this value for u we can then solve for y
p

and z
p
similarly
1
) 1 2 ( 1
) 1 2 ( 1
=
+
+
= =
u h h h
u x x x
h
x
x
h h h h
p
) 2 2 ( ) 1 1 (
1 1
h x h x
h x
u
h h
h


=
20
of
24
3D Line Clipping Example (cont)
When then simply continue as per the two
dimensional line clipping algorithm
21
of
24
3D Polygon Clipping
However the most common case in 3D
clipping is that we are clipping graphics
objects made up of polygons
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

H
e
a
r
n

&

B
a
k
e
r
,

C
o
m
p
u
t
e
r

G
r
a
p
h
i
c
s

w
i
t
h

O
p
e
n
G
L


(
2
0
0
4
)

22
of
24
3D Polygon Clipping (cont)
In this case we first try to eliminate the entire
object using its bounding volume
Next we perform clipping on the individual
polygons using the Sutherland-Hodgman
algorithm we studied previously
23
of
24
Cheating with Clipping Planes
For far clipping plane introduce something to
obscure far away objects fog
Make objects very near the camera
transparent
24
of
24
Summary
In todays lecture we examined how clipping
is achieved in 3-D

Potrebbero piacerti anche