XNA碰撞检测
我有一个球在立方体内部移动,我检测它何时移出立方体(带有边界球体和边界框)。 现在我想检测球从哪一边出去。 然后我就可以将球重定向到正确的方向。 我怎样才能用球的“世界”矩阵做到这一点?
我应该自己跟踪球的坐标,还是应该从世界矩阵中推断出它们?
I have a ball moving inside a cube, and I detect when it goes outside of the cube (with a bounding sphere and a bounding box).
Now I would like to detect from which side the ball goes out. Then I could redirect the ball in the correct direction. How can I do this with the ball's “world” matrix?
Should I keep track of the ball's coordinates myself, or should I deduce them from the world matrix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会从碰撞开始。 您有六个平面(每个平面都有一个 [点,法线单位向量] 对)和一个球体(一个 [点,半径] 对)。
检查每个平面上的点。 为此,请从该点中减去按球体半径放大的平面单位向量。 (Point -= PlaneUnitVector * radius)
现在,通过一些向量数学,您可以看到它位于平面的哪一侧。
然后,您将使用平面的单位向量进行弹跳计算。
您将遇到的下一个问题是您一次穿过多个平面的情况。
I'd start over with the collisions. You have six planes (each a [point,normal unit vector] pair) and a sphere (a [point,radius] pair).
Check the point against each plane. To do this, subtract the unit vector, scaled up by the radius of the sphere, of the plane from the point. (Point -= PlaneUnitVector * radius)
Now, with some vector math, you can see which side of the plane it's on.
You'll then use the unit vector of the plane for the bounce calculation.
The next problem you'll run into is the case where you cross through more than one plane at a time.