Пример #1
0
angle_t R_PointToAngle(fixed_t x, fixed_t y, int usePlayer)
{
  static fixed_t oldx, oldy;
  static angle_t oldresult;

  if (usePlayer == 0)
  {
    x -= viewx; y -= viewy;
  }
  else
  {
    //SB- use player position rather than view position (as these will have stereo offset included
    //and can mean different sprites for each eye!)
    x -= viewplayer->mo->x;
    y -= viewplayer->mo->y;
  }

  if ( /* !render_precise && */
      // e6y: here is where "slime trails" can SOMETIMES occur
#ifdef GL_DOOM
      (V_GetMode() != VID_MODEGL) &&
#endif
      (x < INT_MAX/4 && x > -INT_MAX/4 && y < INT_MAX/4 && y > -INT_MAX/4)
     )
  {
    // old R_PointToAngle
    return (x || y) ?
    x >= 0 ?
      y >= 0 ?
        (x > y) ? tantoangle[SlopeDiv(y,x)] :                      // octant 0
                ANG90-1-tantoangle[SlopeDiv(x,y)] :                // octant 1
        x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] :                // octant 8
                       ANG270+tantoangle[SlopeDiv(x,y)] :          // octant 7
      y >= 0 ? (x = -x) > y ? ANG180-1-tantoangle[SlopeDiv(y,x)] : // octant 3
                            ANG90 + tantoangle[SlopeDiv(x,y)] :    // octant 2
        (x = -x) > (y = -y) ? ANG180+tantoangle[ SlopeDiv(y,x)] :  // octant 4
                              ANG270-1-tantoangle[SlopeDiv(x,y)] : // octant 5
    0;
  }

  // R_PointToAngleEx merged into R_PointToAngle
  // e6y: The precision of the code above is abysmal so use the CRT atan2 function instead!
  if (oldx != x || oldy != y)
  {
    oldx = x;
    oldy = y;
    oldresult = (int)(atan2(y, x) * ANG180/M_PI);
  }
  return oldresult;
}
Пример #2
0
angle_t R_PointToAngle2(fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y)
{
  return (y -= viewy, (x -= viewx) || y) ?
    x >= 0 ?
      y >= 0 ?
        (x > y) ? tantoangle[SlopeDiv(y,x)] :                      // octant 0
                ANG90-1-tantoangle[SlopeDiv(x,y)] :                // octant 1
        x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] :                // octant 8
                       ANG270+tantoangle[SlopeDiv(x,y)] :          // octant 7
      y >= 0 ? (x = -x) > y ? ANG180-1-tantoangle[SlopeDiv(y,x)] : // octant 3
                            ANG90 + tantoangle[SlopeDiv(x,y)] :    // octant 2
        (x = -x) > (y = -y) ? ANG180+tantoangle[ SlopeDiv(y,x)] :  // octant 4
                              ANG270-1-tantoangle[SlopeDiv(x,y)] : // octant 5
    0;
}
Пример #3
0
angle_t R_PointToAngle(fixed_t x, fixed_t y)
{
#if 0
	// JDC: the oldresult case only hit 10%, making it a net loss.
	// JDC: added parenthesis to force constant evaluation
    return (int)(atan2(y-viewy, x-viewx) * (ANG180/M_PI) );	
#else
  static fixed_t oldx, oldy;
  static angle_t oldresult;

  x -= viewx; y -= viewy;

  if ( /* !render_precise && */
      // e6y: here is where "slime trails" can SOMETIMES occur
#ifdef GL_DOOM
      (V_GetMode() != VID_MODEGL) &&
#endif
      (x < INT_MAX/4 && x > -INT_MAX/4 && y < INT_MAX/4 && y > -INT_MAX/4)
     )
  {
    // old R_PointToAngle
    return (x || y) ?
    x >= 0 ?
      y >= 0 ?
        (x > y) ? tantoangle[SlopeDiv(y,x)] :                      // octant 0
                ANG90-1-tantoangle[SlopeDiv(x,y)] :                // octant 1
        x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] :                // octant 8
                       ANG270+tantoangle[SlopeDiv(x,y)] :          // octant 7
      y >= 0 ? (x = -x) > y ? ANG180-1-tantoangle[SlopeDiv(y,x)] : // octant 3
                            ANG90 + tantoangle[SlopeDiv(x,y)] :    // octant 2
        (x = -x) > (y = -y) ? ANG180+tantoangle[ SlopeDiv(y,x)] :  // octant 4
                              ANG270-1-tantoangle[SlopeDiv(x,y)] : // octant 5
    0;
  }

  // R_PointToAngleEx merged into R_PointToAngle
  // e6y: The precision of the code above is abysmal so use the CRT atan2 function instead!
  if (oldx != x || oldy != y)
  {
    oldx = x;
    oldy = y;
    oldresult = (int)(atan2(y, x) * ANG180/M_PI );
  }
   return oldresult;
#endif	
}
Пример #4
0
angle_t R_PointToAngle2(fixed_t viewx, fixed_t viewy, fixed_t x, fixed_t y)
{
	x -= viewx;
	y -= viewy;

	if((x | y) == 0)
		return 0;

	if(x < R_P2ATHRESHOLD && x > -R_P2ATHRESHOLD &&
		y < R_P2ATHRESHOLD && y > -R_P2ATHRESHOLD)
	{
		if(x >= 0)
		{
			if (y >= 0)
			{
				if(x > y)
				{
					// octant 0
					return tantoangle_acc[SlopeDiv(y, x)];
				}
				else
				{
					// octant 1
					return ANG90 - 1 - tantoangle_acc[SlopeDiv(x, y)];
				}
			}
			else // y < 0
			{
				y = -y;

				if(x > y)
				{
					// octant 8
					return 0 - tantoangle_acc[SlopeDiv(y, x)];
				}
				else
				{
					// octant 7
					return ANG270 + tantoangle_acc[SlopeDiv(x, y)];
				}
			}
		}
		else // x < 0
		{
			x = -x;

			if(y >= 0)
			{
				if(x > y)
				{
					// octant 3
					return ANG180 - 1 - tantoangle_acc[SlopeDiv(y, x)];
				}
				else
				{
					// octant 2
					return ANG90 + tantoangle_acc[SlopeDiv(x, y)];
				}
			}
			else // y < 0
			{
				y = -y;

				if(x > y)
				{
					// octant 4
					return ANG180 + tantoangle_acc[SlopeDiv(y, x)];
				}
				else
				{
					// octant 5
					return ANG270 - 1 - tantoangle_acc[SlopeDiv(x, y)];
				}
			}
		}
	}
	else
	{
      return (angle_t)(atan2((double)y, (double)x) * (ANG180 / PI));
	}

   return 0;
}