simulated function int LagRot(int NewValue, int LastValue, float MaxDiff, int Index)
{
local int RotDiff;
local float LeadMag, DeltaTime;
if ( NewValue ClockWiseFrom LastValue )
{
if ( LastValue > NewValue )
{
LastValue -= 65536;
}
}
else
{
if ( NewValue > LastValue )
{
NewValue -= 65536;
}
}
DeltaTime = Level.TimeSeconds - LastRotUpdate;
RotDiff = NewValue - LastValue;
if ( (RotDiff == 0) || (OldRotDiff[Index] == 0) )
{
if(ShouldLagRot())
LeadMag = OldLeadMag[Index]; //: 0.0;
if ( (RotDiff == 0) && (OldRotDiff[Index] == 0) )
{
OldMaxDiff[Index] = 0;
}
}
else if ( (RotDiff > 0) == (OldRotDiff[Index] > 0) )
{
if (ShouldLagRot())
{
MaxDiff = FMin(1, Abs(RotDiff)/(12000*DeltaTime)) * MaxDiff;
if ( OldMaxDiff[Index] != 0 )
MaxDiff = FMax(OldMaxDiff[Index], MaxDiff);
OldMaxDiff[Index] = MaxDiff;
if( (NewValue > LastValue) )
LeadMag = -1 * MaxDiff;
}
else
{
LeadMag = 0;
}
if ( DeltaTime < 1/RotChgSpeed )
{
LeadMag = (1.0 - RotChgSpeed*DeltaTime)*OldLeadMag[Index] + RotChgSpeed*DeltaTime*LeadMag;
}
else
{
LeadMag = 0;
}
}
else
{
LeadMag = 0;
OldMaxDiff[Index] = 0;
if ( DeltaTime < 1/ReturnChgSpeed )
{
LeadMag = (1 - ReturnChgSpeed*DeltaTime)*OldLeadMag[Index] + ReturnChgSpeed*DeltaTime*LeadMag;
}
}
OldLeadMag[Index] = LeadMag;
OldRotDiff[Index] = RotDiff;
return NewValue + LeadMag;
}
simulated function bool ShouldLagRot()
{
return default.RotationLag;
}
simulated event RenderOverlays( Canvas Canvas )
{
local int m;
if (Instigator == None)
return;
if ( Instigator.Controller != None )
Hand = Instigator.Controller.Handedness;
if ((Hand < -1.0) || (Hand > 1.0))
return;
// draw muzzleflashes/smoke for all fire modes so idle state won't
// cause emitters to just disappear
for (m = 0; m < NUM_FIRE_MODES; m++)
{
if (FireMode[m] != None)
{
FireMode[m].DrawMuzzleFlash(Canvas);
}
}
SetLocation( Instigator.Location + Instigator.CalcDrawOffset(self) );
SetPosition(Instigator);
PreDrawFPWeapon(); // Laurent -- Hook to override things before render (like rotation if using a staticmesh)
bDrawingFirstPerson = true;
Canvas.DrawActor(self, false, false, DisplayFOV);
Canvas.DrawActor(FPHands, false, false, DisplayFOV);
if( AttachmentComponent != none ){ Canvas.DrawActor(AttachmentComponent, false, false, DisplayFOV); }
bDrawingFirstPerson = false;
}
simulated event SetPosition(Pawn Holder)
{
local rotator NewRotation, FinalRotation;
if ( !Holder.IsFirstPerson() )
return;
if(Holder.Controller != None)
NewRotation = Holder.GetViewRotation(); //: Holder.Controller.Rotation;
// Add some rotation leading
if (Holder.Controller != None)
{
FinalRotation.Yaw = LagRot(NewRotation.Yaw & 65535, LastRotation.Yaw & 65535, MaxYawLag, 0);
FinalRotation.Pitch = LagRot(NewRotation.Pitch & 65535, LastRotation.Pitch & 65535, MaxPitchLag, 1);
}
else
{
FinalRotation = NewRotation;
}
LastRotUpdate = Level.TimeSeconds;
LastRotation = NewRotation;
SetRotation(FinalRotation);
}