GR2 Advanced Computer Graphics AGR

advertisement
GR2
Advanced Computer Graphics
AGR
Lecture 2
Basic Modelling
GR2-00
1
Polygonal Representation

Any 3D object can be represented as
a set of plane, polygonal surfaces
V7
V8
V3
V4
V6
V5
V2
V1
Note: each vertex part of several
polygons
GR2-00
2
Polygonal Representation

GR2-00
Objects with curved surfaces can be
approximated by polygons improved approximation by more
polygons
3
Scene Organisation
Scene = list of objects
 Object = list of surfaces
 Surface = list of polygons
 Polygon = list of vertices

scene
object
GR2-00
vertices
surfaces
polygons
4
Polygon Data Structure
V7
Object Obj1
V8
V3
V2
V4
V6
V5
P2
V1
P1
Object Table
Obj1 P1, P2, P3,
P4, P5, P6
Polygon Table
P1
V1, V2, V3, V4
P2
V1, V5, V6, V2
.
GR2-00
...
Vertex Table
V1 X1, Y1, Z1
V2 X2, Y2, Z2
.
...
5
Typical Primitives

Graphics systems such as OpenGL
typically support:
– triangles, triangle strips and fans
– quads, quad strips
– polygons

Which way is front?
– convention is that normal points towards
you if vertices are specified counterclockwise
GR2-00
6
Modelling Regular Objects

Sweeping
sweep axis
2D Profile

Spinning
R1
R2
spinning axis
GR2-00
7
Sweeping a Circle to Generate
a Cylinder as Polygons
V13
V4
V5
V9
V2
V10
V14
V15
V18
V17
V16
vertices at z=depth
V8
V7
vertices at z=0
GR2-00
V11
V3
V1
V6
V12
V1[x] = R; V1[y] = 0; V1[z] = 0
V2[x] = R cos ; V2[y] = R sin ; V2[z] = 0 (=p/4)
Vk[x] = R cos k; Vk[y] = R sin k; Vk[z] = 0
where
k = 2 p (k - 1 )/8, k=1,2,..8
8
Exercise and Further Reading

Spinning:
– Work out formulae to spin an outline (in
the xy plane) about the y-axis

READING:
– Hearn and Baker, Chapter 10
GR2-00
9
Complex Primitives

Some systems such as VRML have
cylinders, cones, etc as primitives
– polygonal representation calculated
automatically

OpenGL has a utility library (GLU)
which contains various high-level
primitives
– again converted to polygons

For conventional graphics hardware:
– POLYGONS RULE!
GR2-00
10
Automatic Generation of
Polygonal Objects

3D scanners - or laser rangers - are
able to generate computer
representations of objects
– object sits on rotating table
– contour outline generated for a given
height
– scanner moves up a level and next
contour created
– successive contours stitched together to
give polygonal representation
GR2-00
11
A Puzzle
GR2-00
12
Modelling Objects and
Creating Worlds
We have seen how boundary
representations of simple objects can
be created
 Typically each object is created in its
own co-ordinate system
 To create a world, we need to
understand how to transform objects
so as to place them in the right place translation, at the right size - scaling, in
the right orientation- rotation

GR2-00
13
Transformations

The basic linear transformations are:
– translation: P = P + T, where T is translation
vector
– scaling: P’ = S P, where S is a scaling
matrix
– rotation: P’ = R P, where R is a rotation
matrix

GR2-00
As in 2D graphics, we use
homogeneous co-ordinates in order to
express all transformations as matrices
and allow them to be combined easily
14
Homogeneous Co-ordinates
In homogeneous coordinates, a 3D point
P = (x,y,z)T
is represented as:
P = (x,y,z,1)T
 That is, a point in 4D space, with its ‘extra’
co-ordinate equal to 1
 Note: in homogeneous co-ordinates,
multiplication by a constant leaves point
unchanged

– ie (x, y, z, 1)T = (wx, wy, wz, w)T
GR2-00
15
Translation
Suppose we want to translate P (x,y,z)T
by a distance (Tx, Ty, Tz)T
 We express P as (x, y, z, 1)T and form a
translation matrix T as below
 The translated point is P’

GR2-00
x’
y’
z’
1
=
P’
=
1
0
0
0
0
1
0
0
0
0
1
0
T
Tx
Ty
Tz
1
x
y
z
1
P
=
x + Tx
y + Ty
z + Tz
1
16
Scaling

GR2-00
Scaling by Sx, Sy, Sz relative to the
origin:
x’
y’
z’
1
=
P’
=
Sx
0
0
0
0
Sy
0
0
S
0
0
Sz
0
0
0
0
1
x
y
z
1
=
Sx . x
Sy . y
Sz . z
1
P
17
Rotation
Rotation is specified with respect to an
axis - easiest to start with co-ordinate
axes
 To rotate about the x-axis:

x’
y’
z’
1
=
1
0
0
0 cos -sin
0 sin cos
0 0
0
0
0
0
1
x
y
z
1
P’
=
Rz ()
P
a positive angle corresponds to counterclockwise direction looking
at origin from positive position on axis
EXERCISE: write down the matrices for rotation about y and z axes
GR2-00
18
Composite Transformations
The attraction of homogeneous co-ordinates
is that a sequence of transformations may
be encapsulated as a single matrix
 For example, scaling with respect to a fixed
position (a,b,c) can be achieved by:

– translate fixed point to origin- say, T(-a,-b,-c)
– scale- S
– translate fixed point back to its starting positionT(a,b,c)

GR2-00
Thus: P’ = T(a,b,c) S T(-a,-b,-c) P = M P
19
Rotation about a Specified Axis
It is useful to be able to rotate about
any axis in 3D space
 This is achieved by composing 7
elementary transformations

GR2-00
20
Rotation through  about
Specified Axis
y
y
P2
y
P1
x
x
z
z
y
y
x
GR2-00
z
translate P1
to origin
initial position
z
x
rotate through
requ’d angle, 
y
x
z
rotate so that
P2 lies on z-axis
(2 rotations)
z
rotate axis
to orig orientation
P2
P1
x
translate back
21
Inverse Transformations

As in this example, it is often useful to
calculate the inverse of a
transformation
– ie the transformation that returns to
original state
Translation: T-1 (a, b, c) = T (-a, -b, -c)
 Scaling: S-1 ( Sx, Sy, Sz ) = S ............
 Rotation: R-1z () = Rz (-)

GR2-00
22
Rotation about Specified Axis
Thus the sequence is:
T-1 R-1x() R-1 y() Rz() Ry() Rx() T
 EXERCISE: How are  and 
calculated?
 READING:

– Hearn and Baker, chapter 11.
GR2-00
23
Download