public static Dictionary <int, QNode> BuildQNodeMap(CMap _map, Dictionary <int, CAnimationObject> _listObject) { Dictionary <int, QNode> mapNode = new Dictionary <int, QNode>(); foreach (KeyValuePair <int, CNode> pair in _map.Map) { QNode node = null; List <CAnimationObject> list = new List <CAnimationObject>(); Rectangle _bound = new Rectangle(pair.Value.X, pair.Value.Y, pair.Value.Width, pair.Value.Height); node = new QNode(pair.Key, _bound); for (int i = 0; i < pair.Value.ListObject.Count; ++i) { foreach (KeyValuePair <int, CAnimationObject> o in _listObject) { if (pair.Value.ListObject[i].ID == o.Key) { list.Add(o.Value); } } } node.InsertObjects(list); mapNode.Add(pair.Key, node); } return(mapNode); }
public static QuadTree BuildQuadTree(Dictionary <int, QNode> mapNode) { QNode root = null; QNode q = null; var first = mapNode.First(); root = first.Value; QuadTree quadTree; foreach (KeyValuePair <int, QNode> pair in mapNode) { if (pair.Key != 1) { int parentID = pair.Value.GetParentID(); foreach (KeyValuePair <int, QNode> pair2 in mapNode) { if (pair2.Key == parentID) { q = pair2.Value; break; } } q.AddChildNode(pair.Value); } } quadTree = new QuadTree(root); return(quadTree); }
public void AddChildNode(QNode _node) { int num = _node.ID % 8; switch (num) { case 1: m_tl = _node; break; case 2: m_tr = _node; break; case 3: m_bl = _node; break; case 4: m_br = _node; break; default: break; } }
public static Dictionary<int, QNode> BuildQNodeMap(CMap _map, Dictionary<int, CAnimationObject> _listObject) { Dictionary<int, QNode> mapNode = new Dictionary<int, QNode>(); foreach (KeyValuePair<int, CNode> pair in _map.Map) { QNode node = null; List<CAnimationObject> list = new List<CAnimationObject>(); Rectangle _bound = new Rectangle(pair.Value.X, pair.Value.Y, pair.Value.Width, pair.Value.Height); node = new QNode(pair.Key, _bound); for (int i = 0; i < pair.Value.ListObject.Count; ++i) { foreach (KeyValuePair<int, CAnimationObject> o in _listObject) { if (pair.Value.ListObject[i].ID == o.Key) { list.Add(o.Value); } } } node.InsertObjects(list); mapNode.Add(pair.Key, node); } return mapNode; }
public QNode(int _ID, Rectangle _Bound) { m_tl = null; m_tr = null; m_bl = null; m_br = null; m_ID = _ID; m_Bound = _Bound; }
public void InsertListObjectView(Rectangle viewport, QNode node) { int i = 0; int j = 0; if (m_RootNode == node) { if (m_ListObjectsInView.Count > 0) { m_ListObjectsInView.Clear(); } } if (node.GetChildNode(1) == null) // NẾU TRỞ THÀNH NODE LÁ { if (node.Bound.Intersects(viewport)) // VA CHẠM VỚI NODE { for (i = 0; i < node.GetListObjects().Count; ++i) { for (j = 0; j < m_RootNode.GetListObjects().Count; ++j) { if (node.GetListObjects()[i] == m_RootNode.GetListObjects()[j]) { break; } } if (j == m_RootNode.GetListObjects().Count) { m_ListObjectsInView.Add(node.GetListObjects()[i]); } } } } else { if (node.GetChildNode(1).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(1)); } if (node.GetChildNode(2).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(2)); } if (node.GetChildNode(3).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(3)); } if (node.GetChildNode(4).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(4)); } } }
public void InsertListObjectView(Rectangle viewport, QNode node) { int i = 0; int j = 0; if (m_RootNode == node) { if (m_ListObjectsInView.Count > 0) m_ListObjectsInView.Clear(); } if (node.GetChildNode(1) == null) // NẾU TRỞ THÀNH NODE LÁ { if (node.Bound.Intersects(viewport)) // VA CHẠM VỚI NODE { for (i = 0; i < node.GetListObjects().Count; ++i) { for (j = 0; j < m_RootNode.GetListObjects().Count; ++j) { if (node.GetListObjects()[i] == m_RootNode.GetListObjects()[j]) break; } if (j == m_RootNode.GetListObjects().Count) { m_ListObjectsInView.Add(node.GetListObjects()[i]); } } } } else { if (node.GetChildNode(1).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(1)); } if (node.GetChildNode(2).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(2)); } if (node.GetChildNode(3).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(3)); } if (node.GetChildNode(4).Bound.Intersects(viewport)) { InsertListObjectView(viewport, node.GetChildNode(4)); } } }
public void RemoveObject(CAnimationObject _object, QNode _node) { if (_node.GetChildNode(1) == null) { _node.RemoveObject(_object); } else { RemoveObject(_object, _node.GetChildNode(1)); RemoveObject(_object, _node.GetChildNode(2)); RemoveObject(_object, _node.GetChildNode(3)); RemoveObject(_object, _node.GetChildNode(4)); } }
public QuadTree(QNode _root) { m_RootNode = _root; }
public QuadTree() { m_RootNode = null; }