herdem_sheep.c
/**
 * Handler for when two sheep collide
 */
Handler for when two sheep collide
Handler for when two sheep collide
void herdem_sheep_sheep_collision_handler(jty_c_info *c_info)
{
    herdem_sheep *sheep1 = (herdem_sheep *)c_info->e1.actor;
    herdem_sheep *sheep2 = (herdem_sheep *)c_info->e2.actor;
    double c = 1; 
    double rmi1 = sheep1->mi / (sheep1->mi + sheep2->mi); 
    double rmi2 = sheep2->mi / (sheep1->mi + sheep2->mi); 
    jty_vector v_rel = {
        .x = sheep1->parent.vx - sheep2->parent.vx,
        .y = sheep1->parent.vy - sheep2->parent.vy
    };
    if (c_info->normal.x) {
        sheep1->parent.vx -= (1 + c) * v_rel.x * rmi1;
        sheep2->parent.vx += (1 + c) * v_rel.x * rmi2;
    } else {
        sheep1->parent.vy -= (1 + c) * v_rel.y * rmi1;
        sheep2->parent.vy += (1 + c) * v_rel.y * rmi2;
    }
    sheep2->parent.x += rmi2 * c_info->normal.x * (c_info->penetration + 1);
    sheep2->parent.y += rmi2 * c_info->normal.y * (c_info->penetration + 1);
    sheep1->parent.x -= rmi1 * c_info->normal.x * (c_info->penetration + 1);
    sheep1->parent.y -= rmi1 * c_info->normal.y * (c_info->penetration + 1);
}
void herdem_sheep_sheep_collision_handler ( jty_c_info * c_info ) { herdem_sheep * sheep1 = ( herdem_sheep * ) c_info -> e1 . actor ; herdem_sheep * sheep2 = ( herdem_sheep * ) c_info -> e2 . actor ; double c = 1 ; double rmi1 = sheep1 -> mi / ( sheep1 -> mi + sheep2 -> mi ) ; double rmi2 = sheep2 -> mi / ( sheep1 -> mi + sheep2 -> mi ) ; jty_vector v_rel = { . x = sheep1 -> parent . vx - sheep2 -> parent . vx , . y = sheep1 -> parent . vy - sheep2 -> parent . vy } ; if ( c_info -> normal . x ) { sheep1 -> parent . vx -= ( 1 + c ) * v_rel . x * rmi1 ; sheep2 -> parent . vx += ( 1 + c ) * v_rel . x * rmi2 ; } else { sheep1 -> parent . vy -= ( 1 + c ) * v_rel . y * rmi1 ; sheep2 -> parent . vy += ( 1 + c ) * v_rel . y * rmi2 ; } sheep2 -> parent . x += rmi2 * c_info -> normal . x * ( c_info -> penetration + 1 ) ; sheep2 -> parent . y += rmi2 * c_info -> normal . y * ( c_info -> penetration + 1 ) ; sheep1 -> parent . x -= rmi1 * c_info -> normal . x * ( c_info -> penetration + 1 ) ; sheep1 -> parent . y -= rmi1 * c_info -> normal . y * ( c_info -> penetration + 1 ) ; }
Handler for when two sheep collide
Handler for when two sheep collide
/* coefficient of restitution */ /* Reduced inverse mass
                                                            of sheep 1 */ /* Reduced inverse mass
                                                            of sheep 2 */