public void TestCorrectResultsMotionRight() { ProjectileMotion motionRight = new ProjectileMotion( new ProjectileMotionSettings( new ProjectileMotionQuantities(V, new ElevationAngle(ElevationAngle.ElevationAngleTypes.Right), H, G, Utilities.UnitsOfResults) ) { PointsForTrajectory = UsePoints } ); Utilities.AlmostSame(motionRight.GetLength(), new Length(0, UnitLength.Basic)); Utilities.AlmostSame(motionRight.GetTimeFarthest(), motionRight.GetTimeHighest()); Utilities.AlmostSame(motionRight.GetMaxDistance(), new Length(motionRight.GetMaxHeight().GetBasicVal() - H.GetBasicVal(), UnitLength.Basic)); Utilities.AlmostSame(motionRight.GetMaxDistance(), motionRight.Trajectory.GetInitialPoint().GetDistanceFromPoint(motionRight.Trajectory.GetHighestPoint())); Utilities.AlmostSame(motionRight.Trajectory.GetArcLength(), new Length(2 * motionRight.GetMaxHeight().GetBasicVal() - H.GetBasicVal(), UnitLength.Basic)); Utilities.AlmostSame(motionRight.Trajectory.GetAreaUnderArc(), new Area(0, UnitArea.Basic)); Utilities.AlmostSame(motionRight.Trajectory.GetHighestPoint().Y, motionRight.GetMaxHeight()); Utilities.AlmostSame(motionRight.Trajectory.GetFarthestPoint().Y, motionRight.Trajectory.GetHighestPoint().Y); Utilities.AlmostSame(motionRight.Trajectory.GetFarthestPoint().X, motionRight.Trajectory.GetHighestPoint().X); Utilities.AlmostSame(motionRight.Trajectory.GetInitialPoint().X, motionRight.Trajectory.GetFinalPoint().X); Utilities.AlmostSame(motionRight.Trajectory.GetInitialPoint().Y, new Length(motionRight.Trajectory.GetFinalPoint().Y.GetBasicVal() + H.GetBasicVal(), UnitLength.Basic)); Utilities.AlmostSame(Utilities.GetTrajectoryLengthIteratively(motionRight), motionRight.Trajectory.GetArcLength()); Utilities.AlmostSame(Utilities.GetAreaUnderTrajectoryIteratively(motionRight), motionRight.Trajectory.GetAreaUnderArc()); Utilities.AlmostSame(Utilities.GetMaxHeightIteratively(motionRight), motionRight.GetMaxHeight()); Utilities.AlmostSame(Utilities.GetMaxDistanceIteratively(motionRight), motionRight.GetMaxDistance()); }
public void TestCorrectResultsMotionHorizontal() { ProjectileMotion motionHorizontal = new ProjectileMotion( new ProjectileMotionSettings( new ProjectileMotionQuantities(V, new ElevationAngle(ElevationAngle.ElevationAngleTypes.Horizontal), new InitialHeight(20, UnitLength.Metre), G, Utilities.UnitsOfResults) ) { PointsForTrajectory = UsePoints } ); Utilities.AlmostSame(motionHorizontal.GetTimeHighest(), new Time(0, UnitTime.Basic)); Utilities.AlmostSame(motionHorizontal.GetTimeHighest(), motionHorizontal.Trajectory.GetInitialPoint().T); Utilities.AlmostSame(motionHorizontal.GetMaxDistance(), motionHorizontal.Trajectory.GetInitialPoint().GetDistanceFromPoint(motionHorizontal.Trajectory.GetFinalPoint())); Utilities.AlmostSame(motionHorizontal.Trajectory.GetHighestPoint().Y, motionHorizontal.GetMaxHeight()); Utilities.AlmostSame(motionHorizontal.Trajectory.GetFarthestPoint().Y, motionHorizontal.Trajectory.GetFinalPoint().Y); Utilities.AlmostSame(motionHorizontal.Trajectory.GetFarthestPoint().X, motionHorizontal.Trajectory.GetFinalPoint().X); Utilities.AlmostSame(motionHorizontal.Trajectory.GetInitialPoint().X, motionHorizontal.Trajectory.GetHighestPoint().X); Utilities.AlmostSame(motionHorizontal.Trajectory.GetInitialPoint().Y, motionHorizontal.Trajectory.GetHighestPoint().Y); Utilities.AlmostSame(Utilities.GetTrajectoryLengthIteratively(motionHorizontal), motionHorizontal.Trajectory.GetArcLength()); Utilities.AlmostSame(Utilities.GetAreaUnderTrajectoryIteratively(motionHorizontal), motionHorizontal.Trajectory.GetAreaUnderArc()); Utilities.AlmostSame(Utilities.GetMaxHeightIteratively(motionHorizontal), motionHorizontal.GetMaxHeight()); Utilities.AlmostSame(Utilities.GetMaxDistanceIteratively(motionHorizontal), motionHorizontal.GetMaxDistance()); }
public void Play() { if (_isRunning) { Debug.LogWarning("Simulation is already running, can't play it."); } if (_isDone) { Debug.LogWarning("Simulation is done, can't play it."); } if (!_hasStarted) { projectileMotion = new ProjectileMotion(initData); currentData = projectileMotion.data; catapultController.JustThrow(); _hasStarted = true; } if (OnSimulationStart != null) { OnSimulationStart(); } trajectoryController.isRendering = true; _isRunning = true; }
public void GameTick(object sender, ElapsedEventArgs e) { _time++; var shells = State.AllShells.Where(s => !s.IsDead).ToList(); var projectileMotion = new ProjectileMotion(_time, GameParameters.GameLoopIntervalMilliseconds); shells.ForEach(projectileMotion.Calculate); var tanks = State.AllTanks; var activeShells = shells.Where(s => !s.IsDead).ToList(); var activeTanks = tanks.Where(t => !t.IsDead).ToList(); tanks.ForEach(t => t.IsDead |= t.IsHit); // kill off tanks that got hit from the prior tick if (_noKillPolicy.IsInKillTimeZone(GameParameters, _gameStopWatch.Elapsed)) { var collisionDetector = new CollisionDetector((p, s) => { p.Tank.Armour--; s.IsDead = true; if (p.Tank.Armour == 0) { p.Tank.IsHit = true; SetPlayerStatus(p, PlayerStatus.Dead); BroadcastMessage("'{0}' was killed by '{1}'", p.Tank.Name, s.Origin.Name); } else { BroadcastMessage("'{0}' was hit by '{1}'. Armour left={2}", p.Tank.Name, s.Origin.Name, p.Tank.Armour); } }); activeShells.ForEach(s => activeTanks.ForEach(t => collisionDetector.Detect(s, t))); } GetViewPortClients().Tick(State.ToViewPortState((GameParameters.ViewPortSize))); tanks.ForEach(t => t.IsFiring = false); if (activeTanks.Count < GameParameters.MinimumActiveTanks) { BroadcastMessage("Game over. {0} won", activeTanks.ToCsv(",", t => t.Name)); Stop(); } if (_gameStopWatch.ElapsedMilliseconds > GameParameters.MaximumGameTimeMinutes * 1000 * 60) { BroadcastMessage("Total allowed game time of {0} minutes elasped", GameParameters.MaximumGameTimeMinutes); Stop(); } }
public FileContentResult DataToCsv() { if (!CheckForExistingMotion()) { return(null); } ProjectileMotion SavedMotion = GetSession().GetSavedProjectileMotionWithOrWithoutResistance(); return(new ExportHelper(SavedMotion.Settings.CsvDataFileName, "application/CSV", SavedMotion.Saving.DataToCsvGetMemoryStream()).GetResultAsContentType()); }
public FileContentResult InfoToPdf() { if (!CheckForExistingMotion()) { return(null); } ProjectileMotion SavedMotion = GetSession().GetSavedProjectileMotionWithOrWithoutResistance(); return(new ExportHelper(SavedMotion.Settings.PdfInfoFileName, "application/pdf", SavedMotion.Saving.InfoToPdfGetMemoryStream()).GetResultAsContentType()); }
public void ShootRocket() { ProjectileMotion g_Rocket = Instantiate(Rocket, transform.position + 0.3f * transform.up, transform.rotation).GetComponent <ProjectileMotion>(); g_Rocket.transform.Rotate(0, 0, 90); g_Rocket.lifetime = RocketLifetime; // g_Rocket.transform.rotation = Angle; g_Rocket.speed = ProjectileSpeed; g_Rocket.Homing = Homing; g_Rocket.GetComponent <CircleCollider2D>().radius = HomingRadius; }
/// <summary> /// 在从池中取出后调用的初始化 /// オブジェクトプールから取ってからの実行メッソド /// </summary> /// <param name="target"></param> /// <param name="damage"></param> /// <param name="speed"></param> public void AfterTakedInitialize(IEnemy target, DamageMessage damage, float speed, System.Type type) { this.transform.position = damage.Damager.position; this.Target = target; this.DamageMessage = damage; this.Speed = speed; var angle = Vector3.Angle(damage.Damager.forward, damage.Damager.forward.SetValue(y: 0)); this.projectile = ProjectileMotion.CalculateVelocity(damage.Damager.position, target.Transform.position, angle); this.launcherType = type; this.AudioEmission.PlayRandomAudio(); }
public Length GetTrajectoryLengthIteratively(ProjectileMotion motion) { double trajectoryLength = 0; List <ProjectileMotionPoint> points = motion.Trajectory.GetPointsList(); for (int i = 0; i < points.Count - 1; i++) { trajectoryLength += points[i].GetDistanceFromPoint(points[i + 1]).GetBasicVal(); } return(new Length(trajectoryLength, UnitLength.Basic)); }
public Area GetAreaUnderTrajectoryIteratively(ProjectileMotion motion) { double areaUnderTrajectory = 0; List <ProjectileMotionPoint> points = motion.Trajectory.GetPointsList(); for (int i = 0; i < points.Count - 1; i++) { areaUnderTrajectory += (points[i + 1].X.GetBasicVal() - points[i].X.GetBasicVal()) * (points[i].Y.GetBasicVal() + points[i + 1].Y.GetBasicVal()) / 2; } return(new Area(areaUnderTrajectory, UnitArea.Basic)); }
public void AfterTakedInitialize(Vector3 target, DamageMessage damage, float speed, float range) { this.transform.position = damage.Damager.position; this.target = target; this.DamageMessage = damage; this.Speed = speed; this.ExplosionRange = range; var angle = Vector3.Angle(damage.Damager.forward, damage.Damager.forward.SetValue(y: 0)); this.projectile = ProjectileMotion.CalculateVelocity(damage.Damager.position, target, angle); this.AudioEmission.PlayRandomAudio(); }
public void Awake() { catapultController.JustReset(); ballBaseController.height = 0.0f; trajectoryController.isRendering = false; initData = new ProjectileMotionData(); currentData = initData; SetDefaultSettings(); projectileMotion = null; _hasStarted = false; _isRunning = false; _isDone = false; }
public ProjectileMotion NeglectResistance() { ProjectileMotion DegradedMotion = new ProjectileMotion(new ProjectileMotionSettings(Settings.Quantities) { RoundDigits = Settings.RoundDigits }); if (GetLength().Val > 0) { DegradedMotion.Settings.PointsForTrajectory = (int)(Settings.PointsForTrajectory * DegradedMotion.GetLength().Val / GetLength().Val); } return(DegradedMotion); }
static void Main() { InitialVelocity v = new InitialVelocity(40, UnitVelocity.KilometrePerHour); ElevationAngle α = new ElevationAngle(41, UnitAngle.Degree); InitialHeight h = new InitialHeight(169, UnitLength.Centimetre); GravAcceleration g = new GravAcceleration(GravAcceleration.GravAccelerations.Earth); ProjectileMotionResultsUnits units = new ProjectileMotionResultsUnits() { Length = UnitLength.Metre, Time = UnitTime.Second, Velocity = UnitVelocity.KilometrePerHour, Angle = UnitAngle.Degree, Area = UnitArea.SquareMetre, GravAcceleration = UnitGravAcceleration.MetrePerSquareSecond }; ProjectileMotion motion = new ProjectileMotion( new ProjectileMotionSettings(new ProjectileMotionQuantities(v, α, h, g, units)) { RoundDigits = 4, PathToFiles = "C:\\Users\\oplan\\Documents\\c#\\ProjectileMotions", PointsForTrajectory = 160 }); motion.Saving.InfoToTxt(); ProjectileMotionWithResistance motionWithResistance = new ProjectileMotionWithResistance( new ProjectileMotionWithResistanceSettings( new ProjectileMotionWithResistanceQuantities( v, α, h, g, new Mass(46, UnitMass.Gram), new Density(Density.Densities.Air), new FrontalArea(Math.Pow(new Length(12.9, UnitLength.Centimetre).GetBasicVal(), 2.0) * Math.PI, UnitArea.SquareMetre), new DragCoefficient(DragCoefficient.DragCoefficients.Sphere), units ) ) { RoundDigits = 4, PathToFiles = "C:\\Users\\oplan\\Documents\\c#\\ProjectileMotions", PointsForTrajectory = 153 }); motionWithResistance.Saving.InfoToTxt(); }
public Length GetMaxDistanceIteratively(ProjectileMotion motion) { double maxD = 0; foreach (ProjectileMotionPoint point in motion.Trajectory.GetPointsList()) { double d = point.GetDistance().GetBasicVal(); if (d > maxD) { maxD = d; } } return(new Length(maxD, UnitLength.Basic)); }
public Length GetMaxHeightIteratively(ProjectileMotion motion) { double maxH = motion.Trajectory.GetInitialPoint().Y.GetBasicVal(); foreach (ProjectileMotionPoint point in motion.Trajectory.GetPointsList()) { double y = point.Y.GetBasicVal(); if (y > maxH) { maxH = y; } } return(new Length(maxH, UnitLength.Basic)); }
public static IProjectileFactory GetProjectileFactory(ProjectileMotion projectileMotionType) { switch (projectileMotionType) { case ProjectileMotion.Straight: return(new StraightProjectileFactory()); break; case ProjectileMotion.Homing: return(new HomingProjectileFactory()); break; default: throw new ArgumentOutOfRangeException(nameof(projectileMotionType), projectileMotionType, null); } }
public float CalculateDistance(List <EventData> data) { // find max velocity float v = data.Max(d => d.V); // calculate launch angles var aa = ProjectileMotion.GetLaunchAngle(POST_X, POST_Y, v); // if both angles are nan - the kick failed if (aa.Length < 2) { return(0); } if ((aa[0] == float.NaN) && (aa[1] == float.NaN)) { return(0); } // if either is nan then use the other if ((aa[0] == float.NaN) || (aa[1] == float.NaN)) { var a = (aa[0] == float.NaN) ? aa[1] : aa[0]; var d = ProjectileMotion.GetDistance(v, a); return((d == float.NaN) ? 0 : d); } else { float a = (float)Math.Round(Math.Min(aa[0], aa[1]), 1), aMax = (float)Math.Round(Math.Max(aa[0], aa[1]), 1); // find max distance float dLast = 0; while (a < aMax) { var d = ProjectileMotion.GetDistance(v, a); if (d > dLast) { dLast = d; } if (d < dLast) { return(d); } a += TENTH_DEGREE; } return(dLast); } }
public void TestCorrectResultsMotionLow() { ProjectileMotion motion = new ProjectileMotion( new ProjectileMotionSettings( new ProjectileMotionQuantities(V, Α, H, G, Utilities.UnitsOfResults) ) { PointsForTrajectory = UsePoints } ); Utilities.AlmostSame(motion.GetDur(), Dur); Utilities.AlmostSame(motion.GetLength(), Len); Utilities.AlmostSame(motion.GetMaxHeight(), MaxH); Utilities.AlmostSame(Utilities.GetTrajectoryLengthIteratively(motion), motion.Trajectory.GetArcLength()); Utilities.AlmostSame(Utilities.GetAreaUnderTrajectoryIteratively(motion), motion.Trajectory.GetAreaUnderArc()); Utilities.AlmostSame(Utilities.GetMaxHeightIteratively(motion), motion.GetMaxHeight()); Utilities.AlmostSame(Utilities.GetMaxDistanceIteratively(motion), motion.GetMaxDistance()); }
public void TestCorrectResultsMotionHigh() { ProjectileMotion motion = new ProjectileMotion( new ProjectileMotionSettings( new ProjectileMotionQuantities(V, new ElevationAngle(82, UnitAngle.Degree), H, G, Utilities.UnitsOfResults) ) { PointsForTrajectory = UsePoints } ); Utilities.AlmostSame(Utilities.GetTrajectoryLengthIteratively(motion), motion.Trajectory.GetArcLength()); Utilities.AlmostSame(Utilities.GetAreaUnderTrajectoryIteratively(motion), motion.Trajectory.GetAreaUnderArc()); Utilities.AlmostSame(Utilities.GetMaxHeightIteratively(motion), motion.GetMaxHeight()); Utilities.AlmostSame(Utilities.GetMaxDistanceIteratively(motion), motion.GetMaxDistance()); Assert.IsTrue(motion.GetMaxDistance() > motion.Trajectory.GetFinalPoint().GetDistanceFromPoint(motion.Trajectory.GetInitialPoint())); Assert.IsTrue(motion.GetTimeFarthest() > motion.GetTimeHighest()); Assert.IsTrue(motion.Trajectory.GetFarthestPoint().Y < motion.Trajectory.GetHighestPoint().Y); }
public void Reset() { _isDone = false; _isRunning = false; _hasStarted = false; trajectoryController.isRendering = false; ballTransform.localPosition = new Vector3(initData.xPos, initData.yPos, initData.zPos); ballBaseController.height = initData.yPos; catapultController.JustReset(); projectileMotion = null; currentData = initData; if (OnSimulationReset != null) { OnSimulationReset(); } }
public void TestCorrectResultsMotionsDetailed() { double[] aValues = new double[] { 85, 0, 22, 30, 45, 67, 78, 90 }; double[] vValues = new double[] { 54, 0, 12, 31, 60, 120, 400 }; double[] hValues = new double[] { 0, 5, 14, 20, 60, 131, 225 }; foreach (double a in aValues) { foreach (double h in hValues) { foreach (double v in vValues) { ProjectileMotion motion = new ProjectileMotion( new ProjectileMotionSettings( new ProjectileMotionQuantities( new InitialVelocity(v, UnitVelocity.KilometrePerHour), new ElevationAngle(a, UnitAngle.Degree), new InitialHeight(h, UnitLength.Metre), G, Utilities.UnitsOfResults ) ) { PointsForTrajectory = UsePoints } ); string additionalMessage = string.Format( "Used values: {0} °, {1} km/h, {2} m.", a, v, h ); Utilities.AlmostSame(Utilities.GetAreaUnderTrajectoryIteratively(motion), motion.Trajectory.GetAreaUnderArc(), additionalMessage); Utilities.AlmostSame(Utilities.GetMaxHeightIteratively(motion), motion.GetMaxHeight(), additionalMessage); Utilities.AlmostSame(Utilities.GetTrajectoryLengthIteratively(motion), motion.Trajectory.GetArcLength(), additionalMessage); Utilities.AlmostSame(Utilities.GetMaxDistanceIteratively(motion), motion.GetMaxDistance(), additionalMessage); } } } }
public ActionResult Motion(bool ShowLargerMotionChart = false) { ProjectileMotion motion = GetSession().GetSavedProjectileMotion(); if (motion == null) { return(DefaultRedirect()); } return(View(new DisplayMotionModel(motion, ShowLargerMotionChart) { Layout = new LayoutModel("Projectile motion") { FluidContainer = true, Menu = new LayoutMenuModel() { ActiveMenuItem = LayoutMenuModel.ActiveNavItem.MotionDropdown, SetWithResistance = false } }, })); }
public _MotionInformationModel(ProjectileMotion motion) { Motion = motion; }
internal ProjectileMotionFilesSaving(ProjectileMotion motion) { Motion = motion; }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody>(); motion = GetComponent <ProjectileMotion>(); }
public _MotionChartModel(ProjectileMotionWithResistance motion) { Motion = motion; DegradedMotion = motion.NeglectResistance(); ShowMotionWithoutResistanceTrajectoryToo = motion.Settings.ShowMotionWithoutResistanceTrajectoryToo; }
public _MotionChartModel(ProjectileMotion motion) { Motion = motion; DegradedMotion = null; ShowMotionWithoutResistanceTrajectoryToo = false; }
public DisplayMotionModel(ProjectileMotion motion, bool showLargerMotionChart) : base(showLargerMotionChart) { Motion = motion; }
public SessionStore SaveProjectileMotion(ProjectileMotion motion) { GetSessionBase()[SessionStoreConstants.PROJECTILEMOTION] = motion; return(this); }