components/prboom/p_map.c
/*
 * killough 9/12/98:
 *
 * Apply "torque" to objects hanging off of ledges, so that they
 * fall off. It's not really torque, since Doom has no concept of
 * rotation, but it's a convincing effect which avoids anomalies
 * such as lifeless objects hanging more than halfway off of ledges,
 * and allows objects to roll off of the edges of moving lifts, or
 * to slide up and then back down stairs, or to fall into a ditch.
 * If more than one linedef is contacted, the effects are cumulative,
 * so balancing is possible.
 */
killough 9/12/98:
Apply "torque" to objects hanging off of ledges, so that they
fall off. It's not really torque, since Doom has no concept of
rotation, but it's a convincing effect which avoids anomalies
such as lifeless objects hanging more than halfway off of ledges,
and allows objects to roll off of the edges of moving lifts, or
to slide up and then back down stairs, or to fall into a ditch.
If more than one linedef is contacted, the effects are cumulative,
so balancing is possible.
killough 9 / 12 / 98 : Apply " torque " to objects hanging off of ledges so that they fall off . It ' s not really torque since Doom has no concept of rotation but it ' s a convincing effect which avoids anomalies such as lifeless objects hanging more than halfway off of ledges and allows objects to roll off of the edges of moving lifts or to slide up and then back down stairs or to fall into a ditch . If more than one linedef is contacted the effects are cumulative so balancing is possible .
static boolean PIT_ApplyTorque(line_t *ld)
{
  if (ld->backsector &&       
      tmbbox[BOXRIGHT]  > ld->bbox[BOXLEFT]  &&
      tmbbox[BOXLEFT]   < ld->bbox[BOXRIGHT] &&
      tmbbox[BOXTOP]    > ld->bbox[BOXBOTTOM] &&
      tmbbox[BOXBOTTOM] < ld->bbox[BOXTOP] &&
      P_BoxOnLineSide(tmbbox, ld) == -1)
    {
      mobj_t *mo = tmthing;
      fixed_t dist =                               
  + (ld->dx >> FRACBITS) * (mo->y >> FRACBITS)
  - (ld->dy >> FRACBITS) * (mo->x >> FRACBITS)
  - (ld->dx >> FRACBITS) * (ld->v1->y >> FRACBITS)
  + (ld->dy >> FRACBITS) * (ld->v1->x >> FRACBITS);
      if (dist < 0 ?                               
    ld->frontsector->floorheight < mo->z &&
    ld->backsector->floorheight >= mo->z :
          ld->backsector->floorheight < mo->z &&
          ld->frontsector->floorheight >= mo->z)
  {
    fixed_t x = D_abs(ld->dx), y = D_abs(ld->dy);
    if (y > x)
      {
        fixed_t t = x;
        x = y;
        y = t;
      }
    y = finesine[(tantoangle[FixedDiv(y,x)>>DBITS] +
      ANG90) >> ANGLETOFINESHIFT];
    dist = FixedDiv(FixedMul(dist, (mo->gear < OVERDRIVE) ?
           y << -(mo->gear - OVERDRIVE) :
           y >> +(mo->gear - OVERDRIVE)), x);
    x = FixedMul(ld->dy, dist);
    y = FixedMul(ld->dx, dist);
    dist = FixedMul(x,x) + FixedMul(y,y);
    while (dist > FRACUNIT*4 && mo->gear < MAXGEAR)
      ++mo->gear, x >>= 1, y >>= 1, dist >>= 1;
    mo->momx -= x;
    mo->momy += y;
  }
    }
  return true;
}
static boolean PIT_ApplyTorque ( line_t * ld ) { if ( ld -> backsector && tmbbox [ BOXRIGHT ] > ld -> bbox [ BOXLEFT ] && tmbbox [ BOXLEFT ] < ld -> bbox [ BOXRIGHT ] && tmbbox [ BOXTOP ] > ld -> bbox [ BOXBOTTOM ] && tmbbox [ BOXBOTTOM ] < ld -> bbox [ BOXTOP ] && P_BoxOnLineSide ( tmbbox , ld ) == -1 ) { mobj_t * mo = tmthing ; fixed_t dist = + ( ld -> dx >> FRACBITS ) * ( mo -> y >> FRACBITS ) - ( ld -> dy >> FRACBITS ) * ( mo -> x >> FRACBITS ) - ( ld -> dx >> FRACBITS ) * ( ld -> v1 -> y >> FRACBITS ) + ( ld -> dy >> FRACBITS ) * ( ld -> v1 -> x >> FRACBITS ) ; if ( dist < 0 ? ld -> frontsector -> floorheight < mo -> z && ld -> backsector -> floorheight >= mo -> z : ld -> backsector -> floorheight < mo -> z && ld -> frontsector -> floorheight >= mo -> z ) { fixed_t x = D_abs ( ld -> dx ) , y = D_abs ( ld -> dy ) ; if ( y > x ) { fixed_t t = x ; x = y ; y = t ; } y = finesine [ ( tantoangle [ FixedDiv ( y , x ) >> DBITS ] + ANG90 ) >> ANGLETOFINESHIFT ] ; dist = FixedDiv ( FixedMul ( dist , ( mo -> gear < OVERDRIVE ) ? y << - ( mo -> gear - OVERDRIVE ) : y >> + ( mo -> gear - OVERDRIVE ) ) , x ) ; x = FixedMul ( ld -> dy , dist ) ; y = FixedMul ( ld -> dx , dist ) ; dist = FixedMul ( x , x ) + FixedMul ( y , y ) ; while ( dist > FRACUNIT * 4 && mo -> gear < MAXGEAR ) ++ mo -> gear , x >>= 1 , y >>= 1 , dist >>= 1 ; mo -> momx -= x ; mo -> momy += y ; } } return true ; }
killough 9/12/98:
 Apply "torque" to objects hanging off of ledges, so that they
 fall off.
killough 9 / 12 / 98 : Apply " torque " to objects hanging off of ledges so that they fall off .
// If thing touches two-sided pivot linedef // lever arm // dropoff direction /* At this point, we know that the object straddles a two-sided
     * linedef, and that the object's center of mass is above-ground.
     */ /* Momentum is proportional to distance between the
     * object's center of mass and the pivot linedef.
     *
     * It is scaled by 2^(OVERDRIVE - gear). When gear is
     * increased, the momentum gradually decreases to 0 for
     * the same amount of pseudotorque, so that oscillations
     * are prevented, yet it has a chance to reach equilibrium.
     */ /* Apply momentum away from the pivot linedef. */ /* Avoid moving too fast all of a sudden (step into "overdrive") */