Graphics Reference
In-Depth Information
UWB
_
BoundingBox UWB
_
SceneNode::GetBounds( ...
)
const
Source file.
uwbgl
_
SceneNode2.cpp
file in the
Common Files/
SceneNode
subfolder
UWB
_
BoundingBox bbox;
// This is the bounding box (bbx)
.
of
the
UWBGL
_
D3D
_
Lib12
project.
if
(m
_
pPrimitive)
bbox.Add(m
_
pPrimitive->GetBoundingVolume( ... ));
// bbox from primitives in OC space
A:
B:
helper.PushModelTransform();
// set up OC-to-WC transform on matrix stack
m
_
xform.SetUpModelStack(helper);
.
C:
helper.TransformPoint(...)
// transform each bbox vertex from OC to WC
// computes the bounding box in WC
.
for
(
int
i=0; i<NumChildren(); i++)
// compute bbox for all children
bbox.Add(m
_
child
_
nodes[i]->GetBounds());
// extend bbox to bound all children's bbox
D:
E:
helper.PopModelTransform();
// restore the top of the matrix stack
return
bbox;
Listing 11.13.
The
SceneNode::GetBounds()
function.
•
Transform the OC bounding box to WC (C).
At label C, each of the eight
vertices of the bounding box is transformed from OC to WC. Notice that,
as illustrated in Figure 11.21, the result of transforming
B
o
b
to WC space is
a rotated rectangle. However, by definition, a bounding box must be axis-
aligned. For this reason, the bounding box in WC space is the axis-aligned
box
B
wc
b
(lower middle of
Figure 11.21
)
.
•
Compute and combine with children's bounding boxes (D).
At label D,
the child node of body, the left arm's
GetBounds()
function is invoked.
The
GetBounds()
function will be executed on behalf of the left arm, and
at label A, the left arm computes the OC bounding box
B
oc
la
(top left of
of the matrix stack. Recall that at this point, the top of the matrix stack
contains the
M
b
matrix. In this way, the OC-to-WC transformation matrix
at the top of the matrix stack becomes the concatenation of
M
b
M
la
.As
a result, the WC bounding box returned from the left arm is
B
wc
la
(upper
body's bounding box
B
wc
b
with the left arm's bounding box
B
wc
la
to form the
Search WWH ::
Custom Search