コード例 #1
0
        public void InsertObject(CNode node, OBJECT obj)
        {
            RECTANGLE rect = RECTANGLE.Intersec(node.m_bound, obj.RangeOfMovement);

            if (rect.cX == 0 && rect.cY == 0 && rect.width == 0 && rect.height == 0)
            {
                return;
            }

            if (node.m_bound.width >= (MAX_HEIGHT_SIZE_OF_NODE + 10) && node.m_bound.height > (MAX_HEIGHT_SIZE_OF_NODE + 10))
            {
                if (node.m_tl == null)
                {
                    node.m_tl = new CNode(node.m_id, PositionOfNode.TopLeft, node.Bound);
                    node.m_tr = new CNode(node.m_id, PositionOfNode.TopRight, node.Bound);
                    node.m_bl = new CNode(node.m_id, PositionOfNode.BottomLeft, node.Bound);
                    node.m_br = new CNode(node.m_id, PositionOfNode.BottomRight, node.Bound);
                }

                node.InsertObject(node.m_tl, obj);
                node.InsertObject(node.m_tr, obj);
                node.InsertObject(node.m_bl, obj);
                node.InsertObject(node.m_br, obj);
            }
            else
            {
                node.m_listObject.Add(obj);
            }

            return;
        }
コード例 #2
0
ファイル: CNode.cs プロジェクト: tavietanh/ninja-gaiden
        public void InsertObject(CNode node, OBJECT obj)
        {
            RECTANGLE rect = RECTANGLE.Intersec(node.m_bound, obj.RangeOfMovement);

            if (rect.cX == 0 && rect.cY == 0 && rect.width == 0 && rect.height == 0)
            {
                return;
            }
            node.m_listObject.Add(obj);

            return;
        }
コード例 #3
0
ファイル: CNode.cs プロジェクト: tavietanh/ninja-gaiden
        public CNode(int ID, RECTANGLE Bound)
        {
            // if node is root
            this.m_id = ID;

            this.m_next = null;

            this.m_listObject = new List <OBJECT>();
            if (ID == 0)
            {
                this.m_bound = Bound;
            }
            else
            {
                this.m_bound = new RECTANGLE(Bound.cX, Bound.cY, Support.SIZE_CELLS_WIDTH, Support.SIZE_CELLS_HEIGHT);
            }
        }
コード例 #4
0
        public CNode(int parentID, PositionOfNode positionOfNode, RECTANGLE parentBound)
        {
            // if node is root
            this.m_id = parentID * 10 + (int)positionOfNode;

            this.m_tl = null;
            this.m_tr = null;
            this.m_bl = null;
            this.m_br = null;

            this.m_listObject = new List<OBJECT>();

            if (parentID == 0)
            {
                this.m_bound = parentBound;
            }
            else
            {
                if (positionOfNode == PositionOfNode.TopLeft)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX, parentBound.cY, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.TopRight)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX + parentBound.width / 2, parentBound.cY, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.BottomLeft)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX, parentBound.cY - parentBound.height / 2, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.BottomRight)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX + parentBound.width / 2, parentBound.cY - parentBound.height / 2, parentBound.width / 2, parentBound.height / 2);
                }
            }
        }
コード例 #5
0
        public CNode(int parentID, PositionOfNode positionOfNode, RECTANGLE parentBound)
        {
            // if node is root
            this.m_id = parentID * 10 + (int)positionOfNode;

            this.m_tl = null;
            this.m_tr = null;
            this.m_bl = null;
            this.m_br = null;

            this.m_listObject = new List <OBJECT>();

            if (parentID == 0)
            {
                this.m_bound = parentBound;
            }
            else
            {
                if (positionOfNode == PositionOfNode.TopLeft)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX, parentBound.cY, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.TopRight)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX + parentBound.width / 2, parentBound.cY, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.BottomLeft)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX, parentBound.cY - parentBound.height / 2, parentBound.width / 2, parentBound.height / 2);
                }
                else if (positionOfNode == PositionOfNode.BottomRight)
                {
                    this.m_bound = new RECTANGLE(parentBound.cX + parentBound.width / 2, parentBound.cY - parentBound.height / 2, parentBound.width / 2, parentBound.height / 2);
                }
            }
        }
コード例 #6
0
        public void writeQuadtreeToXml(CNode quadTree, XmlWriter writer)
        {
            if (quadTree != null)
            {
                mWriter.WriteStartElement("Node");
                mWriter.WriteAttributeString("Id", Convert.ToString(quadTree.ID));
                mWriter.WriteAttributeString("X", Convert.ToString(quadTree.Bound.cX));
                mWriter.WriteAttributeString("Y", Convert.ToString(quadTree.Bound.cY));
                mWriter.WriteAttributeString("Width", Convert.ToString(quadTree.Bound.width));
                mWriter.WriteAttributeString("Height", Convert.ToString(quadTree.Bound.height));

                if (quadTree.ListObject.Count == 0)
                {
                    writeQuadtreeToXml(quadTree.Tl, mWriter);
                    writeQuadtreeToXml(quadTree.Tr, mWriter);
                    writeQuadtreeToXml(quadTree.Bl, mWriter);
                    writeQuadtreeToXml(quadTree.Br, mWriter);
                }
                else
                {
                    mWriter.WriteStartElement("Objects");
                    for (int i = 0; i < quadTree.ListObject.Count; ++i)
                    {
                        mWriter.WriteStartElement("Object");
                        mWriter.WriteAttributeString("Type", Convert.ToString(quadTree.ListObject[i].Type));
                        mWriter.WriteAttributeString("Id", Convert.ToString(quadTree.ListObject[i].ID));
                        mWriter.WriteAttributeString("Index", Convert.ToString(quadTree.ListObject[i].Index));
                        mWriter.WriteAttributeString("X", Convert.ToString(quadTree.ListObject[i].Position.cX));
                        mWriter.WriteAttributeString("Y", Convert.ToString(quadTree.ListObject[i].Position.cY));
                        mWriter.WriteAttributeString("Width", Convert.ToString(quadTree.ListObject[i].Bound.width));
                        mWriter.WriteAttributeString("Height", Convert.ToString(quadTree.ListObject[i].Bound.height));

                        mWriter.WriteEndElement();
                    }
                    mWriter.WriteEndElement();
                }

                mWriter.WriteEndElement();
            }
        }
コード例 #7
0
        public void InsertObject(CNode node, OBJECT obj)
        {
            RECTANGLE rect = RECTANGLE.Intersec(node.m_bound, obj.RangeOfMovement);

            if (rect.cX == 0 && rect.cY == 0 && rect.width == 0 && rect.height == 0)
            {
                return ;
            }

            if (node.m_bound.width >= (MAX_HEIGHT_SIZE_OF_NODE + 10) && node.m_bound.height > (MAX_HEIGHT_SIZE_OF_NODE + 10))
            {
                if (node.m_tl == null)
                {
                    node.m_tl = new CNode(node.m_id, PositionOfNode.TopLeft, node.Bound);
                    node.m_tr = new CNode(node.m_id, PositionOfNode.TopRight, node.Bound);
                    node.m_bl = new CNode(node.m_id, PositionOfNode.BottomLeft, node.Bound);
                    node.m_br = new CNode(node.m_id, PositionOfNode.BottomRight, node.Bound);
                }

                node.InsertObject(node.m_tl, obj);
                node.InsertObject(node.m_tr, obj);
                node.InsertObject(node.m_bl, obj);
                node.InsertObject(node.m_br, obj);
            }
            else
            {
                node.m_listObject.Add(obj);
            }

            return;
        }