矩形碰撞检测 SDL 2.0
rectangle colision detection SDL 2.0
我在矩形碰撞方面遇到了问题,这是算法:
我检测 r1(renctangle 1) 是否高于 r2(矩形 2):
int BottomA = A.x+A.h;
int TopB = B.x;
if(TopB>BottomA)
{
Gravity();
}
但是相互重叠,我已经测试了在 60 种情况下限制一秒钟内或不受时间限制的 2 次重叠(10 或 15 像素,有时更少)。 重叠打破了横向碰撞的密码。
首先,碰撞检测与 SDL 无关。SDL 只显示内容。
您似乎正在使用轴对齐的框。轴对齐框的碰撞检测是最简单的条件。您只需在两个轴上检查它们(如果您在 3D 中工作,则在三个轴上检查它们)。如果任何轴不重叠,则两个框不重叠。
bool axis_check(int a_min, int a_max, int b_min, int b_max)
{
if (a_max<b_min || b_max<a_min) return false;
else return true;
}
bool box_collision(int a_x_min, int a_x_max, int a_y_min, int a_y_max,
int b_x_min, int b_x_max, int b_y_min, int b_y_max)
{
if (axis_check(a_x_min, a_x_max, b_x_min, b_x_max)
&& axis_check(a_y_min, a_y_max, b_y_min, b_y_max))
return true;
else
return false;
}
如果场景中有如此多的对象,则可以使用空间细分方法。有许多空间细分方法,例如递归划分为两个子空间,递归划分为八个子空间或网格。
相关文章:
- 落砂模拟碰撞检测C++和SFML
- SFML 中的重力和碰撞检测
- 我的碰撞检测中的奇怪行为
- 如何为球形物体和三角形地形提供高效的碰撞检测和响应
- 圆形与方形碰撞检测以及需要响应C++ |OpenGL。我的问题就是这个"I need to keep the circle outside the square"
- 在Qt3D中进行碰撞检测的预期方法(或好方法)是什么?
- 在碰撞检测方面苦苦挣扎.如何正确检测碰撞?
- 三角形-三角形碰撞检测问题
- 不同类别之间的C SFML碰撞检测
- 使用D3DXVECTOR C 的碰撞检测,发生碰撞后该怎么办
- 当我发生碰撞检测时,矢量迭代器不兼容
- 如何使用灵活的碰撞库在两个点云或点云与机器人末端执行器模型之间进行碰撞检测
- 优化碰撞检测C
- 使用碰撞检测来增加SFML 2.4中的游戏分数的问题
- 使用OnComponentHit UE4 C++进行碰撞检测
- 体素世界中的碰撞检测
- 如何在 2D 碰撞检测中正确解析碰撞的位置?
- (中广)获取AABB树生成的边界立方体进行碰撞检测
- 矩形碰撞检测 SDL 2.0
- SDL碰撞检测