// Draw a given Fish private void DrawFish(Fish fish) { Matrix world = Matrix.Identity; effectWorld.SetValue(world); effectView.SetValue(camera.View); effectProjection.SetValue(camera.Projection); Matrix trans = Matrix.CreateTranslation(fish.Position); //back fin fish.bones[24].Transform = Matrix.CreateRotationY(-animFactor); //side fins fish.bones[12].Transform = Matrix.CreateRotationY(animFactor / 5); fish.bones[9].Transform = Matrix.CreateRotationY(-animFactor / 5); //under fins fish.bones[15].Transform = Matrix.CreateRotationY(-animFactor); fish.bones[18].Transform = Matrix.CreateRotationY(animFactor); //whole fish fish.bones[1].Transform = Matrix.CreateRotationY(animFactor / 10); GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; fish.CopyAbsoluteBoneTransformsTo(ref fish.fishMatrix); world *= fish.Scale * Matrix.CreateFromQuaternion(fish.Rotation) * trans; fish.World = world; foreach (ModelMesh mesh in fish.meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = fish.matrix[mesh.ParentBone.Index] * world; effect.View = camera.View; effect.Projection = camera.Projection; effect.EnableDefaultLighting(); effect.LightingEnabled = true; } mesh.Draw(); } GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; }
// Did this fish just hit a Fish? public bool hits(Fish fishToHit, Matrix hitWorld) { BoundingSphere hitSphere = fishToHit.Sphere; BoundingSphere sphere1 = hitSphere.Transform(hitWorld); BoundingSphere hitSphere2 = Sphere; BoundingSphere sphere2 = hitSphere.Transform(World); bool collision = sphere1.Intersects(sphere2); if (collision) if (score > fishToHit.score) score = fishToHit.score; else { score = -fishToHit.score; position = startPos; dead = true; } return collision; }