CHAPTER 4 ■ WORKING WITH MODELS
331
protected override void LoadContent()
{
device = graphics.GraphicsDevice;
basicEffect = new BasicEffect(device, null);
cCross = new CoordCross(device);
myModel = XNAUtils.LoadModelWithBoundingSphere(ref
➥
modelTransforms, "tank", Content);
}
Now that you have the sphere, you can call this method, which will indicate whether a col-
lision has occurred during the last frame:
private bool RayCollision(Model model, Matrix world,
➥
Vector3 lastPosition, Vector3 currentPosition)
{
BoundingSphere modelSpere = (BoundingSphere)model.Tag;
BoundingSphere transSphere =
➥
XNAUtils.TransformBoundingSphere(modelSpere, world);
Vector3 direction = currentPosition - lastPosition;
float distanceCovered = direction.Length();
direction.Normalize(); ...