Beispiel #1
0
    public void SimpleAABBTree_BoundingBoxHitDetection_GetNearestToPoint()
    {
        SimpleAABBTree myTree    = new SimpleAABBTree();
        Vector3        TestPoint = new Vector3(0, 0, 0);
        List <NearestObjectForSort> myObjectsAndDistanceFromPoint = new List <NearestObjectForSort>();

        for (int i = 0; i < 100; i++)
        {
            var aBox     = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeStaticOBJ(aBox);
            NearestObjectForSort mySortObject = new NearestObjectForSort()
            {
                Distance = Vector3.Distance(aBox.Center, TestPoint), myObject = myEntity
            };
            myObjectsAndDistanceFromPoint.Add(mySortObject);
            myTree.Insert(myEntity);
        }

        myObjectsAndDistanceFromPoint.Sort();
        var Result = myTree.GetNearest <SimpleAABBTreeStaticOBJ>(TestPoint, 100);

        Assert.AreEqual(100, Result.Count);
        for (int i = 0; i < Result.Count; i++)
        {
            Assert.IsNotNull(Result[i]);
            //Assert.AreEqual(Vector3.Distance(Result[i].Bounds.Center, TestPoint), myObjectsAndDistanceFromPoint[i].Distance);
        }
        Result = myTree.GetNearest <SimpleAABBTreeStaticOBJ>(TestPoint, 100, 100);
        Assert.AreEqual(100, Result.Count);
        for (int i = 0; i < Result.Count; i++)
        {
            Assert.IsNotNull(Result[i]);
            //Assert.AreEqual(Result[i], myObjectsAndDistanceFromPoint[i]);
        }
    }
Beispiel #2
0
    public void SimpleAABBTree_InsertTwoOverlappingElementsRemoveOne_ChecksOtherRemains()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        BoundingBox myBox     = new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2));
        var         myEntity2 = new SimpleAABBTreeStaticOBJ(myBox);

        myTree.Insert(myEntity2);

        myTree.Remove(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.AreEqual(1, Results.Count, "Results didn't match expected number of items in the Tree.");
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity2)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Beispiel #3
0
    public void SimpleAABBTree_InsertTwoDisjointedElementsRemoveOne_ChecksOtherRemains()
    {//TODO: STILL
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        var         myEntity2 = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(1.1f, 1.1f, 1.1f), new Vector3(2, 2, 2)));
        BoundingBox myBox     = new BoundingBox(new Vector3(1.1f, 1.1f, 1.1f), new Vector3(2, 2, 2));

        myTree.Insert(myEntity2);

        myTree.Remove(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.IsTrue(Results.Count == 1);
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity2)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Beispiel #4
0
    public void SimpleAABBTree_InsertTwoElements_Intersects_TreeCheck()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2)));
        BoundingBox myBox = new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2));

        myTree.Insert(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.IsTrue(Results.Count == 2);
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Beispiel #5
0
    public void SimpleAABBTree_CountTest_OneEntityAdded()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        Assert.AreEqual(myTree.Count, 1);
    }
Beispiel #6
0
    public void SimpleAABBTree_Deletion_CheckCountIsZeroAdd1Remove1()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        Assert.IsTrue(myTree.Count == 1);
        myTree.Remove(myEntity);
        Assert.IsTrue(myTree.Count == 0);
    }
Beispiel #7
0
    public void SimpleAABBTree_BoundingBoxHitDetection_HitOne_TreeOnlyHasOne()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        BoundingBox         myTestBox = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(2, 2, 2));
        RayCastHit <Object> myHit     = myTree.BoundingPrimativeCast <Object>(myTestBox);

        Assert.AreEqual(1, myHit.Count);
    }
Beispiel #8
0
    public void SimpleAABBTree_TreeRaySingleHitDetection_OneItemInTree()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        BoundingBox    myBox    = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
        var            myEntity = new SimpleAABBTreeStaticOBJ(myBox);

        myTree.Insert(myEntity);
        Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay);

        Assert.AreEqual(myHit.Count, 1);
    }
Beispiel #9
0
    public void Test2()
    {
        SimpleAABBTree myBTree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT = 20;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            myBox = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeStaticOBJ(myBox);
            myBTree.Insert(myEntity);
        }
        myBTree.SetReadOnly(true);
        Assert.Throws <Exception>(delegate()
        {
            myBox        = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeStaticOBJ(myBox);
            myBTree.Insert(myEntity);
        });
    }
Beispiel #10
0
    public void SimpleAABBTree_TreeRaySingleHitDetection_CheckIsOne()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2)));
        myTree.Insert(myEntity);

        Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay);

        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(0.5f, -1, 0.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(1.5f, 1.5f, 1.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
    }
Beispiel #11
0
    public void SimpleAABBTree_IteratorTest_MultipleEntities_OneEntityDifferentClass_Added()
    {
        int            TESTCOUNT = 20;
        SimpleAABBTree myTree    = new SimpleAABBTree();
        BoundingBox    myBox;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));
            myTree.Insert(myEntity);
        }
        //Inserts one dummy item
        SimpleAABBTreeStaticOBJ myEntity2 = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));

        myTree.Insert(myEntity2);

        int Count = 0;

        foreach (SimpleAABBTreeDynamicInstance A in myTree.GetEnumerator <SimpleAABBTreeDynamicInstance>())
        {
            Count++;
        }
        Assert.IsTrue(Count == TESTCOUNT);
    }