void SetColor(int index)
 {
     //The model drawer requires a reset to change the color.
     Game.ModelDrawer.Remove(testEntity);
     displayBox = Game.ModelDrawer.GetDisplayObject(testEntity);
     displayBox.TextureIndex = index;
     Game.ModelDrawer.Add(displayBox);
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public DetectorVolumeDemo(DemosGame game)
            : base(game)
        {
            var model = game.Content.Load <Model>("tube");

            Vector3[] modelVertices;
            int[]     modelIndices;
            ModelDataExtractor.GetVerticesAndIndicesFromModel(model, out modelVertices, out modelIndices);
            detectorVolume = new DetectorVolume(new TriangleMesh(new StaticMeshData(modelVertices, modelIndices)));
            Space.Add(detectorVolume);

            game.ModelDrawer.Add(detectorVolume.TriangleMesh);

            //The detector volume works on all of the entity types:
            //Convexes!
            testEntity = new Box(new Vector3(0, -10, 0), 1, 1, 1);

            //Compounds!
            //var bodies = new List<CompoundShapeEntry>
            //{
            //    new CompoundShapeEntry(new SphereShape(.5f), new Vector3(0, -8.2f, 0), 1),
            //    new CompoundShapeEntry(new SphereShape(.5f), new Vector3(0, -9f, 0), 1),
            //    new CompoundShapeEntry(new SphereShape(.5f), new Vector3(0, -9.8f, 0), 1)
            //};
            //testEntity = new CompoundBody(bodies);

            //Mobile meshes!
            //model = game.Content.Load<Model>("tube");
            //TriangleMesh.GetVerticesAndIndicesFromModel(model, out modelVertices, out modelIndices);
            //testEntity = new MobileMesh(modelVertices, modelIndices, new AffineTransform(new Vector3(.2f, .2f, .2f), Quaternion.Identity, new Vector3(0, -10, 0)), MobileMeshSolidity.Solid);

            testEntity.Tag = "noDisplayObject";
            displayBox     = game.ModelDrawer.Add(testEntity);
            SetColor(0);
            game.ModelDrawer.IsWireframe = true;
            testEntity.LinearVelocity    = new Vector3(0, 1, 0);
            Space.Add(testEntity);

            //The color of the entity will change based upon events.
            //The events don't pay attention to the causing events, so you can toss a ball through the volume to recolor the entity.
            detectorVolume.EntityBeganTouching           += BeganTouching;
            detectorVolume.EntityStoppedTouching         += StoppedTouching;
            detectorVolume.VolumeBeganContainingEntity   += BeganContaining;
            detectorVolume.VolumeStoppedContainingEntity += StoppedContaining;

            game.Camera.Position       = new Vector3(0, 0, 22);
            Space.ForceUpdater.Gravity = new Vector3();
        }