Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Engine.XBoxPlayerInput


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
class XBoxPlayerInput extends PlayerInput
    config(User)
    transient;

const InputMax = 32768;

var() config float  HScale;
var() config float  HExponent;
var() config float  HLookRateMax;
var() config float  VScale;
var() config float  VExponent;
var() config float  VLookRateMax;
var() config bool   bInvertVLook;
var() config bool   bLookSpring;
var() float         HLook;
var() float         VLook;
var() float         abx, abz; //tmp
var() float         wfor,wstr; //tmp
var() float         wafor,wastr; //tmp

struct LookPreset
{
    var() localized string  PresetName;
    var() float             HScale;
    var() float             HExponent;
    var() float             VScale;
    var() float             VExponent;
};

const NumPresets=4;
var() config LookPreset     LookPresets[NumPresets];
var() config string         SelectedPresetName;
 
var() float                 VelScale;
var() float                 AccelScale;
var() float                 DampeningFactor;
var() float                 MinAccelComponent;

const MaxFilterEntries=4;
var() float                 ForwardFilter[MaxFilterEntries];
var() float                 StrafeFilter[MaxFilterEntries];

// Postprocess the player's input.
function PlayerInput( float DeltaTime )
{
    local float FOVScale;

    if (bSnapLevel != 0)
        bCenterView = true;
    else if (aBaseZ != 0)
        bCenterView = false;

    abx = aBaseX; //tmp
    abz = aBaseZ; //tmp

    if (bInvertVLook)
        aBaseZ *= -1.f;

    // Remap the turn inputs to an exponential curve
    HLook = Remap(aBaseX, HScale, HExponent, HLookRateMax);
    VLook = Remap(aBaseZ, VScale, VExponent, VLookRateMax);

    // Check for Double click move
    // flag transitions
    bEdgeForward    = (bWasForward  ^^ (aBaseY  > 0));
    bEdgeBack       = (bWasBack     ^^ (aBaseY  < 0));
    bEdgeRight      = (bWasRight    ^^ (aStrafe > 0));
    bEdgeLeft       = (bWasLeft     ^^ (aStrafe < 0));
    bWasForward     = (aBaseY  > 0);
    bWasBack        = (aBaseY  < 0);
    bWasRight       = (aStrafe > 0);
    bWasLeft        = (aStrafe < 0);

    // Map to other input axes
    aForward = aBaseY;
 //   if (Pawn != None)
//	    VelToAccel(deltaTime);

    FOVScale = DesiredFOV * 0.01; //should be 1/defaultFOV
    aTurn    = HLook * FOVScale;
    aLookUp  = VLook * FOVScale;
    
    // Handle walking.
    HandleWalking();
}

// exp remap + linear remap
static function float Remap(float in, float scale, float exp, float ratemax)
{
    local float out;
    local bool bNeg;

    in /= InputMax;

    if (in < 0)
    {
        bNeg = true;
        in *= -1.f;
    }

    out = (in * scale) + (in**exp);

    if (bNeg)
        out *= -1.f;

    out *= ratemax/(1.f + scale);

    return out;
}

//try doing this a a vector, instead of components
function VelToAccel(float dt)
{
    local vector x, y, z;
    
    // tmp
    wfor = aForward*VelScale;
    wstr = aStrafe*VelScale;

    GetAxes(Pawn.Rotation, x, y, z);
    aForward = GetComponentAccel(aForward, x, dt, ForwardFilter);
    aStrafe  = GetComponentAccel(aStrafe,  y, dt, StrafeFilter);

    // tmp
    wafor = aForward;
    wastr = aStrafe;
}

function float GetComponentAccel(float input, vector dir, float dt, out float filter[MaxFilterEntries], optional bool blog)
{
    local float speed;
    local float error; 
    local float output;

    // No input ... early out
    if (input == 0.f)
        return FilterOutput(filter, input);

    speed = Pawn.Velocity dot dir;
    error = input*VelScale - speed;

    output = DampeningFactor * error * AccelScale * dt;

    if (sign(output) != sign(input))
        output = MinAccelComponent * sign(input);

    output = FilterOutput(filter, output);

    if (blog) log(Level.TimeSeconds$"    "$input*VelScale$"    "$speed$"    "$error$"    "$output);

    return output;
}

function float sign(float in)
{
    if (in != 0.f)
        return Abs(in) / in;
    return 0.f;
}

function float FilterOutput(out float filter[MaxFilterEntries], float output)
{
    local int i;
    local float total;

    output /= MaxFilterEntries;

    for (i=0; i<MaxFilterEntries-1; i++)
    {
        filter[i] = filter[i+1];
        total += filter[i];
    }
    filter[i] = output;
    total += output;

    return total;
}

function bool InvertLook()
{
    bInvertVLook = !bInvertVLook;
    return bInvertVLook;
}

defaultproperties
{
     HExponent=1.000000
     HLookRateMax=1500.000000
     VExponent=1.000000
     VLookRateMax=750.000000
     bInvertVLook=True
     LookPresets(0)=(PresetName="Linear",HExponent=1.000000,VExponent=1.000000)
     LookPresets(1)=(PresetName="Exponential",HExponent=2.000000,VExponent=2.000000)
     LookPresets(2)=(PresetName="Hybrid",HScale=0.500000,HExponent=4.000000,VScale=0.500000,VExponent=4.000000)
     LookPresets(3)=(PresetName="Custom",HScale=0.500000,HExponent=4.000000,VScale=0.500000,VExponent=4.000000)
     SelectedPresetName="Hybrid"
     VelScale=0.013400
     AccelScale=4.655000
     DampeningFactor=30.000000
     MinAccelComponent=0.100000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mon 23/10/2006 20:25:18.000 - Creation time: Wed 7/2/2007 19:16:59.171 - Created with UnCodeX