• <legend id='YPnJx'><style id='YPnJx'><dir id='YPnJx'><q id='YPnJx'></q></dir></style></legend>
    <tfoot id='YPnJx'></tfoot>
        <i id='YPnJx'><tr id='YPnJx'><dt id='YPnJx'><q id='YPnJx'><span id='YPnJx'><b id='YPnJx'><form id='YPnJx'><ins id='YPnJx'></ins><ul id='YPnJx'></ul><sub id='YPnJx'></sub></form><legend id='YPnJx'></legend><bdo id='YPnJx'><pre id='YPnJx'><center id='YPnJx'></center></pre></bdo></b><th id='YPnJx'></th></span></q></dt></tr></i><div id='YPnJx'><tfoot id='YPnJx'></tfoot><dl id='YPnJx'><fieldset id='YPnJx'></fieldset></dl></div>

        <small id='YPnJx'></small><noframes id='YPnJx'>

          <bdo id='YPnJx'></bdo><ul id='YPnJx'></ul>
      1. libgdx 中 BoundingBox 和 Sphere 之间的碰撞检测

        时间:2023-07-28

            <bdo id='CP8RC'></bdo><ul id='CP8RC'></ul>

              1. <tfoot id='CP8RC'></tfoot>
              2. <small id='CP8RC'></small><noframes id='CP8RC'>

                <i id='CP8RC'><tr id='CP8RC'><dt id='CP8RC'><q id='CP8RC'><span id='CP8RC'><b id='CP8RC'><form id='CP8RC'><ins id='CP8RC'></ins><ul id='CP8RC'></ul><sub id='CP8RC'></sub></form><legend id='CP8RC'></legend><bdo id='CP8RC'><pre id='CP8RC'><center id='CP8RC'></center></pre></bdo></b><th id='CP8RC'></th></span></q></dt></tr></i><div id='CP8RC'><tfoot id='CP8RC'></tfoot><dl id='CP8RC'><fieldset id='CP8RC'></fieldset></dl></div>
              3. <legend id='CP8RC'><style id='CP8RC'><dir id='CP8RC'><q id='CP8RC'></q></dir></style></legend>
                  <tbody id='CP8RC'></tbody>
                  本文介绍了libgdx 中 BoundingBox 和 Sphere 之间的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的 libgdx 游戏中,我有用于地图和玩家对象的 3D 边界框和球体.我想计算它们是否相互碰撞,以便正确模拟这些物体的运动.我可以使用什么方法来计算这些对象是否碰撞/相交?

                  In my libgdx game I have 3D BoundingBoxes and Spheres for map and player objects. I want to calculate whether they collide with each other in order to properly simulate the motion of these objects. What method can I use to calculate whether these objects collide/intersect?

                  推荐答案

                  可以使用以下方法:

                  public static boolean intersectsWith(BoundingBox boundingBox, Sphere sphere) {
                      float dmin = 0;
                  
                      Vector3 center = sphere.center;
                      Vector3 bmin = boundingBox.getMin();
                      Vector3 bmax = boundingBox.getMax();
                  
                      if (center.x < bmin.x) {
                          dmin += Math.pow(center.x - bmin.x, 2);
                      } else if (center.x > bmax.x) {
                          dmin += Math.pow(center.x - bmax.x, 2);
                      }
                  
                      if (center.y < bmin.y) {
                          dmin += Math.pow(center.y - bmin.y, 2);
                      } else if (center.y > bmax.y) {
                          dmin += Math.pow(center.y - bmax.y, 2);
                      }
                  
                      if (center.z < bmin.z) {
                          dmin += Math.pow(center.z - bmin.z, 2);
                      } else if (center.z > bmax.z) {
                          dmin += Math.pow(center.z - bmax.z, 2);
                      }
                  
                      return dmin <= Math.pow(sphere.radius, 2);
                  }
                  

                  仿照

                  Box-Sphere 相交测试的简单方法吉姆·阿尔沃摘自图形宝石",学术出版社,1990 年

                  A Simple Method for Box-Sphere Intersection Testing by Jim Arvo from "Graphics Gems", Academic Press, 1990

                  可在此处找到示例 C 代码:http://www.realtimerendering.com/resources/GraphicsGems/gems/BoxSphere.c

                  The sample C code for which can be found here: http://www.realtimerendering.com/resources/GraphicsGems/gems/BoxSphere.c

                  这篇关于libgdx 中 BoundingBox 和 Sphere 之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 box2d 在 libgdx 中拖动对象? 下一篇:使用 Leaflet.Draw.Circle 将 Java 更新到 1.8.0_301 JavaF

                  相关文章

                  最新文章

                  <tfoot id='tClJo'></tfoot>

                  <i id='tClJo'><tr id='tClJo'><dt id='tClJo'><q id='tClJo'><span id='tClJo'><b id='tClJo'><form id='tClJo'><ins id='tClJo'></ins><ul id='tClJo'></ul><sub id='tClJo'></sub></form><legend id='tClJo'></legend><bdo id='tClJo'><pre id='tClJo'><center id='tClJo'></center></pre></bdo></b><th id='tClJo'></th></span></q></dt></tr></i><div id='tClJo'><tfoot id='tClJo'></tfoot><dl id='tClJo'><fieldset id='tClJo'></fieldset></dl></div>
                  • <bdo id='tClJo'></bdo><ul id='tClJo'></ul>

                  1. <small id='tClJo'></small><noframes id='tClJo'>

                      <legend id='tClJo'><style id='tClJo'><dir id='tClJo'><q id='tClJo'></q></dir></style></legend>