怎样做碰撞检测的最佳方式? [英] What's the best way to do collision detection?

查看:292
本文介绍了怎样做碰撞检测的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必要界定这将是合法的区域多边形,并允许用户周围的多边形,$ P $内pventing他们从任何地方移动矩形,其中分点创业多边形外移动矩形。

I have a need to define a polygon that would be the "legal" area, and allow a user to move a rectangle around within that polygon, preventing them from moving the rectangle anywhere where its points venture outside the polygon.

多边形是一个固定的形状,所以,我想这可能是最简单的导入形状的PNG,并以这种方式拉分,不知何故?但我仍处于亏损状态,以参与检查矩形的坐标作为用户拖动它,以及在什么时候,他们搬到了形状的边界多边形的边测试数学。

The polygon is a fixed shape, so, I was thinking it may be easiest to import a PNG of that shape and pull the points in that way, somehow? But I'm still at a loss as to the math involved in checking the coordinates of the rectangle as the user drags it, and testing at what point they have moved the shape to the edge of the bounding polygon.

不幸的是,边界多边形是一个相当复杂的形状。我希望有人能够在一个教程点我认为显示了运行这样一个碰撞检测的最好办法就是。

Unfortunately the bounding polygon is a fairly complex shape. I'm hoping someone can point me at a tutorial that shows what the best way to run such a collision detection is.

推荐答案

METANET的出色的碰撞检测教程对如何做轴对齐包围盒(AABB)和任意碰撞席卷了良好的部分墙。

Metanet's excellent collision detection tutorial has a good section on how to do swept collision with axis-aligned bounding boxes (AABB) and arbitrary "walls."

如果您的多边形是凹的,你可能会发现它最容易分解首先为多个凸多边形,这将简化现有的碰撞检测算法。

If your polygon is concave, you'll probably find it easiest to first decompose it into multiple convex polygons, which will simplify the available collision detection algorithms.

这篇关于怎样做碰撞检测的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆