- 积分
- 890
- 明经币
- 个
- 注册时间
- 2013-7-19
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2023-7-11 22:01:58
|
显示全部楼层
- // 搜索指定宽、高内的节点(点的x y值 宽w 高h)
- void Search(const nodeType* n, COOR_TYPE x, COOR_TYPE y, COOR_TYPE w, COOR_TYPE h, std::vector<const nodeType*>& result) const
- {
- if (n != NULL)
- {
- if (n->leaf)
- {
- acutPrintf(_T("n->leaf true"));
- // 判断两个矩形是否相交
- if (Intersect(n->x, n->y, n->w, n->h, x, y, w, h))
- {
- acutPrintf(_T(" push_back "));
- result.push_back(n);
- }
- }
- else if (Intersect(n, x, y, w, h) && n->node_size > 0)
- {
- acutPrintf(_T("n->leaf false"));
- for (int i = 0; i < 4; i++)
- {
- if (n->child[i])
- {
- Search(n->child[i], x, y, w, h, result);
- acutPrintf(_T("n->node Search "));
- }
- }
- }
- }
- }
复制代码
这段矩形碰撞的原理是什么???为什么判断两个矩形碰撞,先要判断一个矩形和另一个的nodeType,也就是另一个矩形所在的节点是否碰撞???我测试的例子大部分都是检查出来了,就有一个怎么都不对,这个没检查出来的就是我说的这种,一个矩形和节点没碰撞,但是和这个节点里的一个child是碰撞的,不知道我这么理解对不对,这导致循序直接跳过这个nodeType,他的四个child也被跳过了,想完善完善还是能力不足,问题先放着,先谢谢g大,确实牛b |
|