我正在尝试将一个具有速度和角速度的多边形从不可移动的墙壁上弹回,当其中一个顶点与其碰撞时。我可以检测到碰撞,并且已经计算出了输入并知道需要什么输出,但是我还没有找到或者想出响应的实现方法。任何帮助都将不胜感激。
function collisionResponse(
c, // object center of mass position
v, // velocity of object
a, // the angular velocity of the object
p, // point of contact with line
n // normalized normal of line
) {
// Make a vector from center mass to contact point
cp = p - c;
// Total velocity at contact point (add angular effect)
pv.x = v.x - cp.y * a;
pv.y = v.y + cp.x * a;
// Reflect point of contact velocity off the line (wall)
rv = reflect( pv, n );
// ..magic happens.. ??
result.v = ?? // resulting object velocity
result.a = ?? // resulting object angular velocity
return result;
}
result.v = v + rv; result.a = a + cross(rv, cp) / i;
但我仍然没有I的值。 - pixelmike