如何降低弹跳后球的速度并在c ++ opengl碰撞检测中停止球并使之永远不弹跳?

//处理所有球形碰撞

void handleBallBallCollisions(vector<Ball*> &balls, Octree* octree) {
vector<BallPair> bps;
potentialBallBallCollisions(bps, balls, octree);
for(unsigned int i = 0; i < bps.size(); i++) {
    BallPair bp = bps[i];

    Ball* b1 = bp.ball1;
    Ball* b2 = bp.ball2;
    if (testBallBallCollision(b1, b2)) {
        //Make the balls reflect off of each other
        Vec3f displacement = (b1->pos - b2->pos).normalize();
        b1->v -= 2 * displacement * b1->v.dot(displacement);
        b2->v -= 2 * displacement * b2->v.dot(displacement);
 }}}
void applyGravity(vector<Ball*> &balls) {
for (unsigned int i = 0; i < balls.size(); i++) {
    Ball* ball = balls[i];
    ball->v -= Vec3f( 0, GRAVITY * TIME_BETWEEN_UPDATES, 0);


}

最佳答案

碰撞后,为两个球的速度Ball::v添加一个阻尼因子。从物理上讲,这将是非弹性散射,其中一部分能量以热量的形式消散。

08-25 07:42