private void FourCollisionsButton_Click(object sender, EventArgs e)
        {
            CollisionAPI API = new CollisionAPI();
            // Create some obstacles, at 4 corners of a square
            List<CollisionShape> shapes = new List<CollisionShape>();

            CollisionSphere sphere = new CollisionSphere(new Vector3(0f, 0f, 2f), 1f);
            shapes.Add(sphere);
            API.AddCollisionShape(sphere, 1);

            CollisionCapsule capsule = new CollisionCapsule(new Vector3(10f,0f,0f),
                                                            new Vector3(10f,0f,4f),
                                                            1f);
            shapes.Add(capsule);
            API.AddCollisionShape(capsule, 2);

            // Now, an AABB
            CollisionAABB aabb = new CollisionAABB(new Vector3(9.5f,9.5f,0f),
                                                   new Vector3(10.5f,10.5f,4f));
            shapes.Add(aabb);
            API.AddCollisionShape(aabb, 3);

            CollisionOBB obb = new CollisionOBB(new Vector3(0f,10f,2),
                                                   new Vector3[3] {
                                                       new Vector3(1f,0f,0f),
                                                       new Vector3(0f,1f,0f),
                                                       new Vector3(0f,0f,1f)},
                                                new Vector3(1f, 1f, 1f));
            shapes.Add(obb);
            API.AddCollisionShape(obb, 4);

            FileStream f = new FileStream("C:\\Junk\\DumpSphereTree.txt", FileMode.Create, FileAccess.Write);
            StreamWriter writer = new StreamWriter(f);

            API.DumpSphereTree(writer);
            API.SphereTreeRoot.VerifySphereTree();

            // Now a moving object capsule in the center of the square
            CollisionCapsule moCap = new CollisionCapsule(new Vector3(5f,5f,0f),
                                                          new Vector3(5f,5f,4f),
                                                          1f);

            // Remember where the moving object started
            Vector3 start = moCap.center;

            // Move the moving object toward each of the obstacles
            foreach (CollisionShape s in shapes) {
                moCap.AddDisplacement(start - moCap.center);
                MoveToObject(writer, API, s, moCap);
            }

            writer.Close();
        }
        private void RandomSpheresButton_Click(object sender, EventArgs e)
        {
            const int iterations = 20;
            const int objects = 10;
            const float coordRange = 1000.0f;
            const float objectSizeRange = 20.0f;

            CollisionAPI API = new CollisionAPI();
            Random rand = new Random((int)3141526);
            FileStream f = new FileStream("C:\\Junk\\RandomSphereTree.txt", FileMode.Create, FileAccess.Write);
            StreamWriter stream = new StreamWriter(f);

            // Create and delete many randomly-placed collision
            // objects, periodically verifying the sphere tree
            for (int i=0; i<iterations; i++) {
                stream.Write("//////////////////////////////////////////////////////////////////////\n\n");
                stream.Write(string.Format("Creation Iteration {0}, adding {1} objects, object size range {2}, coordinate range {3}\n\n",
                                           i, objects, objectSizeRange, coordRange));
                GenerateRandomObjects(stream, API, rand, objects, 0, coordRange, objectSizeRange);
                stream.Write(string.Format("\n\nAfter iteration {0}:\n\n", i));
                API.DumpSphereTree(stream);
                stream.Flush();
                API.SphereTreeRoot.VerifySphereTree();
            }
            for (int i=0; i<objects; i++) {
                stream.Write("\n\n//////////////////////////////////////////////////////////////////////\n\n");
                stream.Write(string.Format("Deleting shapes with handle {0}\n\n", i));
                API.RemoveCollisionShapesWithHandle(i);
                API.DumpSphereTree(stream);
                stream.Flush();
                API.SphereTreeRoot.VerifySphereTree();
            }
            stream.Close();
        }