예제 #1
0
        public IEnumerator Test9RadialRetrival()
        {
            List <GameObject> objects = SetupScene(0);
            BVH <GameObject>  bvh     = CreateBVH(objects);

            GameObject insideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj1.name = "In Radius 3";
            insideObj1.transform.localScale = Vector3.one * 0.01f;
            insideObj1.transform.position   = new Vector3(0, 5, 0);

            GameObject insideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj2.name = "In Radius 1";
            insideObj2.transform.localScale = Vector3.one * 5;
            insideObj2.transform.position   = new Vector3(0, -4.5f, 0);

            GameObject insideObj3 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            insideObj3.name = "In Radius 2";
            insideObj3.transform.localScale = Vector3.one * 5;
            insideObj3.transform.position   = new Vector3(-5, 0, 0);

            GameObject outsideObj1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            outsideObj1.name = "Outside Radius 1";
            outsideObj1.transform.localScale = Vector3.one * 5;
            outsideObj1.transform.position   = new Vector3(0, -40, 0);

            GameObject outsideObj2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            outsideObj2.name = "Outside Radius 2";
            outsideObj2.transform.localScale = Vector3.one * 5;
            outsideObj2.transform.position   = new Vector3(-5.1f, 0, 0);


            objects.Add(insideObj1);
            bvh.Add(insideObj1);

            objects.Add(insideObj2);
            bvh.Add(insideObj2);

            objects.Add(insideObj3);
            bvh.Add(insideObj3);

            objects.Add(outsideObj1);
            bvh.Add(outsideObj1);

            objects.Add(outsideObj2);
            bvh.Add(outsideObj2);

            float t = 0;

            while (t < TIME_PER_TEST)
            {
                t += Time.deltaTime;

                bvh.RenderDebug();

                Vector3 center = new Vector3(0, 5, 0);
                float   radius = 10f;
                List <BVHNode <GameObject> > hit = bvh.Traverse(BVHHelper.RadialNodeTraversalTest(center, radius));

                Debug.DrawLine(center, center + new Vector3(radius, 0, 0), Color.red);
                Debug.DrawLine(center, center + new Vector3(0, radius, 0), Color.green);
                Debug.DrawLine(center, center + new Vector3(0, 0, radius), Color.blue);

                Debug.Log("Traversed " + hit.Count + " nodes");

                int objectCount = 0;
                foreach (var g in hit)
                {
                    if (g.GObjects != null)
                    {
                        foreach (GameObject obj in g.GObjects)
                        {
                            Debug.Log("Found Object: " + obj.name);
                            Assert.AreNotSame(obj.name, "Outside Radius");
                            objectCount++;
                        }
                    }
                }

                Debug.Log("Found " + objectCount + " leaf nodes");

                yield return(null);
            }

            DestroyScene(objects);
        }