{"id":203192,"date":"2013-11-22T10:51:03","date_gmt":"2013-11-22T06:51:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=203192"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=203192","title":{"rendered":"<span class=\"post_title\">\u0412\u0437\u0440\u044b\u0432\u044b \u0432 Box2D<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0438\u0434\u043e\u0432 \u0432\u0437\u0440\u044b\u0432\u043e\u0432 \u0432 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0434\u0432\u0438\u0436\u043a\u0435 Box2D.<br \/>  \u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0432\u0437\u0440\u044b\u0432\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044e \u0442\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0437\u0440\u044b\u0432\u043d\u043e\u0439 \u0432\u043e\u043b\u043d\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0438\u043b\u044b \u043a \u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430 \u0432\u0437\u0440\u044b\u0432\u0430.<\/p>\n<p>  \u041c\u044b \u0440\u0430\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u0432\u0437\u0440\u044b\u0432\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438:  <\/p>\n<ul>\n<li>\u041d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u043b \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u0432\u0437\u0440\u044b\u0432\u0430<\/li>\n<li>Raycast \u2013 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u043b \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u043b\u0443\u0447\u0435\u0439<\/li>\n<li>\u0427\u0430\u0441\u0442\u0438\u0446\u044b \u2013 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u0442\u0435\u043b \u043e\u0442 \u044d\u043f\u0438\u0446\u0435\u043d\u0442\u0440\u0430 \u0432\u0437\u0440\u044b\u0432\u0430<\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0447\u0430\u0441\u0442\u0438\u0446\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u043b\u0430 \u0438 \u043a\u0430\u043a-\u0442\u043e \u0432\u043e\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e: \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430 \u043d\u0430\u0441. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0446\u0435\u043d\u0443, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0432\u0438\u0434\u0430 \u0432\u0437\u0440\u044b\u0432\u043e\u0432:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/be2\/767\/a71\/be2767a71123e6a54d2f08dc908f1196.png\"\/><\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u0430<\/h4>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0432\u043d\u0438\u043a\u0430\u0442\u044c \u0432 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0441\u0438\u043b\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0442 \u0442\u043e\u0447\u043a\u0438 \u0432\u0437\u0440\u044b\u0432\u0430). \u0412\u0437\u0440\u044b\u0432 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043c \u0433\u0430\u0437\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043a\u0430 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u0432\u043e\u0437\u0434\u0443\u0445\u0430 \u043d\u0435 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0414\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0443 \u0440\u0430\u0434\u0438\u0443\u0441\u0430 \u043a \u0446\u0435\u043d\u0442\u0440\u0443 \u0432\u0437\u0440\u044b\u0432\u0430.<\/p>\n<p>  \u0412\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:  <\/p>\n<pre><code class=\"cpp\">void applyBlastImpulse(b2Body* body, b2Vec2 blastCenter, b2Vec2 applyPoint, float blastPower) {       b2Vec2 blastDir = applyPoint - blastCenter;       float distance = blastDir.Normalize();       \/\/ \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u0432\u0437\u0440\u044b\u0432\u0430       if ( distance == 0 )           return;        float invDistance = 1 \/ distance;       float impulseMag = blastPower * invDistance * invDistance;       body-&gt;ApplyLinearImpulse( impulseMag * blastDir, applyPoint ); } <\/code><\/pre>\n<h4>\u041d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u043b \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u0432\u0437\u0440\u044b\u0432\u0430<\/h4>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0440\u044b\u0432\u043e\u0432: \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0442\u0435\u043b\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0434\u0438\u0443\u0441\u0430 \u0432\u0437\u0440\u044b\u0432\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u0430. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f: \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0442\u0435\u043b\u0430 \u0441 \u0438\u0445\u043d\u0438\u043c\u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043c\u0430\u0441\u0441\u044b \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0432\u0437\u0440\u044b\u0432\u0430. \u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0432 Box2D \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <b>QueryAABB<\/b>:<\/p>\n<pre><code class=\"cpp\">MyQueryCallback queryCallback; b2AABB aabb; aabb.lowerBound = center - b2Vec2( blastRadius, blastRadius ); aabb.upperBound = center + b2Vec2( blastRadius, blastRadius ); m_world-&gt;QueryAABB( &queryCallback, aabb );    \/\/ \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u043b\u0430 \u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0446\u0435\u043d\u0442\u0440 \u043c\u0430\u0441\u0441 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u0434\u0438\u0443\u0441 \u0432\u0437\u0440\u044b\u0432\u0430 for (int i = 0; i &lt; queryCallback.foundBodies.size(); i++) {       b2Body* body = queryCallback.foundBodies[i];       b2Vec2 bodyCom = body-&gt;GetWorldCenter();              \/\/ignore bodies outside the blast range       if ( (bodyCom - center).Length() &gt;= m_blastRadius )           continue;                  applyBlastImpulse(body, center, bodyCom, blastPower ); } <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0440\u044b\u0432\u0430. \u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0442\u0435\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0438\u043c\u043f\u0443\u043b\u044c\u0441 \u043f\u043e\u0441\u043b\u0435 \u0432\u0437\u0440\u044b\u0432\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/292\/c98\/965\/292c989651606ec8b80724919f4476ce.png\"\/><\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u0421\u0430\u043c\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0437 \u043d\u0438\u0445: \u0432\u0437\u0440\u044b\u0432\u043d\u0430\u044f \u0432\u043e\u043b\u043d\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0438 \u0441\u0442\u0435\u043d\u044b. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0442\u0435\u043b\u043e \u0441\u043b\u0435\u0432\u0430 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435. \u041e\u043d\u043e \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u043e\u0434 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432\u0437\u0440\u044b\u0432\u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u0446\u0435\u043d\u0442\u0440 \u043c\u0430\u0441\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0435 \u0440\u0430\u0434\u0438\u0443\u0441\u0430 \u0432\u0437\u0440\u044b\u0432\u0430.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/f36\/4ea\/4f3\/f364ea4f30158909e2e8c0e40eda6a98.png\"\/><br \/>  \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e \u043e\u0431\u0435\u0438\u043c \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u043c \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430 \u0432\u0437\u0440\u044b\u0432\u0430 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u043c\u0430\u0441\u0441\u0443, \u043d\u043e \u0442\u0435\u043b\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0438\u043c\u043f\u0443\u043b\u044c\u0441 \u0432 4 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0442\u0435\u043b\u043e \u0441\u043b\u0435\u0432\u0430.<\/p>\n<h4>Raycast \u043c\u0435\u0442\u043e\u0434<\/h4>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043b\u0443\u0447\u0438 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u0435\u043b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0437\u0440\u044b\u0432\u043d\u0430\u044f \u0432\u043e\u043b\u043d\u0430. <\/p>\n<pre><code class=\"cpp\">for (int i = 0; i &lt; numRays; i++) {       float angle = (i \/ (float)numRays) * 360 * DEGTORAD;       b2Vec2 rayDir( sinf(angle), cosf(angle) );       b2Vec2 rayEnd = center + blastRadius * rayDir;          RayCastClosestCallback callback;       m_world-&gt;RayCast(&callback, center, rayEnd);       if ( callback.m_body )            applyBlastImpulse(callback.body, center, callback.point, (m_blastPower \/ (float)numRays)); } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u044b \u0434\u0435\u043b\u0438\u043c \u0441\u0438\u043b\u0443 \u0432\u0437\u0440\u044b\u0432\u0430 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u0443\u0447\u0435\u0439. \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u0447\u0435 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u0443\u0447\u0435\u0439 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0439 \u0441\u0438\u043b\u044b \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u0430 \u0432\u0437\u0440\u044b\u0432\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u0437\u0440\u044b\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c 32 \u043b\u0443\u0447\u0435\u0439:<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/2ad\/4fc\/d48\/2ad4fcd48b0d6774a5f2e8fddff51962.png\"\/><br \/>  \u0413\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435: \u0432\u0437\u0440\u044b\u0432\u043d\u0430\u044f \u0432\u043e\u043b\u043d\u0430 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u043e\u0436\u0435 \u0440\u0435\u0448\u0435\u043d\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u0430\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b:<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/96c\/1c3\/1e8\/96c1c31e851fb21937780d8812e5a016.png\"\/><br \/>  \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u0443\u0447\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0437\u0440\u044b\u0432 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0442\u0432\u0435\u0440\u0441\u0442\u0432\u0438\u044f.<\/p>\n<h4>\u041c\u0435\u0442\u043e\u0434 \u0447\u0430\u0441\u0442\u0438\u0446<\/h4>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0447\u0435\u043d\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445. \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u0435\u043b, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u0437\u043e\u043d\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0437\u0440\u044b\u0432\u0430, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u0442\u0435\u043b \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438\u0445 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u042d\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0437\u0440\u044b\u0432\u0430. <br \/>  \u042d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0434\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043d\u043e \u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043a\u043e\u0434, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0434\u0432\u0438\u0436\u043a\u043e\u043c. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432.<\/p>\n<pre><code class=\"cpp\">for (int i = 0; i &lt; numRays; i++) {       float angle = (i \/ (float)numRays) * 360 * DEGTORAD;       b2Vec2 rayDir( sinf(angle), cosf(angle) );          b2BodyDef bd;       bd.type = b2_dynamicBody;       bd.fixedRotation = true; \/\/ \u0412\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435       bd.bullet = true;       bd.linearDamping = 10;       bd.gravityScale = 0; \/\/ \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0432\u0438\u0442\u0430\u0446\u0438\u044e       bd.position = center; \/\/ \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u0432\u0437\u0440\u044b\u0432\u0430       bd.linearVelocity = blastPower * rayDir;       b2Body* body = m_world-&gt;CreateBody( &bd );          b2CircleShape circleShape;       circleShape.m_radius = 0.05; \/\/ \u041e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0440\u0430\u0434\u0438\u0443\u0441 \u0434\u043b\u044f \u0442\u0435\u043b\u0430          b2FixtureDef fd;       fd.shape = &circleShape;       fd.density = 60 \/ (float)numRays;       fd.friction = 0; \/\/ \u0422\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e       fd.restitution = 0.99f; \/\/ \u041e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0442 \u0442\u0435\u043b       fd.filter.groupIndex = -1; \/\/ \u0427\u0430\u0441\u0442\u0438\u0446\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c       body-&gt;CreateFixture( &fd ); } <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0435\u043b\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443. <br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/01a\/955\/fa2\/01a955fa25bde8555bdc27c681835111.gif\"\/><\/p>\n<p>  \u0412\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435 \u043f\u043b\u044e\u0441\u044b raycast-\u043c\u0435\u0442\u043e\u0434\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0432\u0437\u0440\u044b\u0432\u043d\u0430\u044f \u0432\u043e\u043b\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u0435\u043b, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u044d\u043d\u0435\u0440\u0433\u0438\u0438 \u0432\u0437\u0440\u044b\u0432\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0435\u0441 \u0447\u0430\u0441\u0442\u0438\u0446, \u0438\u0445 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435, \u0442\u0440\u0435\u043d\u0438\u0435 \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u043c\u0438\u0440\u0430 \u043e\u0442 \u0447\u0430\u0441\u0442\u0438\u0446 \u043f\u043e\u0441\u043b\u0435 \u0432\u0437\u0440\u044b\u0432\u0430. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430: \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 CPU. \u0414\u043b\u044f \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0437\u0440\u044b\u0432\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u043e \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043b\u0435\u0433\u043a\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0441 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439:<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/33e\/0ba\/c01\/33e0bac011c3f16e431b07f84106f0d3.png\"\/><\/p>\n<p>  \u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442: \u0441\u0438\u043b\u0430 \u0432\u0437\u0440\u044b\u0432\u0430 \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0432\u0441\u0435 \u0442\u0435\u043b\u0430. \u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u0438\u0446 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e8b\/0c9\/932\/e8b0c99324c7d74d9ca1fb00b5fa8445.png\"\/> \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/203192\/\"> http:\/\/habrahabr.ru\/post\/203192\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0438\u0434\u043e\u0432 \u0432\u0437\u0440\u044b\u0432\u043e\u0432 \u0432 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0434\u0432\u0438\u0436\u043a\u0435 Box2D.<br \/>  \u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0432\u0437\u0440\u044b\u0432\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044e \u0442\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0437\u0440\u044b\u0432\u043d\u043e\u0439 \u0432\u043e\u043b\u043d\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0438\u043b\u044b \u043a \u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430 \u0432\u0437\u0440\u044b\u0432\u0430.<\/p>\n<p>  \u041c\u044b \u0440\u0430\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u0432\u0437\u0440\u044b\u0432\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438:  <\/p>\n<ul>\n<li>\u041d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u043b \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u0432\u0437\u0440\u044b\u0432\u0430<\/li>\n<li>Raycast \u2013 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u043b \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u043b\u0443\u0447\u0435\u0439<\/li>\n<li>\u0427\u0430\u0441\u0442\u0438\u0446\u044b \u2013 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u0442\u0435\u043b \u043e\u0442 \u044d\u043f\u0438\u0446\u0435\u043d\u0442\u0440\u0430 \u0432\u0437\u0440\u044b\u0432\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-203192","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203192"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203192\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}