public static double WheelTurnForEndZeroWheelTurn(this PCar car, double finalAngle, double sign) { PCar physicCar = new PCar(car); int ticks = (int)Math.Abs(Math.Round(physicCar.WheelTurn / game.CarWheelTurnChangePerTick)); physicCar.setWheelTurn(0); physicCar.Iteration(ticks); double angleDeviation = finalAngle.AngleDeviation(physicCar.Angle); if (sign < 0) { Vector v = Vector.sincos(finalAngle + Math.PI); double inverse90Angle = Math.Abs(v.X) > Math.Abs(v.Y) ? ((Math.Sign(v.X) - 1) * Math.PI / 2) : (Math.Sign(v.Y) * Math.PI / 2); if (Math.Abs(Math.Abs(v.X) - Math.Abs(v.Y)) < 1.0e-3)//45 { inverse90Angle = v.Angle; } double angleSub = inverse90Angle.AngleDeviation(physicCar.Angle); angleDeviation = finalAngle.AngleDeviation(physicCar.Angle + 2 * angleSub); } if (Math.Abs(angleDeviation) < game.CarRotationFrictionFactor) { return(0); } return(car.WheelTurn + game.CarWheelTurnChangePerTick * Math.Sign(angleDeviation)); }
/// avoid map crash private HashSet <IPhysicEvent> calculateAvoidMapCrashEvents(Move currentMove) { HashSet <IPhysicEvent> pEvents = new HashSet <IPhysicEvent> { new MapCrashEvent() }; if (null != moverSelfMapCrashEvent) { pEvents.Add(moverSelfMapCrashEvent.Copy()); } if (null != passageLineEvent) { pEvents.Add(passageLineEvent.Copy()); } PCar physicCar = new PCar(car, game); physicCar.setEnginePower(currentMove.EnginePower); physicCar.setWheelTurn(0);//currentMove.WheelTurn physicCar.setBrake(currentMove.IsBrake); PhysicEventsCalculator.calculateEvents(physicCar, new MoveWithOutChange(), pEvents, calculateAvoidSideCrashEventCheckEnd); return(pEvents); }
public static PCar GetZeroWheelTurnCar(this PCar car) { PCar physicCar = new PCar(car); int ticks = (int)Math.Abs(Math.Round(physicCar.WheelTurn / game.CarWheelTurnChangePerTick)); physicCar.setWheelTurn(0); physicCar.Iteration(ticks); return(physicCar); }
public static double WheelTurnForEndZeroWheelTurn(this PCar car, Vector finalPos, double sign) { PCar physicCar = new PCar(car); int ticks = (int)Math.Abs(Math.Round(physicCar.WheelTurn / game.CarWheelTurnChangePerTick)); physicCar.setWheelTurn(0); physicCar.Iteration(ticks); double finalAngle = (finalPos - car.Pos).Angle; return(car.WheelTurnForEndZeroWheelTurn(finalAngle, sign)); }
public void Iteration(PCar car, int iterationCount) { for (int i = 0; i < iterationCount; i++) { if (intersecOildStickEvent.Check(car)) { car.traveledOnOil(intersecOildStickEvent.InfoForCheck as OilSlick); } double speedSign = Math.Sign(car.Dir.Dot(car.Speed)); double wheelTurn = car.WheelTurnForEndZeroWheelTurn(angle, speedSign); car.setWheelTurn(wheelTurn); car.Iteration(1); } }
public void Iteration(PCar car, int iterationCount) { for (int i = 0; i < iterationCount; i++) { if (intersecOildStickEvent.Check(car)) { car.traveledOnOil(intersecOildStickEvent.InfoForCheck as OilSlick); } double speedSign = Math.Sign(car.Dir.Dot(car.Speed)); if (double.IsNaN(finalAngle)) { car.WheelTurnForEndZeroWheelTurn(point, speedSign); } else { car.setWheelTurn(car.WheelTurnForEndZeroWheelTurnToPoint(point, finalAngle, speedSign)); } car.Iteration(1); } }