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

USARBot.KDTrack


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
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
class KDTrack extends KTire config(USARBot) abstract;

var float          Radius;

var class<KTire>   AuxTireClass;
var vector         ATPos;
var float          ATRadius;
var KTire          AuxTire;

var class<KTire>   TrackTireClass;
var array<KTire>   TTires;
var float          TTRadius;
var config int     MaxTTiresNum;
var int            TTiresNum;

// KCarWheelJoint settings
var float          SuspHighLimit;
var float          SuspLowLimit; 
var float          SuspStiffness;
var float          SuspDamping;  
                   
var float          lastKMotorTorque;
var float          lastKMaxSpeed;
var float          lastKBraking;

var float          ATRatio;
var float          TTRatio;


struct pvector {
    var float X;
    var float Y;
    var float Z;
};

var pvector        RS_TiresPos[17];
//var Quat		   RS_TiresQuat[17];
var vector         RS_TiresLinVel[17];
//var vector		   RS_TiresAngVel[17];
var byte           RS_UpdateId;

var byte           last_RS_UpdateId;
var float          NextNetUpdateTime;
var float          MaxNetUpdateInterval;

replication
{
    reliable if(Level.NetMode == NM_DedicatedServer)
        RS_TiresPos, /*RS_TiresQuat,*/ RS_TiresLinVel, /*RS_TiresAngVel,*/ RS_UpdateId;
}

simulated function vector toVector(pVector pv)
{
    local vector vec;
    vec.X = pv.X;
    vec.Y = pv.Y;
    vec.Z = pv.Z;
    return vec;
}

simulated function pVector toPVector(vector vec)
{
    local pVector pv;
    pv.X = vec.X;
    pv.Y = vec.Y;
    pv.Z = vec.Z;
    return pv;
}

simulated function PostNetBeginPlay()
{
    local int i;
    local float len, rOff, lOff, tLen, sinValue, cosValue;
    local vector pos, step;
    local vector RotX, RotY, RotZ, relPos;
    
    Super.PostNetBeginPlay();
    if (MaxTTiresNum>16) MaxTTiresNum=16;
    
    GetAxes(Owner.Rotation,RotX,RotY,RotZ);
    relPos = (Location-Owner.Location)<<Owner.Rotation;
    
    AuxTire = spawn(AuxTireClass,Owner,,Location+ATPos.X*RotX+ATPos.Y*RotY+ATPos.Z*RotZ);
    AuxTire.WheelJoint = spawn(class'KCarWheelJoint',Owner);
    //Set primary constraint params
    AuxTire.WheelJoint.KConstraintActor1 = Owner;
    AuxTire.WheelJoint.KPos1 = (relPos+ATPos)/50;
    AuxTire.WheelJoint.KPriAxis1 = vect(0,0,1);
    AuxTire.WheelJoint.KSecAxis1 = vect(0,1,0);
    //Set secondary constraint params
    AuxTire.WheelJoint.KConstraintActor2 = AuxTire;
    AuxTire.WheelJoint.KPos2 = vect(0,0,0);
    AuxTire.WheelJoint.KPriAxis2 = vect(0,0,1);
    AuxTire.WheelJoint.KSecAxis2 = vect(0,1,0);

    AuxTire.WheelJoint.KSuspHighLimit = SuspHighLimit;
    AuxTire.WheelJoint.KSuspLowLimit  = SuspLowLimit;
    AuxTire.WheelJoint.KSuspStiffness = SuspStiffness;
    AuxTire.WheelJoint.KSuspDamping   = SuspDamping;
    AuxTire.WheelJoint.SetPhysics(PHYS_Karma);

    lOff = Sqrt((Radius+TTRadius)*(Radius+TTRadius)-(Radius-TTRadius)*(Radius-TTRadius));
    rOff = Sqrt((ATRadius+TTRadius)*(ATRadius+TTRadius)-(ATRadius-TTRadius)*(ATRadius-TTRadius));
    tLen = Sqrt(ATPos.X*ATPos.X-(Radius-ATRadius)*(Radius-ATRadius));
    len =  tLen - lOff - rOff;
    TTiresNum = Min(MaxTTiresNum,2*Ceil(len/TTRadius/2+1));
    if (ATPos.X<0) {
        tLen = -tLen;
        len = -len;
        lOff = -lOff;
    }
    sinValue = (Radius-ATRadius)/tLen;
    cosValue = ATPos.X/tLen;
    pos.X = (Radius-TTRadius)*sinValue + lOff*cosValue;
    pos.Z = (Radius-TTRadius)*cosValue - lOff*sinValue;
    step.X = (2*len/(TTiresNum-2))*cosValue;
    step.Z = -(2*len/(TTiresNum-2))*sinValue;
    for (i=0;i<TTiresNum;i+=2) {
        TTires[i] = spawn(TrackTireClass,Owner,,Location+pos.X*RotX+pos.Y*RotY+pos.Z*RotZ);
        TTires[i].WheelJoint = spawn(class'KCarWheelJoint',Owner);
        TTires[i].WheelJoint.KConstraintActor1 = Owner;
        TTires[i].WheelJoint.KPos1 = (relPos+pos)/50;
        TTires[i].WheelJoint.KPriAxis1 = vect(0,0,1);
        TTires[i].WheelJoint.KSecAxis1 = vect(0,1,0);
        TTires[i].WheelJoint.KConstraintActor2 = TTires[i];
        TTires[i].WheelJoint.KPos2 = vect(0,0,0);
        TTires[i].WheelJoint.KPriAxis2 = vect(0,0,1);
        TTires[i].WheelJoint.KSecAxis2 = vect(0,1,0);
        TTires[i].WheelJoint.KSuspHighLimit = SuspHighLimit;
        TTires[i].WheelJoint.KSuspLowLimit  = SuspLowLimit;
        TTires[i].WheelJoint.KSuspStiffness = SuspStiffness;
        TTires[i].WheelJoint.KSuspDamping   = SuspDamping;
        TTires[i].WheelJoint.SetPhysics(PHYS_Karma);

        pos.Z = -pos.Z;
        TTires[i+1] = spawn(TrackTireClass,Owner,,Location+pos.X*RotX+pos.Y*RotY+pos.Z*RotZ);
        TTires[i+1].WheelJoint = spawn(class'KCarWheelJoint',Owner);
        TTires[i+1].WheelJoint.KConstraintActor1 = Owner;
        TTires[i+1].WheelJoint.KPos1 = (relPos+pos)/50;
        TTires[i+1].WheelJoint.KPriAxis1 = vect(0,0,1);
        TTires[i+1].WheelJoint.KSecAxis1 = vect(0,1,0);
        TTires[i+1].WheelJoint.KConstraintActor2 = TTires[i+1];
        TTires[i+1].WheelJoint.KPos2 = vect(0,0,0);
        TTires[i+1].WheelJoint.KPriAxis2 = vect(0,0,1);
        TTires[i+1].WheelJoint.KSecAxis2 = vect(0,1,0);
        TTires[i+1].WheelJoint.KSuspHighLimit = SuspHighLimit;
        TTires[i+1].WheelJoint.KSuspLowLimit  = SuspLowLimit;
        TTires[i+1].WheelJoint.KSuspStiffness = SuspStiffness;
        TTires[i+1].WheelJoint.KSuspDamping   = SuspDamping;
        TTires[i+1].WheelJoint.SetPhysics(PHYS_Karma);
        
        pos.Z = -pos.Z;
        pos += step;
    }
    
    KUpdateParams();
    
    ATRatio = Radius/ATRadius;
    TTRatio = Radius/TTRadius;
}

simulated event KUpdateParams()
{
    local int i;
    
    AuxTire.WheelJoint.KUpdateConstraintParams();
    for (i=0;i<TTires.length;i++)
        TTires[i].WheelJoint.KUpdateConstraintParams();
}

simulated event Destroyed()
{
   local int i;
   
   AuxTire.WheelJoint.Destroy();
   AuxTire.Destroy();
   for(i=0;i<TTires.length;i++) {
      TTires[i].WheelJoint.Destroy();
      TTires[i].Destroy();
   }
   Super.Destroyed();
}

function PackState()
{
    local vector pos,oldPos;
    local KRigidBodyState RBState;
    local int i;

    AuxTire.KGetRigidBodyState(RBState);
    pos = KRBVecToVector(RBState.Position);
    oldPos = toVector(RS_TiresPos[0]);
    
    if ((VSize(oldPos - pos) > 1) || Level.TimeSeconds > NextNetUpdateTime)
        NextNetUpdateTime = Level.TimeSeconds + MaxNetUpdateInterval;
    else
        return;
    
    RS_TiresPos[0] = toPVector(KRBVecToVector(RBState.Position));
    //RS_TiresQuat[0] = RBState.Quaternion;
    RS_TiresLinVel[0] = KRBVecToVector(RBState.LinVel);
    //RS_TiresAngVel[0] = KRBVecToVector(RBState.AngVel);
    for (i=0;i<TTires.length;i++) {
        TTires[i].KGetRigidBodyState(RBState);
        RS_TiresPos[i+1] = toPVector(KRBVecToVector(RBState.Position));
        //RS_TiresQuat[i+1] = RBState.Quaternion;
        RS_TiresLinVel[i+1] = KRBVecToVector(RBState.LinVel);
        //RS_TiresAngVel[i+1] = KRBVecToVector(RBState.AngVel);
    }
    RS_UpdateId += 1;
}

simulated function UndateState()
{
    local int i;
    
    AuxTire.KGetRigidBodyState(AuxTire.ReceiveState);
    AuxTire.ReceiveState.Position = KRBVecFromVector(toVector(RS_TiresPos[0]));
    //AuxTire.ReceiveState.Quaternion = RS_TiresQuat[0];
    AuxTire.ReceiveState.LinVel = KRBVecFromVector(RS_TiresLinVel[0]);
    //AuxTire.ReceiveState.AngVel = KRBVecFromVector(RS_TiresAngVel[0]);
    AuxTire.bReceiveStateNew = true;
    
    for (i=0;i<TTires.length;i++) {
        TTires[i].KGetRigidBodyState(TTires[i].ReceiveState);
        TTires[i].ReceiveState.Position = KRBVecFromVector(toVector(RS_TiresPos[i+1]));
        //TTires[i].ReceiveState.Quaternion = RS_TiresQuat[i+1];
        TTires[i].ReceiveState.LinVel = KRBVecFromVector(RS_TiresLinVel[i+1]);
        //TTires[i].ReceiveState.AngVel = KRBVecFromVector(RS_TiresAngVel[i+1]);
        TTires[i].bReceiveStateNew = true;
    }
    last_RS_UpdateId = RS_UpdateId;
}

simulated function Tick(float Delta)
{
    local int i;
    
    if (WheelJoint==None) return;

    if (Level.NetMode == NM_DedicatedServer) 
        PackState();

    if (Level.NetMode != NM_DedicatedServer && last_RS_UpdateId!=RS_UpdateId)
        UndateState();
    
    if (lastKMotorTorque==WheelJoint.KMotorTorque && 
        lastKMaxSpeed==WheelJoint.KMaxSpeed && 
        lastKBraking==WheelJoint.KBraking)
        return;
    
    AuxTire.WheelJoint.KMotorTorque = WheelJoint.KMotorTorque;
    AuxTire.WheelJoint.KMaxSpeed = ATRatio*WheelJoint.KMaxSpeed;
    AuxTire.WheelJoint.KBraking = WheelJoint.KBraking;
    
    for(i=0;i<TTires.length;i++) {
        TTires[i].WheelJoint.KMotorTorque = WheelJoint.KMotorTorque;
        TTires[i].WheelJoint.KMaxSpeed = TTRatio*WheelJoint.KMaxSpeed;
        TTires[i].WheelJoint.KBraking = WheelJoint.KBraking;
    }
    
    KUpdateParams();
    lastKMotorTorque = WheelJoint.KMotorTorque;
    lastKMaxSpeed = WheelJoint.KMaxSpeed;
    lastKBraking = WheelJoint.KBraking;
}

// NOTE: all the parameters are in UU
// The radius of S_RearWheel is 137uu.
defaultproperties
{
    Radius=5.75
    StaticMesh=StaticMesh'BulldogMeshes.Simple.S_RearWheel'
    DrawScale=0.04200000

    MaxTTiresNum=16
    TrackTireClass=USARBot.TrackTire
    TTRadius=1.37

    AuxTireClass=USARBot.USARTire
    ATRadius=5.75
    ATPos=(X=-13)

    SuspStiffness=150.000000
    SuspDamping=50.000000
    SuspHighLimit=0.0030
    SuspLowLimit=-0.0030
    RollFriction=25.000000
    LateralFriction=25.00000
    SlipRate=0.0003000

    MaxNetUpdateInterval=0.40000
    CollisionRadius=1.000000
    CollisionHeight=1.000000
    Begin Object Class=KarmaParamsRBFull Name=KParams0
        KInertiaTensor(0)=1.800000
        KInertiaTensor(3)=1.800000
        KInertiaTensor(5)=1.800000
        KLinearDamping=0.000000
        KAngularDamping=0.000000
        bHighDetailOnly=False
        bClientOnly=False
        bKDoubleTickRate=True
        Name="KParams0"
    End Object
    KParams=KarmaParamsRBFull'USARBot.KDTrack.KParams0'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 26.9.2006 17:51:34.000 - Creation time: Mo 16.4.2007 11:20:49.109 - Created with UnCodeX