Graphics Reference
In-Depth Information
Here's a strawman algorithm for converting a scene graph into a sequence
of drawPolygon() calls. We'll work with 3
k arrays of coordinates, because
we'll represent the point ( 0, 9 ) as a homogeneous triple ( 0, 9, 1 ) , which we'll write
vertically as a column of the matrix that represents the geometry.
×
for each polygonal geometry element, g
let v be the 3 × k array of vertices of g
let n be the parent node of g
let M be the 3 × 3 identity matrix
while ( n is not the root)
if n is a transformation with matrix S
M = SM
n = parent of n
1
2
3
4
5
6
7
8
9
10
11
w
M v
drawPolygon( w )
=
As you can see, we multiply together several matrices, and then multiply the
result (the composite transformation matrix ) by the vertex coordinates to get
the WPF coordinates for each polygon, which we then draw.
Inline Exercise 10.21: (a) How many elementary operations are needed,
approximately, to multiply a 3
×
3matrixbya3
×
k matrix?
(b) If A and B are 3
1000, would you rather compute ( AB ) C or
A ( BC ) , where the parentheses are meant to indicate the order of calculations
that you perform?
(c) In the code above, should we have multiplied the vertex coordinates by
each matrix in turn, or was it wiser to accumulate the matrix product and only
multiply by the vertex array at the end? Why?
×
3 and C is 3
×
If we hand-simulate the code in the clock example, the circle template coordi-
nates are multiplied by the matrix
10 8
01 8
00 1
4.8 0 0
0 .80
001
10 0 0
0 00
001
.
(10.86)
The minute-hand template coordinates are multiplied by the matrix
.
10 8
01 8
00 1
4.8 0 0
0 .80
001
100
0
100
0
10
001
10
001
(10.87)
And the hour-hand template coordinates are multiplied by the matrix
10 8
01 8
00 1
4.8 0 0
0 .80
001
0.96
0.26
0
0.26
0.96
0
0
0
1
100
0
1.7 0 0
0 .70
001
.
·
10
001
(10.88)
 
 
Search WWH ::




Custom Search