Code:
new g_iRotationAngle;
new Float:g_fRadius = 100.0;
new Float:g_vCenter[ 3 ];
new bool:g_bClockwise;
StartRotation( iCenterEntity, iRotatingEntity, Float:fRadius, bool:bClockwise, Float:fSpeed )
{
entity_get_vector( iCenterEntity, EV_VEC_origin, g_vCenter );
g_fRadius = fRadius;
g_bClockwise = bClockwise;
new Float:fCircumference = 2.0 * M_PI * fRadius;
// speed = distance / time
// time = distance / speed
set_task( ( fCircumference / fSpeed ), "TaskDoRotate", iRotatingEntity, _, _, "b" );
}
public TaskDoRotate( iEntity )
{
if( g_bClockwise )
{
if( g_iRotationAngle-- <= 0 )
{
g_iRotationAngle = 359;
}
}
else
{
g_iRotationAngle = ++g_iRotationAngle % 360;
}
new Float:vVector[ 3 ];
new iAngle = g_iRotationAngle % 90;
new Float:fSin = 1.0;
new Float:fCos = 1.0;
if( iAngle == 0 )
{
switch( g_iRotationAngle )
{
case 180: fCos = -1.0;
case 270: fSin = -1.0;
}
}
else if( g_iRotationAngle < 90 )
{
// all are positive
}
else if( g_iRotationAngle < 180 )
{
// sin is positive, others negative
iAngle = 90 - iAngle;
fCos = -1.0;
}
else if( g_iRotationAngle < 270 )
{
// tan is positive, others negative
fSin = -1.0;
fCos = -1.0;
}
else //if( g_iRotationAngle < 360 )
{
// cos is positive, others negative
iAngle = 90 - iAngle;
fSin = -1.0;
}
vVector[ 0 ] = floatcos( float( iAngle ), degrees ) * g_fRadius * fCos;
vVector[ 1 ] = floatsin( float( iAngle ), degrees ) * g_fRadius * fSin;
vVector[ 0 ] += g_vCenter[ 0 ];
vVector[ 1 ] += g_vCenter[ 1 ];
vVector[ 2 ] += g_vCenter[ 2 ];
entity_set_origin( iEntity, vVector );
}
__________________