public void Setup()
        {
            _worldExtent = 15.0f;
            _proxyExtent = 0.5f;

            _random = new Random(888);

            float h = _worldExtent;

            _queryAABB.LowerBound = new Vector2(-3.0f, -4.0f + h);
            _queryAABB.UpperBound = new Vector2(5.0f, 6.0f + h);

            _rayCastInput.Point1      = new Vector2(-5.0f, 5.0f + h);
            _rayCastInput.Point2      = new Vector2(7.0f, -4.0f + h);
            _rayCastInput.MaxFraction = 1.0f;

            _tree   = new DynamicTree <Actor>();
            _actors = new Actor[100];

            for (int i = 0; i < _actors.Length; i++)
            {
                Actor a = new Actor();
                GetRandomAABB(out AABB randAabb);
                a.AABB     = randAabb;
                _actors[i] = a;
            }
        }
Exemplo n.º 2
0
        public static void OpenWindow(TFPhysicsScene pScene)
        {
            scene = pScene;
            tree  = scene.dynamicTree;
            DynamicTreeViewerEditor window = GetWindow <DynamicTreeViewerEditor>();

            window.titleContent = new GUIContent("Dynamic Tree");
        }
Exemplo n.º 3
0
        void PrintChildren(int depth, DynamicTree<Actor> tree, DynamicTreeNode<Actor> node)
        {
            System.Console.WriteLine($"{new string('\t', depth)} -> [ {node.Child1Id} . {node.Child2Id} ] {new string('\t', 8 - depth)} {node.Bounds}");

            var newDepth = depth + 1;
            if (node.Child1Id != -1) PrintChildren(newDepth, tree, tree.GetNodeAt(node.Child1Id));
            if (node.Child2Id != -1) PrintChildren(newDepth, tree, tree.GetNodeAt(node.Child2Id));
        }
Exemplo n.º 4
0
        internal void DestroyProxies(DynamicTree <FixtureProxy> fixtureTree)
        {
            // Destroy proxies in the broad-phase.
            for (int i = 0; i < ProxyCount; ++i)
            {
                fixtureTree.RemoveProxy(Proxies[i].ProxyId);
                Proxies[i].ProxyId = -1;
            }

            ProxyCount = 0;
        }
Exemplo n.º 5
0
        public void TestManipulation()
        {
            var tree = new DynamicTree();

            var aabb1  = new AABB(new Vector2D(21.9995f, 1.4995f), new Vector2D(28.0005f, 2.2005f));
            var proxy1 = tree.AddProxy(aabb1, null);

            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual(0, proxy1.Depth);
            Assert.IsTrue(proxy1.IsLeaf);
            Assert.IsTrue(proxy1.IsRoot);

            var aabb2  = new AABB(new Vector2D(21.9995f, 1.9995f), new Vector2D(22.5005f, 3.7005f));
            var proxy2 = tree.AddProxy(aabb2, null);

            Assert.AreEqual(3, tree.Count);
            Assert.AreEqual(0, proxy2.Depth);
            Assert.IsTrue(proxy2.IsLeaf);
            Assert.IsFalse(proxy2.IsRoot);

            var aabb3  = new AABB(new Vector2D(27.4995f, 4.9995f), new Vector2D(28.0005f, 6.7005f));
            var proxy3 = tree.AddProxy(aabb3, null);

            Assert.AreEqual(5, tree.Count);
            Assert.AreEqual(0, proxy3.Depth);
            Assert.IsTrue(proxy3.IsLeaf);
            Assert.IsFalse(proxy3.IsRoot);

            var aabb4  = new AABB(new Vector2D(23.4495f, 1.1495f), new Vector2D(24.9505f, 3.8505f));
            var proxy4 = tree.AddProxy(aabb4, null);

            Assert.AreEqual(7, tree.Count);
            Assert.AreEqual(0, proxy4.Depth);
            Assert.IsTrue(proxy4.IsLeaf);
            Assert.IsFalse(proxy4.IsRoot);

            tree.RemoveProxy(proxy2);

            Assert.AreEqual(5, tree.Count);
            Assert.AreEqual(2, tree.FreeCount);
            Assert.AreEqual(-1, proxy2.Depth);
            Assert.IsTrue(proxy2.IsFree);

            aabb4 = new AABB(new Vector2D(23.8495f, 5.9495f), new Vector2D(25.3505f, 8.6505f));
            tree.MoveProxy(proxy4, aabb4, new Vector2D(1, 1));

            Assert.AreEqual(5, tree.Count);
            Assert.AreEqual(2, tree.FreeCount);
        }
Exemplo n.º 6
0
        private void Walk(DynamicTree <SoftBody.Triangle> tree, int index)
        {
            var tn = tree.Nodes[index];

            if (tn.IsLeaf())
            {
                return;
            }
            else
            {
                Walk(tree, tn.Child1);
                Walk(tree, tn.Child2);

                DebugDrawer.DrawAabb(tn.AABB.Min, tn.AABB.Max, Color.Red);
            }
        }
        public static IEnumerable<DesignTimeDataSourceTreeItem> BuildDesignTimeDataSourceTreeItems(DataSourceLocator locator, MyReportBase report, out DynamicTree<DesignTimeDataSourceTreeItem> tree, out List<DesignTimeDataSourceTreeItem> flatList)
        {
            var treeItems = BuildDesignTimeDataSourceTreeItems(locator, report);

            Func<string, string, DesignTimeDataSourceTreeItem> structureBuilder = (string1, string2) =>
            {
                return new DesignTimeDataSourceTreeItem()
                {
                    Name = string1,
                    Path = string2,
                    IsStructure = true
                };
            };

            var treeView = new TreeviewStructureBuilder<DesignTimeDataSourceTreeItem>();
            treeView.Delimiter = @"\";
            treeView.CreateTree(treeItems, structureBuilder, out tree, out flatList, DuplicateTreeItemBehavior.ShowOnlyOneItem);

            return treeItems;
        }
Exemplo n.º 8
0
        private static DynamicTree CreateTestTree()
        {
            var tree = new DynamicTree();

            var aabb1  = new AABB(new Vector2D(21.9995f, 1.4995f), new Vector2D(28.0005f, 2.2005f));
            var proxy1 = tree.AddProxy(aabb1, 1);

            var aabb2  = new AABB(new Vector2D(21.9995f, 1.9995f), new Vector2D(22.5005f, 3.7005f));
            var proxy2 = tree.AddProxy(aabb2, 2);

            var aabb3  = new AABB(new Vector2D(27.4995f, 4.9995f), new Vector2D(28.0005f, 6.7005f));
            var proxy3 = tree.AddProxy(aabb3, 3);

            var aabb4  = new AABB(new Vector2D(23.8495f, 5.9495f), new Vector2D(25.3505f, 8.6505f));
            var proxy4 = tree.AddProxy(aabb4, 4);

            var aabb5  = new AABB(new Vector2D(25.4995f, 6.4995f), new Vector2D(28.0005f, 7.2005f));
            var proxy5 = tree.AddProxy(aabb5, 5);

            return(tree);
        }
Exemplo n.º 9
0
 public DynamicTree<TriMesh.Vertex> BuildPrimalSpanningTree(TriMesh mesh, out TreeNode<TriMesh.Vertex>[] primalFlags)
 {
     DynamicTree<TriMesh.Vertex> primalSpanningTree = new DynamicTree<HalfEdgeMesh.Vertex>();
     TreeNode<TriMesh.Vertex>[] flags = new TreeNode<HalfEdgeMesh.Vertex>[mesh.Vertices.Count];
     foreach (TriMesh.Vertex v in mesh.Vertices)
     {
         if (!v.OnBoundary)
         {
             TreeNode<TriMesh.Vertex> root = new TreeNode<HalfEdgeMesh.Vertex>(v);
             primalSpanningTree.Root = root;
             flags[v.Index] = root;
             break;
         }
     }
     //Iterate verties to get spanning tree
     Queue<TreeNode<TriMesh.Vertex>> queue = new Queue<TreeNode<TriMesh.Vertex>>();
     queue.Enqueue(primalSpanningTree.Root);
     do
     {
         TreeNode<TriMesh.Vertex> currentNode = queue.Dequeue();
         TriMesh.Vertex currentVertex = currentNode.Attribute;
         TriMesh.HalfEdge he = currentVertex.HalfEdge;
         do
         {
             TriMesh.Vertex to = he.Opposite.FromVertex;
             if (flags[to.Index] == null &&
                 !to.OnBoundary &&
                 to != primalSpanningTree.Root.Attribute)
             {
                 TreeNode<TriMesh.Vertex> node = new TreeNode<HalfEdgeMesh.Vertex>(to);
                 flags[to.Index] = node;
                 currentNode.AddChild(node);
                 queue.Enqueue(node);
             }
             he = he.Opposite.Next;
         } while (he != currentVertex.HalfEdge);
     } while (queue.Count != 0);
     primalFlags = flags;
     return primalSpanningTree;
 }
Exemplo n.º 10
0
 public void Init()
 {
     _hasInited    = false;
     EventGroup    = new EventGroup();
     MapConfig     = Logic.Map.Map.Deserialize(Name);
     FixedQuadTree = new FixedQuadTree <SceneObject>();
     FixedQuadTree.SetBounds(new Utility.FixedRect(-FixedMath.One * MapConfig.Width / 2, -FixedMath.One * MapConfig.Height / 2, FixedMath.One * MapConfig.Width, FixedMath.One * MapConfig.Height));
     PhysicsTree = new DynamicTree <FixtureProxy>();
     for (int i = 0; i < MapConfig.Data.Data.Count; i++)
     {
         var stageData = MapConfig.Data.Data[i];
         var aabb      = new AABB(new Vector2d(stageData.X * FixedMath.One + FixedMath.Half, stageData.Y * FixedMath.One + FixedMath.Half), FixedMath.One, FixedMath.One);
         var fp        = new FixtureProxy();
         fp.AABB    = aabb;
         fp.Fixture = new Transform2d()
         {
             p = aabb.Center, angle = 0
         };
         var nodeid = PhysicsTree.AddProxy(ref aabb, fp);
     }
     EventGroup.ListenEvent(SceneEvent.OnLoaded.ToInt(), OnLoded);
 }
Exemplo n.º 11
0
        // These support body activation/deactivation.
        internal void CreateProxies(DynamicTree <FixtureProxy> fixtureTree, ref Transform xf)
        {
            if (ProxyCount != 0)
            {
                throw new InvalidOperationException("Proxies allready created for this Fixture.");
            }

            // Create proxies in the broad-phase.
            ProxyCount = Shape.ChildCount;

            for (int i = 0; i < ProxyCount; ++i)
            {
                FixtureProxy proxy = new FixtureProxy();
                proxy.Fixture    = this;
                proxy.ChildIndex = i;
                Shape.ComputeAABB(out proxy.AABB, ref xf, i);

                //FPE note: This line needs to be after the previous two because FixtureProxy is a struct
                proxy.ProxyId = fixtureTree.AddProxy(ref proxy.AABB, proxy);
                //broadPhase.SetProxy(proxy.ProxyId, ref proxy);

                Proxies[i] = proxy;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 动态化查讯(转换成表达式树集合)  注意,int参数不会判断为0的值
        /// </summary>
        /// <typeparam name="T">对应表</typeparam>
        /// <param name="dynamicTree"></param>
        /// <returns></returns>
        public QuerySet <T> Where(Dictionary <string, DynamicTree> dynamicTree)
        {
            if (dynamicTree != null)
            {
                foreach (var key in dynamicTree.Keys)
                {
                    DynamicTree tree = dynamicTree[key];
                    if (tree != null && !string.IsNullOrEmpty(tree.Value))
                    {
                        Type tableType = typeof(T);
                        if (!string.IsNullOrEmpty(tree.Table))
                        {
                            tableType = EntityCache.QueryEntity(tree.Table).Type;
                        }
                        //如果不存在对应表就使用默认表
                        ParameterExpression param = Expression.Parameter(tableType, "param");
                        object value = tree.Value;
                        if (value == null)
                        {
                            continue;
                        }
                        else if (tree.ValueType == DbType.DateTime)
                        {
                            value = Convert.ToDateTime(value);
                        }
                        else if (tree.ValueType == DbType.String)
                        {
                            value = Convert.ToString(value);
                            if ("" == value.ToString())
                            {
                                continue;
                            }
                        }
                        else if (tree.ValueType == DbType.Int32)
                        {
                            int number = Convert.ToInt32(value);
                            value = number;
                            if (0 == number)
                            {
                                continue;
                            }
                        }
                        Expression whereExpress = null;
                        switch (tree.Operators)
                        {
                        case ExpressionType.Equal:    //等于
                            whereExpress = Expression.Equal(Expression.Property(param, tree.Field), Expression.Constant(value));
                            break;

                        case ExpressionType.GreaterThanOrEqual:    //大于等于
                            whereExpress = Expression.GreaterThanOrEqual(Expression.Property(param, tree.Field), Expression.Constant(value));
                            break;

                        case ExpressionType.LessThanOrEqual:    //小于等于
                            whereExpress = Expression.LessThanOrEqual(Expression.Property(param, tree.Field), Expression.Constant(value));
                            break;

                        case ExpressionType.Call:    //模糊查询
                            var method = typeof(string).GetMethodss().FirstOrDefault(x => x.Name.Equals("Contains"));
                            whereExpress = Expression.Call(Expression.Property(param, tree.Field), method, new Expression[] { Expression.Constant(value) });
                            break;

                        default:
                            whereExpress = Expression.Equal(Expression.Property(param, tree.Field), Expression.Constant(value));
                            break;
                        }
                        WhereExpressionList.Add(Expression.Lambda(TrimExpression.Trim(whereExpress), param));
                    }
                }
            }
            return(this);
        }
Exemplo n.º 13
0
        private void Walk(DynamicTree<SoftBody.Triangle> tree, int index)
        {
            DynamicTreeNode<SoftBody.Triangle> tn = tree.Nodes[index];
            if (tn.IsLeaf()) return;
            else
            {
                Walk(tree,tn.Child1);
                Walk(tree,tn.Child2);

                DebugDrawer.DrawAabb(tn.AABB.Min,tn.AABB.Max, Color.Red);
            }
        }
Exemplo n.º 14
0
 public DynamicTree<TriMesh.Face> BuildDualSpanningCoTree(TriMesh mesh, 
                                                          TreeNode<TriMesh.Vertex>[] primalFlags, 
                                                          out TreeNode<TriMesh.Face>[] dualFlags)
 {
     DynamicTree<TriMesh.Face> dualSpanningTree = new DynamicTree<HalfEdgeMesh.Face>();
     TreeNode<TriMesh.Face>[] flags = new TreeNode<HalfEdgeMesh.Face>[mesh.Faces.Count];
     TreeNode<TriMesh.Face> root = new TreeNode<HalfEdgeMesh.Face>(mesh.Faces[0]);
     dualSpanningTree.Root = root;
     flags[mesh.Faces[0].Index] = root;
     Queue<TreeNode<TriMesh.Face>> queue = new Queue<TreeNode<TriMesh.Face>>();
     queue.Enqueue(dualSpanningTree.Root);
     do
     {
         TreeNode<TriMesh.Face> currentNode = queue.Dequeue();
         TriMesh.Face currentFace = currentNode.Attribute;
         TriMesh.HalfEdge he = currentFace.HalfEdge;
         do
         {
             TriMesh.Face toFace = he.Opposite.Face;
             if (toFace != null
                 && flags[toFace.Index] == null
                 && toFace != dualSpanningTree.Root.Attribute
                 && !InPrimalSpanningTree(he, primalFlags)
                 )
             {
                 TreeNode<TriMesh.Face> node = new TreeNode<HalfEdgeMesh.Face>(toFace);
                 flags[toFace.Index] = node;
                 currentNode.AddChild(node);
                 queue.Enqueue(node);
             }
             he = he.Next;
         } while (he != currentFace.HalfEdge);
     } while (queue.Count != 0);
     dualFlags = flags;
     return dualSpanningTree;
 }
Exemplo n.º 15
0
 public void GeneratorTreeCotree(TriMesh mesh, out DynamicTree<TriMesh.Vertex> primalTree, out DynamicTree<TriMesh.Face> dualTree)
 {
     TreeNode<TriMesh.Vertex>[] primalFlags = null;
     TreeNode<TriMesh.Face>[] dualFlags = null;
     primalTree = BuildPrimalSpanningTree(mesh, out primalFlags);
     dualTree = BuildDualSpanningCoTree(mesh, primalFlags, out dualFlags);
 }
Exemplo n.º 16
0
 public QueryEnumerable(DynamicTree <T> dynamicTree, in Box2 aabb, bool approx)
        public static IEnumerable <DesignTimeDataSourceTreeItem> BuildDesignTimeDataSourceTreeItems(IDataSourceLocator locator, MyReportBase report, out DynamicTree <DesignTimeDataSourceTreeItem> tree, out List <DesignTimeDataSourceTreeItem> flatList)
        {
            var treeItems = BuildDesignTimeDataSourceTreeItems(locator, report);

            Func <string, string, DesignTimeDataSourceTreeItem> structureBuilder = (string1, string2) =>
            {
                return(new DesignTimeDataSourceTreeItem()
                {
                    Name = string1,
                    Path = string2,
                    IsStructure = true
                });
            };

            var treeView = new TreeviewStructureBuilder <DesignTimeDataSourceTreeItem>();

            treeView.Delimiter = @"\";
            treeView.CreateTree(treeItems, structureBuilder, out tree, out flatList, DuplicateTreeItemBehavior.ShowOnlyOneItem);

            return(treeItems);
        }
Exemplo n.º 18
0
        public List<TriMesh.Edge> BuildTree(DynamicTree<TriMesh.Vertex> tree)
        {

            if (tree == null  )
            {
                return null;
            }

            List<TriMesh.Edge> treeMarks = new List<HalfEdgeMesh.Edge>();

            
                treeMarks = new List<HalfEdgeMesh.Edge>();
                TreeNode<TriMesh.Vertex> currentNode = tree.Root;
                Queue<TreeNode<TriMesh.Vertex>> queue = new Queue<TreeNode<TriMesh.Vertex>>();
                queue.Enqueue(currentNode);
                do
                {
                    currentNode = queue.Dequeue();

                    TreeNode<TriMesh.Vertex> currentChild = currentNode.LeftMostChild;
                    while (currentChild != null)
                    {
                        //Mark edge
                        TriMesh.Vertex v1 = currentNode.Attribute;
                        TriMesh.Vertex v2 = currentChild.Attribute;

                        foreach (TriMesh.HalfEdge hf in v1.HalfEdges)
                        {
                            if (hf.ToVertex == v2)
                            {
                                treeMarks.Add(hf.Edge);
                                break;
                            }
                        }

                        queue.Enqueue(currentChild);
                        currentChild = currentChild.RightSibling;
                    }

                } while (queue.Count > 0);
           

            return treeMarks;

             
            
        }
Exemplo n.º 19
0
 public MapTrees()
 {
     SpriteTree   = new DynamicTree <SpriteComponent>(SpriteAabbFunc);
     LightTree    = new DynamicTree <PointLightComponent>(LightAabbFunc);
     OccluderTree = new DynamicTree <ClientOccluderComponent>(OccluderAabbFunc);
 }
Exemplo n.º 20
0
 public MapTrees()
 {
     SpriteTree = new DynamicTree <SpriteComponent>(SpriteAabbFunc);
     LightTree  = new DynamicTree <PointLightComponent>(LightAabbFunc);
 }
Exemplo n.º 21
0
        public List<TriMesh.Edge> BuildCoTree(DynamicTree<TriMesh.Face> cotree)
        {

            if (cotree == null)
            {
                return null;
            }

            List<TriMesh.Edge> cotreeMarks = new List<HalfEdgeMesh.Edge>();

            

            
                Vector3D[]  bycenters = new Vector3D[mesh.Faces.Count];
                cotreeMarks = new List<HalfEdgeMesh.Edge>();
                TreeNode<TriMesh.Face> currentCoNode = cotree.Root;
                Queue<TreeNode<TriMesh.Face>> coQueue = new Queue<TreeNode<TriMesh.Face>>();
                coQueue.Enqueue(currentCoNode);
                do
                {
                    currentCoNode = coQueue.Dequeue();
                    bycenters[currentCoNode.Attribute.Index] = TriMeshUtil.GetMidPoint(currentCoNode.Attribute);

                    TreeNode<TriMesh.Face> currentChild = currentCoNode.LeftMostChild;
                    while (currentChild != null)
                    {
                        //Mark edge
                        TriMesh.Face f1 = currentCoNode.Attribute;
                        TriMesh.Face f2 = currentChild.Attribute;

                        foreach (TriMesh.HalfEdge hf in f1.Halfedges)
                        {
                            if (hf.Opposite.Face == f2)
                            {
                                cotreeMarks.Add(hf.Edge);
                                break;
                            }
                        }

                        coQueue.Enqueue(currentChild);
                        currentChild = currentChild.RightSibling;
                    }

                } while (coQueue.Count > 0);
       
            return cotreeMarks; 

        }