zoukankan      html  css  js  c++  java
  • 几何检测 (四)

    两个AABB的相交性检测

          检测两个静止AABB的相交性是很简单的,只需要在每一维上单独检查它们的重合程度即可。如果在所有维上都没有重合,那么这两个AABB就不会相交。intersectAABBs()就是用这项技术来实现的。

    01 //---------------------------------------------------------------------------
    02 // Check if two AABBs intersect, and return true if so.  Optionally return
    03 // the AABB of their intersection if an intersection is detected.
    04 //---------------------------------------------------------------------------
    05 bool intersectAABBs(const AABB3& box1, const AABB3& box2, AABB3* boxIntersect)
    06 {
    07     // Check for no overlap
    08     if (box1.min.x > box2.max.x) return false;
    09     if (box1.max.x < box2.min.x) return false;
    10     if (box1.min.y > box2.max.y) return false;
    11     if (box1.max.y < box2.min.y) return false;
    12     if (box1.min.z > box2.max.z) return false;
    13     if (box1.max.z < box2.min.z) return false;
    14   
    15     // We have overlap.  Compute AABB of intersection, if they want it.
    16     if (boxIntersect != NULL)
    17     {
    18         boxIntersect->min.x = max(box1.min.x, box2.min.x);
    19         boxIntersect->max.x = min(box1.max.x, box2.max.x);
    20         boxIntersect->min.y = max(box1.min.y, box2.min.y);
    21         boxIntersect->max.y = min(box1.max.y, box2.max.y);
    22         boxIntersect->min.z = max(box1.min.z, box2.min.z);
    23         boxIntersect->max.z = min(box1.max.z, box2.max.z);
    24     }
    25   
    26     return true;
    27
  • 相关阅读:
    项目记录,仿今日头条app
    数组过滤后的重新排序问题
    用函数刷新页面内容比刷新页面要好
    html js绑定键盘按键触发事件(按回车键登陆)
    图片上传前压缩 lrz库
    微信 获取openid
    旅游项目总结
    UWP深入学习五: 传感器与搜索、共享及链接
    UWP深入学习四:动画及图像
    UWP深入学习三:依赖属性、附加属性和数据绑定
  • 原文地址:https://www.cnblogs.com/jiahuafu/p/1958471.html
Copyright © 2011-2022 走看看