{"id":6369,"date":"2024-08-10T18:01:01","date_gmt":"2024-08-10T10:01:01","guid":{"rendered":""},"modified":"2024-08-10T18:01:01","modified_gmt":"2024-08-10T10:01:01","slug":"\u5305\u56f4\u4f53\u7684\u662f\u4ec0\u4e48_\u6b63\u5782\u9762\u4e0e\u5706\u7403\u4f53\u8868\u9762\u76f8\u4ea4","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6369.html","title":{"rendered":"\u5305\u56f4\u4f53\u7684\u662f\u4ec0\u4e48_\u6b63\u5782\u9762\u4e0e\u5706\u7403\u4f53\u8868\u9762\u76f8\u4ea4"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u5305\u56f4\u4f53\u662f\u5565\uff1f<\/strong>
\u6211\u4eec\u76f4\u89c2\u89c9\u5f97\u78b0\u649e\u5f80\u5f80\u662f\u4e24\u4e2a\u591a\u8fb9\u5f62\u76f8\u4ea4\uff0c\u4f46\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u8fd9\u4e48\u7b97\u662f\u5f88\u590d\u6742\u7684\uff0c\u7279\u522b\u662f\u8fb9\u5f88\u591a\u7684\u7269\u4f53\u65f6
\u4e3a\u4e86\u51cf\u5c11\u8ba1\u7b97\uff0c\u5c31\u9700\u8981\u628a\u51e0\u4f55\u4f53\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u4f53\u7a7a\u95f4\u5305\u56f4\u8d77\u6765\uff08\u7b80\u5355\u4f53\u662f\u6307\uff1a\u957f\u65b9\u4f53\u3001\u7403\u4f53\uff09
PS\uff1a\u5305\u56f4\u4f53\u7684\u82f1\u6587\u540d\u53eb\uff1aBV<\/p>\n

\u5982\u56fe\u6240\u793a\uff1a\uff08\u6765\u81ea\u767e\u5ea6\u56fe\u7247\uff09
\"\u5305\u56f4\u4f53\u7684\u662f\u4ec0\u4e48_\u6b63\u5782\u9762\u4e0e\u5706\u7403\u4f53\u8868\u9762\u76f8\u4ea4
\u6ce8\u610f\uff1a\u5305\u56f4\u4f53\u5177\u6709\u4f4e\u6d88\u8017\u7684\u76f8\u4ea4\u6d4b\u8bd5\u7684\u597d\u5904\u540c\u65f6\uff0c\u4e5f\u4f1a\u5360\u7528\u989d\u5916\u7684\u5185\u5b58\uff08\u9700\u8981\u5b58\u50a8\u5305\u56f4\u7684\u6570\u636e\uff09\uff0c\u4e0d\u8fc7\u5f71\u54cd\u4e0d\u5927<\/p>\n


\n

\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c\u4e00\u822c\u90fd\u4f1a\u5bf9\u5176\u8fdb\u884c\u7b80\u5316<\/p>\n

Unity\u91cc\u9762\u4e5f\u63d0\u4f9b\u4e86\u96c6\u4e2d\u5305\u56f4\u4f53\u7684Collider\uff0c\u6bd4\u5982BoxCollider\u3001ShpereCollider\u7b49\uff0c\u540c\u65f6\u5b98\u65b9\u4e5f\u5e76\u4e0d\u63a8\u8350\u4f60\u4f7f\u7528MeshCollider<\/p>\n

\u90a3\u4e48\u8be6\u7ec6\u8bf4\u4e00\u4e0b\u5404\u79cd\u5305\u56f4\u4f53\uff0c\u5982\u56fe\u6240\u793a\uff1a
\"\u5305\u56f4\u4f53\u7684\u662f\u4ec0\u4e48_\u6b63\u5782\u9762\u4e0e\u5706\u7403\u4f53\u8868\u9762\u76f8\u4ea4
1.\u7403\u4f53<\/strong>
\u7403\u4f53\u662f\u4e00\u79cd\u5f88\u5e38\u89c1\u7684\u5305\u56f4\u4f53\uff0c\u53ea\u9700\u8981\u5b58\u50a8\u5706\u5fc3\u70b9\u4ee5\u53ca\u534a\u5f84
\u6570\u636e\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n

public<\/span> struct<\/span> Sphere<\/span> { \n   <\/span> public<\/span> FPVector2<\/span> center;<\/span> \/\/\u5706\u5fc3<\/span> public<\/span> FP<\/span> radius;<\/span> \/\/\u534a\u5f84<\/span> }<\/span> <\/code><\/pre>\n

\u5176\u4f18\u70b9\u5c31\u662f\u8ba1\u7b97\u76f8\u4ea4\u901f\u5ea6\u975e\u5e38\u4e4b\u5feb\uff0c\u4e5f\u4e0d\u4f1a\u53d7\u5230\u65cb\u8f6c\u53d8\u6362\u7684\u5f71\u54cd
\u76f8\u4ea4\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n

\/\/\u5706\u5fc3\u8ddd\u79bb\u662f\u5426\u5c0f\u4e8e\u4e24\u8005\u534a\u5f84\u4e4b\u548c<\/span> public<\/span> static<\/span> bool<\/span><\/span> TestSphereSphere<\/span>(<\/span>Sphere<\/span> a,<\/span> Sphere<\/span> b)<\/span> { \n   <\/span> FPVector2<\/span> d =<\/span> a.<\/span>center -<\/span> b.<\/span>center;<\/span> FP<\/span> dist =<\/span> FPVector2.<\/span>Dot<\/span>(<\/span>d,<\/span> d)<\/span>;<\/span> FP<\/span> radiusSum =<\/span> a.<\/span>radius +<\/span> b.<\/span>radius;<\/span> return<\/span> dist <=<\/span> radiusSum *<\/span> radiusSum;<\/span> }<\/span> <\/code><\/pre>\n

\u5305\u56f4\u76d2\u5982\u4f55\u8ba1\u7b97\u5462\uff1f<\/strong>
\u7b80\u5355\u53ef\u4ee5\u901a\u8fc7\u6240\u6709\u9876\u70b9\u7684AABB\u83b7\u53d6\u4e00\u4e2a\u903c\u8fd1\u7684\u5305\u56f4\u7403\uff0c\u5c06AABB\u7684\u4e2d\u5fc3\u70b9\u4f5c\u4e3a\u7403\u5fc3\uff0c\u7403\u4f53\u7684\u534a\u5f84\u662f\u8ba1\u7b97\u6700\u8fdc\u9876\u70b9\u4e0e\u5706\u5fc3\u7684\u8ddd\u79bb
\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5e76\u4e0d\u597d\uff0c\u53ef\u80fd\u8ba1\u7b97\u51fa\u7684\u4e2d\u5fc3\u548c\u5b9e\u9645\u4e2d\u5fc3\u76f8\u5dee\u751a\u8fdc\uff0c\u6240\u4ee5\u8fd8\u6709\u4e00\u79cd\u4f18\u5316\u65b9\u6cd5\uff0c\u5f00\u59cb\u65f6\u5c31\u8ba1\u7b97\u4e00\u4e2a\u8fd1\u4f3c\u5b8c\u6574\u7684\u5305\u56f4\u7403\uff0c\u7136\u540e\u901a\u8fc7\u540e\u7eed\u6b65\u9aa4\u5b8c\u5584\u8be5\u7403\u4f53\uff0c\u76f4\u81f3\u5305\u56f4\u5168\u90e8\u5b9a\u70b9<\/p>\n


\n

\u4f46\u662f\u90fd\u6d89\u53ca\u5230AABB\uff08\u8f74\u5bf9\u9f50\u5305\u56f4\u76d2\uff09\u7684\u8ba1\u7b97\uff0c\u6240\u4ee5\u5148\u8bf4\u4e00\u4e0b\u5b83<\/strong>
\u8f74\u5bf9\u9f50\u5305\u56f4\u76d2\u662f\u5e94\u7528\u6700\u6700\u6700\u5e7f\u6cdb\u7684\u5305\u56f4\u4f53\uff0c\u5176\u7279\u70b9\u5c31\u662f\uff1a\u9762\u6cd5\u7ebf\u90fd\u5e73\u884c\u4e8e\u7ed9\u5b9a\u5750\u6807\u8f74
\u8fd9\u6837\u5c31\u53ef\u4ee5\u5feb\u901f\u7684\u8fdb\u884c\u76f8\u4ea4\u6d4b\u8bd5\uff0c\u53ea\u9700\u6bd4\u8f83\u5750\u6807\u503c<\/strong>\u5c31\u53ef\u4ee5\u4e86
AABB\u7684\u6570\u636e\u5b9a\u4e49\u6709\u597d\u51e0\u79cd\u8868\u8fbe\u65b9\u5f0f\uff0c\u5206\u522b\u662f<\/p>\n

public<\/span> struct<\/span> AABB1<\/span> { \n   <\/span> public<\/span> FPVector3<\/span> min;<\/span> \/\/\u5de6\u4e0b\u89d2\u7684\u5750\u6807<\/span> public<\/span> FPVector3<\/span> max;<\/span> \/\/\u53f3\u4e0a\u89d2\u5750\u6807<\/span> }<\/span> public<\/span> struct<\/span> AABB2<\/span> { \n   <\/span> public<\/span> FPVector3<\/span> min;<\/span> \/\/\u5de6\u4e0b\u89d2<\/span> public<\/span> FP[<\/span>]<\/span><\/span> distance;<\/span> \/\/\u4e09\u4e2a\u8fb9\u7684\u957f\u5ea6<\/span> }<\/span> public<\/span> struct<\/span> AABB3<\/span> { \n   <\/span> public<\/span> FPVector3<\/span> center;<\/span> \/\/\u4e2d\u5fc3\u70b9<\/span> public<\/span> FP[<\/span>]<\/span><\/span> radius;<\/span> \/\/\u4e09\u4e2a\u8fb9\u7684\u957f\u5ea6\u7684\u4e00\u534a<\/span> }<\/span> <\/code><\/pre>\n

\u5177\u4f53\u4f7f\u7528\u54ea\u79cd\u65b9\u5f0f\uff0c\u770b\u81ea\u5df1\u7684\u9700\u6c42
1.\u5982\u679c\u4ece\u5b58\u50a8\u89d2\u5ea6\u8003\u8651\uff0c\u80af\u5b9a\u662fAABB2\u6216\u8005AABB3\uff08\u5dee\u4e0d\u591a\uff0c3\u66f4\u5c0f\u70b9\uff09
2.\u5982\u679c\u7269\u4f53\u7684\u8fd0\u52a8\u65b9\u5f0f\u53ea\u6709\u5e73\u79fb\uff0c\u5219\u4f7f\u7528AABB2\u6216\u8005AABB3\u66f4\u4e3a\u65b9\u4fbf\uff08\u53ea\u9700\u66f4\u65b0\u4e00\u4e2a\u5750\u6807\uff09
3.\u5982\u679c\u8fd8\u9700\u8981\u5f53\u505a\u4e00\u4e2a\u5305\u56f4\u7403\u68c0\u6d4b\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528AABB3\uff0c\u65b9\u4fbf\u53d6\u534a\u5f84<\/p>\n

AABB\u7684\u76f8\u4ea4\u6d4b\u8bd5\u600e\u4e48\u505a\u5462\uff1f<\/strong>
\u5982\u679cAABB\u5728\u4e09\u4e2a\u8f74\u4e0a\u90fd\u76f8\u4ea4\uff0c\u5219AABB\u76f8\u4ea4
\u5728\u8fd9\u91cc\u4ee5AABB1\u4e3e\u4f8b\u5b50\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

public<\/span> static<\/span> bool<\/span><\/span> TestAABBAABB<\/span>(<\/span>AABB1<\/span> a,<\/span> AABB1<\/span> b)<\/span> { \n   <\/span> if<\/span> (<\/span>a.<\/span>max.<\/span>x <<\/span> b.<\/span>min.<\/span>x ||<\/span> a.<\/span>min.<\/span>x ><\/span> b.<\/span>max.<\/span>x)<\/span> return<\/span> false<\/span>;<\/span> if<\/span> (<\/span>a.<\/span>max.<\/span>y <<\/span> b.<\/span>min.<\/span>y ||<\/span> a.<\/span>min.<\/span>y ><\/span> b.<\/span>max.<\/span>y)<\/span> return<\/span> false<\/span>;<\/span> if<\/span> (<\/span>a.<\/span>max.<\/span>z <<\/span> b.<\/span>min.<\/span>z ||<\/span> a.<\/span>min.<\/span>z ><\/span> b.<\/span>max.<\/span>z)<\/span> return<\/span> false<\/span>;<\/span> return<\/span> true<\/span>;<\/span> }<\/span> <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u5305\u56f4\u4f53\u7684\u662f\u4ec0\u4e48_\u6b63\u5782\u9762\u4e0e\u5706\u7403\u4f53\u8868\u9762\u76f8\u4ea4\u5305\u56f4\u4f53\u662f\u5565\uff1f\u6211\u4eec\u76f4\u89c2\u89c9\u5f97\u78b0\u649e\u5f80\u5f80\u662f\u4e24\u4e2a\u591a\u8fb9\u5f62\u76f8\u4ea4\uff0c\u4f46\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u8fd9\u4e48\u7b97\u662f\u5f88\u590d\u6742\u7684...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6369"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6369"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6369\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}