Ejemplo n.º 1
0
        public void Tick(object s, EventArgs e)
        {
            foreach (var movingObject in _objects.Rockets)
            {
                movingObject.DragForces    = new List <Force>();
                movingObject.GravityForces = new List <Force>();

                foreach (var gravityObject in _objects.Terrains)
                {
                    var distance = PointCalculator.Distance(movingObject.Location, gravityObject.Location);
                    var angle    = PointCalculator.CalculateAngle(movingObject.Location, gravityObject.Location);
                    var force    = GravityCalculator.CalculateGravity(movingObject.Mass, gravityObject.Mass, distance, angle);
                    movingObject.GravityForces.Add(force);

                    var altitude = distance - gravityObject.Diameter;
                    if (altitude < 100000)
                    {
                        // Drag Relevant
                        var rocketForceAngle   = movingObject._angle;
                        var dragAngle          = Angle.FromDegrees(movingObject.Speed.Angle.Degree + 180);
                        var speedDirectionDiff =
                            Angle.FromDegrees(rocketForceAngle.Degree - movingObject.Speed.Angle.Degree);
                        var cd        = movingObject.Drag.GetDragCoefficient(speedDirectionDiff);
                        var a         = movingObject.Drag.GetArea(speedDirectionDiff);
                        var p         = AtmosphereCalculator.CalculateAirDensityAtAltitude(altitude);
                        var dragForce = DragCalculator.CalculateDrag(dragAngle, cd, p, movingObject.Speed, a);
                        movingObject.DragForces.Add(dragForce);
                    }
                }
                movingObject.Tick();
            }
        }
Ejemplo n.º 2
0
        private void DrawMainObjectPath(ProjectedPositionCalculator ppCalc)
        {
            var position = _objects.MainObject.Location;
            var speed    = _objects.MainObject.Speed;
            var mass     = _objects.MainObject.Mass;

            for (var i = 0; i < 300; i++)
            {
                var forces = new Force(Angle.Zero, 0);
                foreach (var planet in _objects.Terrains)
                {
                    var distance = PointCalculator.Distance(position, planet.Location);
                    var angle    = PointCalculator.CalculateAngle(position, planet.Location);
                    forces += GravityCalculator.CalculateGravity(mass, planet.Mass, distance, angle);
                }

                var acceleration = forces.GetAcceleration(mass);
                speed += acceleration.GetSpeed(new TimeSpan(0, 0, 0, 10));

                if (speed.Value > 50000)
                {
                    break;
                }

                var flownDistance = speed.GetDistance(new TimeSpan(0, 0, 0, 10)).CalculateXAndY();
                position.X += (float)flownDistance.X;
                position.Y += (float)flownDistance.Y;
                var projectedPosition = ppCalc.ProjectPoint(position);
                _graphicsBuffer.Graphics.FillRectangle(new SolidBrush(Color.White), projectedPosition.X,
                                                       projectedPosition.Y, 1, 1);
            }
        }