C#简单3D碰撞检测
我正在尝试开发一个简单的 3d 环境(在 openTK 中,所以基本上是 openGL)并实现简单的碰撞检测。我将拥有一个相机对象,该对象将具有一个边界立方体和一个充满三角形和四边形的世界。
如果给我一个边界立方体(或者边界球体,如果更容易的话)和一个多边形列表,是否有一种快速而肮脏的方法来进行基本的碰撞检测?
感谢您的帮助
I'm trying to develop a simple 3d environment (in openTK, so basically openGL) and implement simple collision detection. I will have the camera object which will have a bounding cube and a world full of triangles and quads.
If I'm given a bounding cube (or bounding sphere if that's easier) and a list of polygons, is there a quick and dirty way to do basic collision detection?
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,对于简单的边界框碰撞,我编写了以下方法,该方法将接受
BoundingBox
对象并确定它是否位于BoundingBox
的当前实例内。边界框由作为边界框中心的
Point3D
对象(与Point
类相同,但具有 Z 坐标)以及高度、宽度和高度组成。盒子的深度。使用这 4 个对象,它计算框的左(最小 X)、右(最大 X)、底部(最小 Y)、顶部(最大 Y)、前(最小 Z)和后(最大 Z)(该框是轴对齐。这是简单的碰撞)。这是检测一个盒子是否在另一个盒子内的方法,如果是,则修改该盒子以将其移到外面。您可以通过执行以下操作来调用它:
meshData.Box.Intersection(ref camera.box);
其中meshData
是场景和相机中的某种几何体 是当前用户视角的对象。希望这对其他人有用!
Ok, for simple bounding box collision, I wrote the following method that will accept a
BoundingBox
object and determine if it is inside the the current instance of aBoundingBox
.A bounding box consists of the a
Point3D
object (same as thePoint
class but with a Z coordinate) for the center of the bounding box, and the height, width, and depth of the box. With those 4 objects, it calculates the Left (min X), Right (max X), Bottom (min Y), Top (max Y), Front (min Z) and Back (max Z) of the box (The box is axis aligned. This is simple collision). Here is the method to detect if one box is within the other, and if so, modifiy the box to move it outside.You call it by doing something like:
meshData.Box.Intersection(ref camera.box);
wheremeshData
is some kind of geometry in the scene and thecamera
is the object for the current user's perspective.Hope this is useful for someone else!