Graphics Reference
In-Depth Information
class
UWB
_
Primitive {
Source file.
uwbgl
_
Primitive2.h
file in
the
// exactly the same as
Listing 7.9
...
// except the following three additional functions
.
// Collision Detection / Response
virtual const
UWB
_
BoundingVolume
*
GetBoundingVolume( eLevelOfDetail lod )
const
;
virtual void
CollisionResponse(
const
UWB
_
Primitive
*
pOther,
vec3
other
_
location);
void
DrawBoundingVolume( eLevelOfDetail lod, UWB
_
DrawHelper
*
pRenderer,
UWB
_
Color color )
const
;
Common
Files/Prim-
itives
subfolder
of
the
UWBGL
_
D3D
_
Lib6
project.
};
Listing 7.17.
The
UWB
_
Primitive
class (Tutorial 7.3).
Source file.
Sample code for working with
bounding volumes and prim-
itive collision response.
// assume ... pPrimA and pPrimB are pointers to Primitives
// Get the bounding volume from pPrimA
UWB
_
BoundingVolume
*
pBVA = pPrimA->GetBoundingVolume();
// Get the bounding volume from pPrimB
UWB
_
BoundingVolume
*
pBVB = pPrimB->GetBoundingVolume();
No
source file.
// Test if the two bounding volumes overlaps
if
( pBVA->Intersects(pBVB) ) {
// pPrimA responses to the collision
pPrimA->CollisionResponse( pPrimB, pPrimB->GetLocation() );
// pPrimB responses to the collision
pPrimB->CollisionResponse( pPrimA, pPrimA->GetLocation() );
}
.
Listing 7.18.
Working with the
Primitive
collision interface (Tutorial 7.3).
void
UWB
_
Primitive::CollisionResponse(
const
UWB
_
Primitive
*
pOther,
vec3
other
_
location) {
// vector points from the other
_
location towards the primitive
dir = GetLocation() - other
_
location;
Source file.
uwbgl
_
Primitive2.cpp
file
in the
Common Files/Prim-
itives
// direction pointing away from other
_
location
dir = normalize(dir);
// speed of the current velocity
mySpeed = length(GetVelocity());
// new velocity is the same speed, but away from other
_
location
SetVelocity(mySpeed
*
dir);
subfolder
of
the
UWBGL
_
D3D
_
Lib6
project.
}
Listing 7.19.
The default primitive
CollisionResponse()
function (Tutorial 7.3).
Search WWH ::
Custom Search