private bool fastMove(motorBase motor) { TimeSpan ts = befTime - DateTime.UtcNow; double diffAngle = MathHelperD.ToDegrees(motor.targetRadians) - MathHelperD.ToDegrees(motor.motorRadian); double rad = MathHelperD.ToRadians(diffAngle) / (-0.03); if (targetRPM < Math.Abs(rad * 9.549)) { MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? targetRPM : -targetRPM; } else { motor.MyMotor.TargetVelocityRad = -(float)(rad / 2); } befTime = DateTime.UtcNow; motor.befRadian = motor.motorRadian; if (Math.Abs(MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.targetRadians)) < 0.5) { motor.MyMotor.TargetVelocityRad = 0; return(true); } else { return(false); } }
public void HingeKnee() { float velocity = 2f; if (R1Flg == 0) { if (MathHelperD.ToDegrees(myMotorR1.Angle) > -20) { MorterMoveToAngle(myMotorR2, 80, velocity * 2); } else { MorterMoveToAngle(myMotorR2, 10, velocity * 2); } } else { } if (L1Flg == 0) { if (MathHelperD.ToDegrees(myMotorL1.Angle) < 20) { MorterMoveToAngle(myMotorL2, 80, velocity * 2); } else { MorterMoveToAngle(myMotorL2, 10, velocity * 2); } } else { } }
public void ThrustToVelocity(Vector3D velocity) { if (thrustPidController == null) { throw new Exception("wat de neuk thrustPid is null"); } if (thrustControl == null) { throw new Exception("wat de neuk thrustControl is null"); } if (ingameTime == null) { throw new Exception("wat de neuk ingameTime is null"); } Vector3D difference = velocity - ControlVelocity; double differenceMag = difference.Normalize(); double percent = thrustPidController.NextValue(differenceMag, (lastTime - ingameTime.Time).TotalSeconds); percent = MathHelperD.Clamp(percent, 0, 1); thrustControl.ApplyForce(difference, percent); lastTime = ingameTime.Time; }
public bool Update() { //time = distance / rate double rate = MathHelperD.Clamp(lastValue - shipData[Data.Hydrogen].Value, 0, double.MaxValue) / (p.Time - lastTime).TotalSeconds; //rate = amount / time double distance = shipData[Data.Hydrogen].Value; double time = distance / rate; values[index] = time; index++; if (index >= VALUES) { index = 0; } val = values.Average(); lastValue = shipData[Data.Hydrogen].Value; lastTime = p.Time; if (double.IsNaN(val)) { val = 0; } if (val != Value) { Value = val; return(true); } return(false); }
internal Matrix CreateRotation(double x, double y, double z) { var rotation = MatrixD.Zero; if (x > 0 || x < 0) { rotation = MatrixD.CreateRotationX(MathHelperD.ToRadians(x)); } if (y > 0 || y < 0) { if (x > 0 || x < 0) { rotation *= MatrixD.CreateRotationY(MathHelperD.ToRadians(y)); } else { rotation = MatrixD.CreateRotationY(MathHelperD.ToRadians(y)); } } if (z > 0 || z < 0) { if (x > 0 || x < 0 || y > 0 || y < 0) { rotation *= MatrixD.CreateRotationZ(MathHelperD.ToRadians(z)); } else { rotation = MatrixD.CreateRotationZ(MathHelperD.ToRadians(z)); } } return(rotation); }
Program() { _guns = new List <IMyUserControllableGun>(); _controllers = new List <IMyRemoteControl>(); GridTerminalSystem.GetBlocksOfType(_guns); GridTerminalSystem.GetBlocksOfType(_controllers); _currentControl = _controllers.FirstOrDefault(c => c.IsFunctional); if (_currentControl == null) { return; } if (string.IsNullOrEmpty(Storage)) { if (!Vector3D.TryParse(Storage, out _origin)) { _origin = _currentControl.GetPosition(); } } else { _origin = _currentControl.GetPosition(); Storage = _origin.ToString(); } _weaponAngle = Math.Cos(MathHelperD.ToRadians(WEAPON_ANGLE_LIMIT)); }
private bool fastMove(motorBase motor) { TimeSpan ts = befTime - DateTime.UtcNow; //double ang = (motor.Angle - motor.BefAngle); double diffAngle = motor.TargetAngle - motor.Angle; double rad = MathHelperD.ToRadians(diffAngle) / (-0.03); // motor.MyMotor.TargetVelocityRad = -(float)(rad / 5); if (TargetRPM < Math.Abs(rad * 9.549)) { MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? TargetRPM : -TargetRPM; } else { motor.MyMotor.TargetVelocityRad = -(float)(rad / 2); } befTime = DateTime.UtcNow; motor.BefAngle = motor.Angle; if (Math.Abs(motor.Angle - motor.TargetAngle) < 0.5) { motor.MyMotor.TargetVelocityRad = 0; return(true); } else { return(false); } }
private Vector3D GetSmartLosPosition(int i, ref Dummy.DummyInfo info, int degrees) { double angle = MathHelperD.ToRadians(degrees); var perpDir = Vector3D.CalculatePerpendicularVector(info.Direction); Vector3D up; Vector3D.Normalize(ref perpDir, out up); Vector3D right; Vector3D.Cross(ref info.Direction, ref up, out right); var offset = Math.Tan(angle); // angle better be in radians var destPos = info.Position; switch (i) { case 0: return(destPos + (info.Direction * Comp.Ai.GridVolume.Radius)); case 1: return(destPos + ((info.Direction + up * offset) * Comp.Ai.GridVolume.Radius)); case 2: return(destPos + ((info.Direction - up * offset) * Comp.Ai.GridVolume.Radius)); case 3: return(destPos + ((info.Direction + right * offset) * Comp.Ai.GridVolume.Radius)); case 4: return(destPos + ((info.Direction - right * offset) * Comp.Ai.GridVolume.Radius)); } return(Vector3D.Zero); }
private bool justMove(motorBase motor) { TimeSpan ts = befTime - nowTime; double ang = (MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.befRadian)); double diffAngle = MathHelperD.ToDegrees(motor.targetRadians) - MathHelperD.ToDegrees(motor.motorRadian); double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds; if (diffAngle > rad) { motor.MyMotor.TargetVelocityRPM = motor.targetRPM; } else { motor.MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2)); } motor.befRadian = motor.motorRadian; if ((MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.targetRadians)) < 0.5) { return(true); } else { return(false); } }
private bool justMove(motorBase motor) { TimeSpan ts = befTime - nowTime; double ang = (motor.Angle - motor.BefAngle); double diffAngle = motor.TargetAngle - motor.Angle; double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds; if (diffAngle > rad) { motor.MyMotor.TargetVelocityRPM = motor.TargetRPM; } else { motor.MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2)); } motor.BefAngle = motor.Angle; if ((motor.Angle - motor.TargetAngle) < 0.5) { return(true); } else { return(false); } }
private bool fastMove() { TimeSpan ts = befTime - DateTime.UtcNow; //double ang = (motor.Angle - motor.BefAngle); double diffAngle = DataEntity.GetTargetAngle() - MathHelperD.ToDegrees(MyMotor.Angle); double rad = MathHelperD.ToRadians(diffAngle) / (-0.03); if (DataEntity.GetVelocity() < Math.Abs(rad * 9.549)) { MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? DataEntity.GetVelocity() : -DataEntity.GetVelocity(); } else { MyMotor.TargetVelocityRad = -(float)(rad / 2); } befTime = DateTime.UtcNow; BefAngleDegree = MathHelperD.ToDegrees(MyMotor.Angle); if (Math.Abs(MathHelperD.ToDegrees(MyMotor.Angle) - DataEntity.GetTargetAngle()) < 1) { MyMotor.TargetVelocityRad = 0; return(true); } else { return(false); } }
/// <summary> /// Calculates the output value of a PID loop, given an error and a time step. /// </summary> /// <param name="error">The difference between the Desired and Actual measurement.</param> /// <param name="timeStep">How long it's been since this method has been called (in seconds).</param> /// <returns>The value needed to correct the difference in measurement.</returns> public double CorrectError(double error, double timeStep) { // Derivative term double dInput = error - _lastError; double errorDerivative = _firstRun ? 0 : dInput / timeStep; // Integral term if (!_useIntegralDecay) { _errorIntegral += error * timeStep; _errorIntegral = MathHelperD.Clamp(_errorIntegral, _minOutput, _maxOutput); } else { _errorIntegral = (_errorIntegral * _integralDecay) + (error * timeStep); } // Compute the output double output = _Kp * error + _Ki * _errorIntegral + _Kd * errorDerivative; // Save the error for the next use _lastError = error; _firstRun = false; return(output); }
private bool justMove() { TimeSpan ts = befTime - nowTime; double ang = (MathHelperD.ToDegrees(MyMotor.Angle) - BefAngleDegree); double diffAngle = DataEntity.GetTargetAngle() - (MathHelperD.ToDegrees(MyMotor.Angle)); double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds; if (diffAngle > rad) { MyMotor.TargetVelocityRPM = DataEntity.GetVelocity(); } else { MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2)); } BefAngleDegree = MathHelperD.ToDegrees(MyMotor.Angle); if ((MathHelperD.ToDegrees(MyMotor.Angle) - DataEntity.GetTargetAngle()) < 0.5) { MyMotor.TargetVelocityRad = 0; return(true); } else { return(false); } }
private bool fastMove(motorBase motor) { TimeSpan ts = befTime - DateTime.UtcNow; //double ang = (motor.Angle - motor.BefAngle); double diffAngle = motor.TargetAngle - motor.Angle; double rad = MathHelperD.ToRadians(diffAngle) / (-0.02); motor.MyMotor.TargetVelocityRad = -(float)(rad / 5); befTime = DateTime.UtcNow; motor.BefAngle = motor.Angle; if (Math.Abs(motor.Angle - motor.TargetAngle) < 0.5) { motor.MyMotor.TargetVelocityRad = 0; return(true); } else { return(false); } }
/// <summary> /// PRONAV /// </summary> /// <param name="target"></param> /// <returns>Heading we need to aim at</returns> public Vector3D Navigate(HaE_Entity target) { Vector3D targetpos = target.entityInfo.Position; if (target.entityInfo.HitPosition.HasValue) { targetpos = target.entityInfo.HitPosition.Value; } Vector3D myVel = controller.control.GetShipVelocities().LinearVelocity; Vector3D rangeVec = targetpos - controller.control.GetPosition(); Vector3D closingVel = target.entityInfo.Velocity - myVel; Vector3D accel = CalculateAccel(rangeVec, closingVel); accel += -controller.control.GetNaturalGravity(); //Gravity term double maxForwardAccel = ThrustUtils.GetForwardThrust(controller.thrusters, controller.control); maxForwardAccel /= controller.control.CalculateShipMass().PhysicalMass; double forwardAccel = maxForwardAccel; double accelMag = accel.Normalize(); forwardAccel -= accelMag; forwardAccel = MathHelperD.Clamp(forwardAccel, 0, maxForwardAccel); accel *= accelMag; accel += Vector3D.Normalize(rangeVec) * forwardAccel; return(accel); }
/* * /// Whip's Get Rotation Angles Method v14 - 9/25/18 /// * Dependencies: AngleBetween */ internal static double AngleBetween(Vector3D a, Vector3D b) //returns radians { if (Vector3D.IsZero(a) || Vector3D.IsZero(b)) { return(0); } return(Math.Acos(MathHelperD.Clamp(a.Dot(b) / Math.Sqrt(a.LengthSquared() * b.LengthSquared()), -1, 1))); }
public void HingeControl() { str += "myMotorR1:" + MathHelperD.ToDegrees(myMotorR1.Angle).ToString() + " \r\n"; str += "myMotorR2:" + MathHelperD.ToDegrees(myMotorR2.Angle).ToString() + " \r\n"; str += "myMotorR3:" + MathHelperD.ToDegrees(myMotorR3.Angle).ToString() + " \r\n"; str += "myMotorL1:" + MathHelperD.ToDegrees(myMotorL1.Angle).ToString() + " \r\n"; str += "myMotorL2:" + MathHelperD.ToDegrees(myMotorL2.Angle).ToString() + " \r\n"; str += "myMotorL3:" + MathHelperD.ToDegrees(myMotorL3.Angle).ToString() + " \r\n"; }
public motorBase(IMyMotorStator moter, bool reverseFlg, float targetAngle, float targetRpm) { MyMotor = moter; MyMotor_reverse = reverseFlg; targetRadians = MathHelperD.ToRadians(targetAngle); targetRPM = targetRpm; nowTime = DateTime.UtcNow; befTime = DateTime.UtcNow; }
public double Update(double error, TimeSpan sincelastupdate) { double dt = sincelastupdate.TotalSeconds; diff_error = (error - last_error) / dt; accum_error += error * dt; last_error = error; double value = P * error + I * accum_error + D * diff_error; return(MathHelperD.Clamp(value, Min, Max)); }
public void ThrustToVelocity(Vector3D velocity) { Vector3D difference = velocity - ControlVelocity; double differenceMag = difference.Normalize(); double percent = thrustPidController.NextValue(differenceMag, (lastTime - ingameTime.Time).TotalSeconds); percent = MathHelperD.Clamp(percent, 0, 1); thrustControl.ApplyForce(difference, percent); lastTime = ingameTime.Time; }
public static double GetAngleBetween(Vector3D a, Vector3D b) { if (Vector3D.IsZero(a) || Vector3D.IsZero(b)) { return(0); } if (Vector3D.IsUnit(ref a) && Vector3D.IsUnit(ref b)) { return(Math.Acos(MathHelperD.Clamp(a.Dot(b), -1, 1))); } return(Math.Acos(MathHelperD.Clamp(a.Dot(b) / Math.Sqrt(a.LengthSquared() * b.LengthSquared()), -1, 1))); }
public void Apply(float pitch, float yaw, float roll, float dT, bool killRot = false, Vector3D?error = null) { var inputVec = new Vector3D(-pitch, yaw, roll) * dT; var rotationVec = new Vector3D(); inputVec.X += reference.RotationIndicator.X * dT * 100; inputVec.Y += reference.RotationIndicator.Y * dT * 100; inputVec.Z += reference.RollIndicator * dT * 100; rotationVec += inputVec; if (killRot) { KillRotError += AngularVelocity * 200 * dT; if (KillRotError.Length() < .1) { KillRotError *= 0; } rotationVec += new Vector3D( MathHelperD.Clamp(KillRotError.X, -100, 100), MathHelperD.Clamp(KillRotError.Y, -100, 100), MathHelperD.Clamp(KillRotError.Z, -100, 100)); KillRotError += inputVec; KillRotError *= 0.7f; } if (error.HasValue) { gravController.currentError.X = error.Value.X - pitch; gravController.currentError.Y = error.Value.Y - yaw; gravController.currentError.Z = error.Value.Z + roll; gravController.Step(dT); rotationVec += gravController.output; } bool applyOverride = inputVec.Length() > 0 || killRot && KillRotError.Length() != 0; rotationVec *= MathHelper.RadiansPerSecondToRPM; rotationVec.X = MathHelper.Clamp(rotationVec.X, -300, 300); rotationVec.Y = MathHelper.Clamp(rotationVec.Y, -300, 300); rotationVec.Z = MathHelper.Clamp(rotationVec.Z, -300, 300); foreach (var tuple in gyrosToControl) { var gyro = tuple.Value; if (applyOverride) { var rotation = Vector3.TransformNormal(rotationVec, tuple.Key); gyro.Pitch = rotation.X; gyro.Yaw = rotation.Y; gyro.Roll = rotation.Z; } gyro.GyroOverride = applyOverride; } }
internal void DrawLineOffsetEffect(Vector3D pos, Vector3D direction, double tracerLength, float beamRadius, Vector4 color) { MatrixD matrix; var up = MatrixD.Identity.Up; var startPos = pos + -(direction * tracerLength); MatrixD.CreateWorld(ref startPos, ref direction, ref up, out matrix); var offsetMaterial = AmmoDef.Const.TracerMaterial; var tracerLengthSqr = tracerLength * tracerLength; var maxOffset = AmmoDef.AmmoGraphics.Lines.OffsetEffect.MaxOffset; var minLength = AmmoDef.AmmoGraphics.Lines.OffsetEffect.MinLength; var maxLength = MathHelperD.Clamp(AmmoDef.AmmoGraphics.Lines.OffsetEffect.MaxLength, 0, tracerLength); double currentForwardDistance = 0; while (currentForwardDistance < tracerLength) { currentForwardDistance += MyUtils.GetRandomDouble(minLength, maxLength); var lateralXDistance = MyUtils.GetRandomDouble(maxOffset * -1, maxOffset); var lateralYDistance = MyUtils.GetRandomDouble(maxOffset * -1, maxOffset); Offsets.Add(new Vector3D(lateralXDistance, lateralYDistance, currentForwardDistance * -1)); } for (int i = 0; i < Offsets.Count; i++) { Vector3D fromBeam; Vector3D toBeam; if (i == 0) { fromBeam = matrix.Translation; toBeam = Vector3D.Transform(Offsets[i], matrix); } else { fromBeam = Vector3D.Transform(Offsets[i - 1], matrix); toBeam = Vector3D.Transform(Offsets[i], matrix); } Vector3 dir = (toBeam - fromBeam); var length = dir.Length(); var normDir = dir / length; MyTransparentGeometry.AddLineBillboard(offsetMaterial, color, fromBeam, normDir, length, beamRadius); if (Vector3D.DistanceSquared(matrix.Translation, toBeam) > tracerLengthSqr) { break; } } Offsets.Clear(); }
internal void Init(ProInfo info, double firstStepSize, double maxSpeed) { System = info.System; AmmoDef = info.AmmoDef; Ai = info.Ai; IsShrapnel = info.IsShrapnel; if (ParentId != ulong.MaxValue) { Log.Line($"invalid avshot, parentId:{ParentId}"); } ParentId = info.Id; Model = (info.AmmoDef.Const.PrimeModel || info.AmmoDef.Const.TriggerModel) ? Model = ModelState.Exists : Model = ModelState.None; PrimeEntity = info.PrimeEntity; TriggerEntity = info.TriggerEntity; Origin = info.Origin; Offset = AmmoDef.Const.OffsetEffect; MaxTracerLength = info.TracerLength; MuzzleId = info.MuzzleId; WeaponId = info.WeaponId; MaxSpeed = maxSpeed; MaxStepSize = MaxSpeed * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; ShootVelStep = info.ShooterVel * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; info.Ai.WeaponBase.TryGetValue(info.Target.FiringCube, out FiringWeapon); MaxTrajectory = info.MaxTrajectory; ShotFade = info.ShotFade; ShrinkInited = false; HitEmitter.CanPlayLoopSounds = false; if (AmmoDef.Const.DrawLine) { Tracer = !AmmoDef.Const.IsBeamWeapon && firstStepSize < MaxTracerLength && !MyUtils.IsZero(firstStepSize - MaxTracerLength, 1E-01F) ? TracerState.Grow : TracerState.Full; } else { Tracer = TracerState.Off; } if (AmmoDef.Const.Trail) { MaxGlowLength = MathHelperD.Clamp(AmmoDef.AmmoGraphics.Lines.Trail.DecayTime * MaxStepSize, 0.1f, MaxTrajectory); Trail = AmmoDef.AmmoGraphics.Lines.Trail.Back ? TrailState.Back : Trail = TrailState.Front; GlowShrinkSize = !AmmoDef.AmmoGraphics.Lines.Trail.UseColorFade ? AmmoDef.Const.TrailWidth / AmmoDef.AmmoGraphics.Lines.Trail.DecayTime : 1f / AmmoDef.AmmoGraphics.Lines.Trail.DecayTime; Back = Trail == TrailState.Back; } else { Trail = TrailState.Off; } TotalLength = MathHelperD.Clamp(MaxTracerLength + MaxGlowLength, 0.1f, MaxTrajectory); }
public void Running() { float velocity = 2f; if (R1Flg == 0) { MorterMoveToAngle(myMotorR1, -80, velocity); } else if (R1Flg == 1) { MorterMoveToAngle(myMotorR1, 20, velocity); } if (L1Flg == 0) { MorterMoveToAngle(myMotorL1, 80, velocity); } else if (L1Flg == 1) { MorterMoveToAngle(myMotorL1, -20, velocity); } if (R1Flg == 0) { if (MathHelperD.ToDegrees(myMotorR1.Angle) > -20) { MorterMoveToAngle(myMotorR2, 80, velocity * 2); } else { MorterMoveToAngle(myMotorR2, 10, velocity * 2); } } if (L1Flg == 0) { if (MathHelperD.ToDegrees(myMotorL1.Angle) < 20) { MorterMoveToAngle(myMotorL2, 80, velocity * 2); } else { MorterMoveToAngle(myMotorL2, 10, velocity * 2); } } }
public void AimTarget_sensor(IMySensorBlock sensor) { string[] vs = RArm.myMotor1.MyMotor.CustomData.Split(','); var str = sensor.CustomData.Split(','); var vector = new Vector3D(double.Parse(str[0]), double.Parse(str[1]), double.Parse(str[2])); Vector3D worldDirection = vector - sensor.GetPosition(); Vector3D direction = Vector3D.TransformNormal(worldDirection, MatrixD.Transpose(sensor.WorldMatrix)); vs[1] = MathHelperD.ToDegrees(-Math.Atan2(direction.Z, direction.Y)).ToString(); RArm.myMotor1.MyMotor.CustomData = vs[0] + "," + vs[1] + ',' + vs[2]; vs = RArm.myMotor2.MyMotor.CustomData.Split(','); vs[1] = "0"; //MathHelperD.ToDegrees(Math.Atan2(direction.X, direction.Y)).ToString(); RArm.myMotor2.MyMotor.CustomData = vs[0] + "," + vs[1] + ',' + vs[2]; }
public void MorterMoveToAngle(IMyMotorStator motorStator, double TargetAngle, float velocity) { var angle = MathHelperD.ToDegrees(motorStator.Angle) - TargetAngle; if (Math.Abs(angle) < velocity) { motorStator.TargetVelocityRad = 0; } else if (MathHelperD.ToDegrees(motorStator.Angle) > TargetAngle) { motorStator.TargetVelocityRad = -velocity; } else if (MathHelperD.ToDegrees(motorStator.Angle) < TargetAngle) { motorStator.TargetVelocityRad = velocity; } }
internal void LineVariableEffects() { var color = AmmoDef.AmmoGraphics.Lines.Tracer.Color; if (AmmoDef.Const.LineColorVariance) { var cv = AmmoDef.AmmoGraphics.Lines.ColorVariance; var randomValue = MyUtils.GetRandomFloat(cv.Start, cv.End); color.X *= randomValue; color.Y *= randomValue; color.Z *= randomValue; } Color = color; var tracerWidth = AmmoDef.AmmoGraphics.Lines.Tracer.Width; var trailWidth = AmmoDef.Const.TrailWidth; if (AmmoDef.Const.LineWidthVariance) { var wv = AmmoDef.AmmoGraphics.Lines.WidthVariance; var randomValue = MyUtils.GetRandomFloat(wv.Start, wv.End); tracerWidth += randomValue; if (AmmoDef.AmmoGraphics.Lines.Trail.UseWidthVariance) { trailWidth += randomValue; } } var target = TracerFront + (-Direction * TotalLength); ClosestPointOnLine = MyUtils.GetClosestPointOnLine(ref TracerFront, ref target, ref Ai.Session.CameraPos); DistanceToLine = (float)Vector3D.Distance(ClosestPointOnLine, Ai.Session.CameraMatrix.Translation); if (AmmoDef.Const.IsBeamWeapon && Vector3D.DistanceSquared(TracerFront, TracerBack) > 640000) { target = TracerFront + (-Direction * (TotalLength - MathHelperD.Clamp(DistanceToLine * 6, DistanceToLine, MaxTrajectory * 0.5))); ClosestPointOnLine = MyUtils.GetClosestPointOnLine(ref TracerFront, ref target, ref Ai.Session.CameraPos); DistanceToLine = (float)Vector3D.Distance(ClosestPointOnLine, Ai.Session.CameraMatrix.Translation); } double scale = 0.1f; ScaleFov = Math.Tan(MyAPIGateway.Session.Camera.FovWithZoom * 0.5); TracerWidth = Math.Max(tracerWidth, scale * ScaleFov * (DistanceToLine / 100)); TrailWidth = Math.Max(trailWidth, scale * ScaleFov * (DistanceToLine / 100)); TrailScaler = ((float)TrailWidth / trailWidth); }
// check value, set random value if allowed and value not set protected float CheckValue(float value, bool randomize, float minValue, float maxValue, TimeSpan duration, string description) { // overcast if (value < 0 && randomize) { value = (random.Next((int)maxValue * 100) / 100); // ensure there is a value if range is 0 - 1 } else { float correctedValue = (float)MathHelperD.Clamp(value, minValue, maxValue); if (correctedValue != value) { Trace.TraceInformation("Invalid value for {0} for weather at {1} : {2}; value must be between {3} and {4}, clamped to {5}", description, duration.ToString(), value, minValue, maxValue, correctedValue); value = correctedValue; } } return(value); }
private double CalcAccelToStopAtPos(double deltaPos, double curSpd, double maxAccel, double posAccuracy, double AccelPerDeltaPosFactor) { double accel; double absDeltaPos = Math.Abs(deltaPos); //if (absDeltaPos >= posAccuracy) //{ int signDeltaPos = Math.Sign(deltaPos); if (Math.Sign(curSpd) != signDeltaPos) { //удаляемся или не движемся //accel = maxAccel * signDeltaPos; accel = MathHelperD.Clamp(AccelPerDeltaPosFactor * deltaPos * maxAccel, -maxAccel, maxAccel); ToLog("\nудаляемся", true); } else { //приближаемся, оценим тормозной путь double temp = 0.5 * curSpd * curSpd; double brakingDist = temp / maxAccel; ToLog("\nbrakingDist: " + brakingDist.ToString("#0.000"), true); if (absDeltaPos >= brakingDist) { //еще успеем затормозить, поэтому даем максимальное ускорение //accel = maxAccel * signDeltaPos; accel = MathHelperD.Clamp(AccelPerDeltaPosFactor * deltaPos * maxAccel, -maxAccel, maxAccel); ToLog("\nеще успеем: " + absDeltaPos.ToString("#0.00000") + " / " + brakingDist.ToString("#0.00000"), true); } else { //уменьшаем ускорение accel = -temp / deltaPos; ToLog("\nуменьш: " + accel.ToString("#0.000"), true); } } //} //else //{ // accel = AccelPerDeltaPosFactor * deltaPos * maxAccel; // ToLog("\n!!!",true); //} return(accel); }