本文整理汇总了C#中Train.Derail方法的典型用法代码示例。如果您正苦于以下问题:C# Train.Derail方法的具体用法?C# Train.Derail怎么用?C# Train.Derail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Train
的用法示例。
在下文中一共展示了Train.Derail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateTopplingCantAndSpring
// update toppling, cant and spring
internal static void UpdateTopplingCantAndSpring(Train Train, int CarIndex, double TimeElapsed)
{
if (TimeElapsed == 0.0 | TimeElapsed > 0.5)
{
return;
}
// get direction, up and side vectors
double dx, dy, dz;
double ux, uy, uz;
double sx, sy, sz;
{
dx = Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.X - Train.Cars[CarIndex].RearAxle.Follower.WorldPosition.X;
dy = Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.Y - Train.Cars[CarIndex].RearAxle.Follower.WorldPosition.Y;
dz = Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.Z - Train.Cars[CarIndex].RearAxle.Follower.WorldPosition.Z;
double t = 1.0 / Math.Sqrt(dx * dx + dy * dy + dz * dz);
dx *= t; dy *= t; dz *= t;
t = 1.0 / Math.Sqrt(dx * dx + dz * dz);
double ex = dx * t;
double ez = dz * t;
sx = ez;
sy = 0.0;
sz = -ex;
World.Cross(dx, dy, dz, sx, sy, sz, out ux, out uy, out uz);
}
// cant and radius
double c;
{
double ca = Train.Cars[CarIndex].FrontAxle.Follower.CurveCant;
double cb = Train.Cars[CarIndex].RearAxle.Follower.CurveCant;
c = Math.Tan(0.5 * (Math.Atan(ca) + Math.Atan(cb)));
}
double r, rs;
if (Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius != 0.0 & Train.Cars[CarIndex].RearAxle.Follower.CurveRadius != 0.0)
{
r = Math.Sqrt(Math.Abs(Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius * Train.Cars[CarIndex].RearAxle.Follower.CurveRadius));
rs = (double)Math.Sign(Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius + Train.Cars[CarIndex].RearAxle.Follower.CurveRadius);
}
else if (Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius != 0.0)
{
r = Math.Abs(Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius);
rs = (double)Math.Sign(Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius);
}
else if (Train.Cars[CarIndex].RearAxle.Follower.CurveRadius != 0.0)
{
r = Math.Abs(Train.Cars[CarIndex].RearAxle.Follower.CurveRadius);
rs = (double)Math.Sign(Train.Cars[CarIndex].RearAxle.Follower.CurveRadius);
}
else
{
r = 0.0;
rs = 0.0;
}
// roll due to shaking
{
double a0 = Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngle;
double a1;
if (Train.Cars[CarIndex].Specs.CurrentRollShakeDirection != 0.0)
{
const double c0 = 0.03;
const double c1 = 0.15;
a1 = c1 * Math.Atan(c0 * Train.Cars[CarIndex].Specs.CurrentRollShakeDirection);
double d = 0.5 + Train.Cars[CarIndex].Specs.CurrentRollShakeDirection * Train.Cars[CarIndex].Specs.CurrentRollShakeDirection;
if (Train.Cars[CarIndex].Specs.CurrentRollShakeDirection < 0.0)
{
Train.Cars[CarIndex].Specs.CurrentRollShakeDirection += d * TimeElapsed;
if (Train.Cars[CarIndex].Specs.CurrentRollShakeDirection > 0.0) Train.Cars[CarIndex].Specs.CurrentRollShakeDirection = 0.0;
}
else
{
Train.Cars[CarIndex].Specs.CurrentRollShakeDirection -= d * TimeElapsed;
if (Train.Cars[CarIndex].Specs.CurrentRollShakeDirection < 0.0) Train.Cars[CarIndex].Specs.CurrentRollShakeDirection = 0.0;
}
}
else
{
a1 = 0.0;
}
double SpringAcceleration;
if (!Train.Cars[CarIndex].Derailed)
{
SpringAcceleration = 15.0 * Math.Abs(a1 - a0);
}
else
{
SpringAcceleration = 1.5 * Math.Abs(a1 - a0);
}
double SpringDeceleration = 0.25 * SpringAcceleration;
Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed += (double)Math.Sign(a1 - a0) * SpringAcceleration * TimeElapsed;
double x = (double)Math.Sign(Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed) * SpringDeceleration * TimeElapsed;
if (Math.Abs(x) < Math.Abs(Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed))
{
Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed -= x;
}
else
{
Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed = 0.0;
}
a0 += Train.Cars[CarIndex].Specs.CurrentRollDueToShakingAngularSpeed * TimeElapsed;
//.........这里部分代码省略.........
示例2: UpdateSpeeds
// update train passengers
// update speeds
private static void UpdateSpeeds(Train Train, double TimeElapsed)
{
if (Game.MinimalisticSimulation & Train == PlayerTrain)
{
// hold the position of the player's train during startup
for (int i = 0; i < Train.Cars.Length; i++)
{
Train.Cars[i].Specs.CurrentSpeed = 0.0;
Train.Cars[i].Specs.CurrentAccelerationOutput = 0.0;
}
return;
}
// update brake system
double[] DecelerationDueToBrake, DecelerationDueToMotor;
UpdateBrakeSystem(Train, TimeElapsed, out DecelerationDueToBrake, out DecelerationDueToMotor);
// calculate new car speeds
double[] NewSpeeds = new double[Train.Cars.Length];
for (int i = 0; i < Train.Cars.Length; i++)
{
double PowerRollingCouplerAcceleration;
// rolling on an incline
{
double a = Train.Cars[i].FrontAxle.Follower.WorldDirection.Y;
double b = Train.Cars[i].RearAxle.Follower.WorldDirection.Y;
PowerRollingCouplerAcceleration = -0.5 * (a + b) * Game.RouteAccelerationDueToGravity;
}
// friction
double FrictionBrakeAcceleration;
{
double v = Math.Abs(Train.Cars[i].Specs.CurrentSpeed);
double a = GetResistance(Train, i, ref Train.Cars[i].FrontAxle, v);
double b = GetResistance(Train, i, ref Train.Cars[i].RearAxle, v);
FrictionBrakeAcceleration = 0.5 * (a + b);
}
// power
double wheelspin = 0.0;
double wheelSlipAccelerationMotorFront;
double wheelSlipAccelerationMotorRear;
double wheelSlipAccelerationBrakeFront;
double wheelSlipAccelerationBrakeRear;
if (Train.Cars[i].Derailed)
{
wheelSlipAccelerationMotorFront = 0.0;
wheelSlipAccelerationBrakeFront = 0.0;
wheelSlipAccelerationMotorRear = 0.0;
wheelSlipAccelerationBrakeRear = 0.0;
}
else
{
wheelSlipAccelerationMotorFront = GetCriticalWheelSlipAccelerationForElectricMotor(Train, i,Train.Cars[i].FrontAxle.Follower.AdhesionMultiplier, Train.Cars[i].FrontAxle.Follower.WorldUp.Y,Train.Cars[i].Specs.CurrentSpeed);
wheelSlipAccelerationMotorRear = GetCriticalWheelSlipAccelerationForElectricMotor(Train, i,Train.Cars[i].RearAxle.Follower.AdhesionMultiplier, Train.Cars[i].RearAxle.Follower.WorldUp.Y,Train.Cars[i].Specs.CurrentSpeed);
wheelSlipAccelerationBrakeFront = GetCriticalWheelSlipAccelerationForFrictionBrake(Train, i,Train.Cars[i].FrontAxle.Follower.AdhesionMultiplier, Train.Cars[i].FrontAxle.Follower.WorldUp.Y,Train.Cars[i].Specs.CurrentSpeed);
wheelSlipAccelerationBrakeRear = GetCriticalWheelSlipAccelerationForFrictionBrake(Train, i,Train.Cars[i].RearAxle.Follower.AdhesionMultiplier, Train.Cars[i].RearAxle.Follower.WorldUp.Y,Train.Cars[i].Specs.CurrentSpeed);
}
if (DecelerationDueToMotor[i] == 0.0)
{
double a;
if (Train.Cars[i].Specs.IsMotorCar)
{
if (DecelerationDueToMotor[i] == 0.0)
{
if (Train.Specs.CurrentReverser.Actual != 0 & Train.Specs.CurrentPowerNotch.Actual > 0 & !Train.Specs.CurrentHoldBrake.Actual & !Train.Specs.CurrentEmergencyBrake.Actual)
{
// target acceleration
a = GetAccelerationOutput(Train, i, Train.Specs.CurrentPowerNotch.Actual - 1, (double)Train.Specs.CurrentReverser.Actual * Train.Cars[i].Specs.CurrentSpeed);
// readhesion device
if (a > Train.Cars[i].Specs.ReAdhesionDevice.MaximumAccelerationOutput)
{
a = Train.Cars[i].Specs.ReAdhesionDevice.MaximumAccelerationOutput;
}
// wheel slip
if (a < wheelSlipAccelerationMotorFront)
{
Train.Cars[i].FrontAxle.CurrentWheelSlip = false;
}
else
{
Train.Cars[i].FrontAxle.CurrentWheelSlip = true;
wheelspin += (double)Train.Specs.CurrentReverser.Actual * a * Train.Cars[i].Specs.MassCurrent;
}
if (a < wheelSlipAccelerationMotorRear)
{
Train.Cars[i].RearAxle.CurrentWheelSlip = false;
}
else
{
Train.Cars[i].RearAxle.CurrentWheelSlip = true;
wheelspin += (double)Train.Specs.CurrentReverser.Actual * a * Train.Cars[i].Specs.MassCurrent;
}
// readhesion device
{
if (Game.SecondsSinceMidnight >= Train.Cars[i].Specs.ReAdhesionDevice.NextUpdateTime)
{
double d = Train.Cars[i].Specs.ReAdhesionDevice.UpdateInterval;
double f = Train.Cars[i].Specs.ReAdhesionDevice.ApplicationFactor;
double t = Train.Cars[i].Specs.ReAdhesionDevice.ReleaseInterval;
//.........这里部分代码省略.........