Esempio n. 1
0
        private void BuildNode(PureQuadTreeNode node)
        {
            float levelFalloff = falloff / node.Level;

            // first establish if visible or not by testing centre of node, then corners until visible
            bool visible = (node.Level == 0 || TestPoint(node.Centre) || TestPoint(node.Location) ||
                            TestPoint(new Vector2(node.Location.X + node.Size.X, node.Location.Y)) ||
                            TestPoint(new Vector2(node.Location.X, node.Location.Y + node.Size.Y)) ||
                            TestPoint(new Vector2(node.Location.X + node.Size.X, node.Location.Y + node.Size.Y)));

            // log what detail the leaf is to be, and if visible
            if (visible)
            {
                leafDetail[node.Code] = (short)node.Level;
            }
            else
            {
                leafDetail[node.Code] = (short)-node.Level;
            }

            if (visible)
            {
                // decide if to fork or not
                //Vector2 halfChildSize = node.Size * 0.25f;
                float distance = (node.Centre - viewPos).Length();
                // test this node first directly
                if (distance < levelFalloff)
                {
                    node.Fork(1, false);
                    for (int c = 0; c < 4; c++)
                    {
                        BuildNode(node.Children[c]);
                    }
                }
            }

            //else
            //{
            //    // test children directly
            //    for (int i = 0; i < 4; i++)
            //    {
            //        // check centre distance
            //        Vector2 centre = new Vector2();
            //        switch (i)
            //        {
            //            case 2:
            //                centre = new Vector2(node.Location.X + halfChildSize.X, node.Location.Y + halfChildSize.Y);
            //                break;
            //            case 3:
            //                centre = new Vector2(node.Location.X + (halfChildSize.X * 3), node.Location.Y + halfChildSize.Y);
            //                break;
            //            case 0:
            //                centre = new Vector2(node.Location.X + halfChildSize.X, node.Location.Y + (halfChildSize.Y * 3));
            //                break;
            //            case 1:
            //                centre = new Vector2(node.Location.X + (halfChildSize.X * 3), node.Location.Y + (halfChildSize.Y * 3));
            //                break;
            //        }
            //        float distance = (centre - viewPos).Length();
            //        if (distance < levelFalloff)
            //        {
            //            if (node.Children == null)
            //            {
            //                node.Fork(1, false);
            //                for (int c = 0; c < 4; c++)
            //                {
            //                    BuildNode(node.Children[c]);
            //                }
            //            }
            //        }
            //        else
            //        {
            //            // check visibility
            //            bool visible = false;

            //            //if (distance < falloff)
            //            //{
            //            float value = viewFOVpl1.Dot(new Vector3(node.Centre.X, 0, node.Centre.Y));
            //            if (value > 0)
            //            {
            //                //if (viewFOVpl2.Dot(new Vector3(node.Centre.X, 0, node.Centre.Y)) < 0)
            //                visible = true;
            //            }
            //            //}

            //            // log what detail the leaf is to be, and if visible
            //            if (visible)
            //                leafDetail[node.Code] = (short)node.Level;
            //            else
            //                leafDetail[node.Code] = (short)-node.Level;
            //        }
            //    }
            //}
        }
Esempio n. 2
0
        private void BuildNode(PureQuadTreeNode node)
        {
            float levelFalloff = falloff / node.Level;

            // first establish if visible or not by testing centre of node, then corners until visible
            bool visible = (node.Level == 0 || TestPoint(node.Centre) || TestPoint(node.Location) ||
                            TestPoint(new Vector2(node.Location.X + node.Size.X, node.Location.Y)) ||
                            TestPoint(new Vector2(node.Location.X, node.Location.Y + node.Size.Y)) ||
                            TestPoint(new Vector2(node.Location.X + node.Size.X, node.Location.Y + node.Size.Y)));

            // log what detail the leaf is to be, and if visible
            if (visible)
                leafDetail[node.Code] = (short)node.Level;
            else
                leafDetail[node.Code] = (short)-node.Level;

            if (visible)
            {
                // decide if to fork or not
                //Vector2 halfChildSize = node.Size * 0.25f;
                float distance = (node.Centre - viewPos).Length();
                // test this node first directly
                if (distance < levelFalloff)
                {
                    node.Fork(1, false);
                    for (int c = 0; c < 4; c++)
                    {
                        BuildNode(node.Children[c]);
                    }
                }
            }
            
            //else
            //{
            //    // test children directly
            //    for (int i = 0; i < 4; i++)
            //    {
            //        // check centre distance
            //        Vector2 centre = new Vector2();
            //        switch (i)
            //        {
            //            case 2:
            //                centre = new Vector2(node.Location.X + halfChildSize.X, node.Location.Y + halfChildSize.Y);
            //                break;
            //            case 3:
            //                centre = new Vector2(node.Location.X + (halfChildSize.X * 3), node.Location.Y + halfChildSize.Y);
            //                break;
            //            case 0:
            //                centre = new Vector2(node.Location.X + halfChildSize.X, node.Location.Y + (halfChildSize.Y * 3));
            //                break;
            //            case 1:
            //                centre = new Vector2(node.Location.X + (halfChildSize.X * 3), node.Location.Y + (halfChildSize.Y * 3));
            //                break;
            //        }
            //        float distance = (centre - viewPos).Length();
            //        if (distance < levelFalloff)
            //        {
            //            if (node.Children == null)
            //            {
            //                node.Fork(1, false);
            //                for (int c = 0; c < 4; c++)
            //                {
            //                    BuildNode(node.Children[c]);
            //                }
            //            }
            //        }
            //        else
            //        {
            //            // check visibility
            //            bool visible = false;

            //            //if (distance < falloff)
            //            //{
            //            float value = viewFOVpl1.Dot(new Vector3(node.Centre.X, 0, node.Centre.Y));
            //            if (value > 0)
            //            {
            //                //if (viewFOVpl2.Dot(new Vector3(node.Centre.X, 0, node.Centre.Y)) < 0)
            //                visible = true;
            //            }
            //            //}

            //            // log what detail the leaf is to be, and if visible
            //            if (visible)
            //                leafDetail[node.Code] = (short)node.Level;
            //            else
            //                leafDetail[node.Code] = (short)-node.Level;
            //        }
            //    }
            //}
        }