Graphics Reference
In-Depth Information
void
CModel::UpdateSimulation() {
.
// check if primitive is going out of world bound
// Get the bounding volumes ready for collision detection
const
UWB
_
BoundingVolume
*
pCircleBV = m
_
Circle.GetBoundingVolume(lod);
const
UWB
_
BoundingVolume
*
pPointBV
= m
_
Point.GetBoundingVolume(lod);
const
UWB
_
BoundingVolume
*
pLineBV
= m
_
Line.GetBoundingVolume(lod);
.
// Colliding circle and point
if
(pCircleBV && pPointBV && pCircleBV->Intersects(
*
pPointBV))
m
_
Circle.CollisionResponse(&m
_
Point, ptLoc);
// circle to response
m
_
Point.CollisionResponse(&m
_
Circle, cirLoc);
// point to response
// Colliding circle and line
if
(pCircleBV && pLineBV && pCircleBV->Intersects(
*
pLineBV)) ...
// Colliding line and point
if
(pPointBV && pLineBV && pPointBV->Intersects(
*
pLineBV)) ...
.
// update the position of each object
Source file.
Model.cpp
file
in
the
Model
folder
of
the
D3D
_
Collisions
project.
Listing 7.20.
The
CModel::UpdateSimulation()
function (Tutorial 7.3).
Working with the collision functionality.
With the collision functionality sup-
ported by the library, the source code of Tutorial 7.3 differs from that of Tuto-
rial 7.2 only in the
CModel::UpdateSimulation()
function. Listing 7.20 shows
that during periodic timer updates, we must intersect all primitive objects against
each other to ensure that we have tested all the potential collisions.
7.6
Collection of Primitives
Tutorial 7.4.
Project Name:
D3D
_
ObjectCollections
Library Support:
UWBGL
_
MFC
_
Lib1
UWBGL
_
D3D
_
Lib7
From Listing 7.20, it is obvious that we need some form of collection structure
such that we can use a loop programming construct to iterate through each primi-
tive to test for the collision between all the primitives.
Tutorial 7.4. Primitive List
•
Goals.
To introduce the idea of having a collection structure itself be a
Primitive
; experience working with such structures.
Search WWH ::
Custom Search