/// <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; TriangleMesh.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; Space.ForceUpdater.Gravity = new Vector3(); game.Camera.Position = new Vector3(0, 0, 22); }
/// <summary> /// Constructs a new force field shape using a detector volume. /// </summary> /// <param name="volume">Volume to use.</param> public VolumeForceFieldShape(DetectorVolume volume) { Volume = volume; }
private void StoppedTouching(DetectorVolume volume, Entity toucher) { SetColor(0); }
private void StoppedContaining(DetectorVolume volume, Entity entity) { SetColor(3); }
private void BeganTouching(DetectorVolume volume, Entity toucher) { SetColor(1); }
private void BeganContaining(DetectorVolume volume, Entity entity) { SetColor(2); }