Example #1
0
        /// <summary>
        /// Recursively updates the engines in the spacecraft and updates propellant mass.
        /// </summary>
        private void UpdateEngines(double dt)
        {
            Thrust = 0;

            if (Engines.Length > 0 && PropellantMass > 0)
            {
                double altitude = GetRelativeAltitude();

                double ispMultiplier = GravitationalParent.GetIspMultiplier(altitude);

                foreach (IEngine engine in Engines)
                {
                    if (!engine.IsActive)
                    {
                        continue;
                    }

                    Thrust += engine.Thrust(ispMultiplier);

                    PropellantMass = Math.Max(0, PropellantMass - engine.MassFlowRate() * dt);
                }
            }

            foreach (SpaceCraftBase child in Children)
            {
                child.UpdateEngines(dt);

                Thrust += child.Thrust;
            }
        }
Example #2
0
        /// <summary>
        /// Updates the spacecraft and it's children.
        /// </summary>
        public override void Update(double dt)
        {
            double altitude = GetRelativeAltitude();

            IspMultiplier = GravitationalParent.GetIspMultiplier(altitude);

            if (Parent == null)
            {
                UpdateEngines(dt);

                if (Thrust > 0)
                {
                    var thrustVector = new DVector2(Math.Cos(Pitch), Math.Sin(Pitch));

                    AccelerationN += (thrustVector * Thrust) / Mass;
                }

                if (_requiresStaging)
                {
                    AccelerationN += _stagingForce;

                    _requiresStaging = false;
                }

                // Integrate acceleration
                Velocity += (AccelerationG * dt);
                Velocity += (AccelerationD * dt);
                Velocity += (AccelerationN * dt);
                Velocity += (AccelerationL * dt);

                // Re-normalize FTL scenarios
                if (Velocity.LengthSquared() > Constants.SpeedLightSquared)
                {
                    Velocity.Normalize();

                    Velocity *= Constants.SpeedOfLight;
                }

                // Integrate velocity
                Position += (Velocity * dt);

                MachNumber = GetRelativeVelocity().Length() * 0.0029411764;

                foreach (ISpaceCraft child in Children)
                {
                    child.UpdateChildren(Position, Velocity);
                }

                _trailTimer += dt;

                // Somewhat arbitrary conditions for launch trails
                if (dt < 0.1666666666 && altitude > 50 && !InOrbit && _trailTimer > 1)
                {
                    _launchTrail.AddPoint(Position, GravitationalParent, Throttle > 0);
                    _trailTimer = 0;
                }
            }
        }
        /// <summary>
        /// Renders the space craft at it's correct scale and rotation according to the camera.
        /// The engines are rendered first and then the space craft body.
        /// </summary>
        public override void RenderGdi(Graphics graphics, Camera camera)
        {
            if (Terminated)
            {
                return;
            }

            // Only draws the ship if it's visible
            if (Visibility(camera.Bounds) > 0)
            {
                RectangleD bounds = ComputeBoundingBox();

                // In range for render
                if (camera.Intersects(bounds))
                {
                    RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position, camera.Bounds, Width, Height);

                    // Saftey
                    if (screenBounds.Width > RenderUtils.ScreenWidth * 500)
                    {
                        return;
                    }

                    RenderBelow(graphics, camera);

                    RenderShip(graphics, camera, screenBounds);

                    RenderAbove(graphics, camera);
                }
            }

            // Only draw orbit traces and launch trails for detatched ships
            if (Parent == null)
            {
                camera.ApplyScreenRotation(graphics);

                if (camera.Bounds.Width > 1000)
                {
                    if (GravitationalParent != null)
                    {
                        string parentName = GravitationalParent.ToString();

                        if (_launchTrails.ContainsKey(parentName))
                        {
                            _launchTrails[parentName].Draw(graphics, camera, GravitationalParent);
                        }
                    }
                }

                // Don't draw orbit traces on the ground
                base.RenderGdi(graphics, camera);

                graphics.ResetTransform();
            }
        }
Example #4
0
        public override void UpdateAnimations(TimeStep timeStep)
        {
            DVector2 retrogradeVelocity = GetRelativeVelocity();

            retrogradeVelocity.Negate();

            DVector2 engineBase = Position - DVector2.FromAngle(Pitch) * Height * 0.5;

            double altitude = GetRelativeAltitude();

            double atmosphericDensity = GravitationalParent.GetAtmosphericDensity(altitude);

            _engineSmoke.Update(timeStep, engineBase, Velocity, retrogradeVelocity, atmosphericDensity, _sootRatio);

            base.UpdateAnimations(timeStep);
        }
Example #5
0
        /// <summary>
        /// Updates the spacecraft and it's children.
        /// </summary>
        public override void Update(double dt)
        {
            Controller.Update(dt);

            double altitude = GetRelativeAltitude();

            IspMultiplier = GravitationalParent.GetIspMultiplier(altitude);

            if (Parent == null)
            {
                UpdateEngines(dt);

                if (Thrust > 0)
                {
                    var thrustVector = new DVector2(Math.Cos(Rotation), Math.Sin(Rotation));

                    AccelerationN += (thrustVector * Thrust) / Mass;
                }

                // Integrate acceleration
                Velocity += (AccelerationG * dt);
                Velocity += (AccelerationD * dt);
                Velocity += (AccelerationN * dt);

                // Re-normalize FTL scenarios
                if (Velocity.LengthSquared() > FlightGlobals.SPEED_LIGHT_SQUARED)
                {
                    Velocity.Normalize();

                    Velocity *= FlightGlobals.SPEED_OF_LIGHT;
                }

                // Integrate velocity
                Position += (Velocity * dt);

                MachNumber = GetRelativeVelocity().Length() * 0.0029411764;

                foreach (ISpaceCraft child in Children)
                {
                    child.UpdateChildren(Position, Velocity);
                }
            }
        }
        public virtual void UpdateChildren(DVector2 position, DVector2 velocity)
        {
            var rotationOffset = new DVector2(Math.Cos(Pitch), Math.Sin(Pitch));

            Position = position - new DVector2(StageOffset.X * rotationOffset.Y + StageOffset.Y * rotationOffset.X,
                                               -StageOffset.X * rotationOffset.X + StageOffset.Y * rotationOffset.Y);
            Velocity.X = velocity.X;
            Velocity.Y = velocity.Y;

            // get the mach number from the planet and altitude
            if (GravitationalParent != null)
            {
                double speedOfSound = GravitationalParent.GetSpeedOfSound(GetRelativeAltitude());
                MachNumber = velocity.Length() * 0.0029411764;

                foreach (ISpaceCraft child in Children)
                {
                    child.UpdateChildren(Position, Velocity);
                }
            }
        }
Example #7
0
        private void UpdateEngines(double dt)
        {
            _thrust = 0;

            if (Engines.Length > 0 && PropellantMass > 0)
            {
                double ispMultiplier = GravitationalParent.GetIspMultiplier(Altitude);

                foreach (IEngine engine in Engines)
                {
                    if (!engine.IsActive)
                    {
                        continue;
                    }

                    _thrust += engine.Thrust(ispMultiplier);

                    PropellantMass = Math.Max(0, PropellantMass - engine.MassFlowRate(ispMultiplier) * dt);
                }
            }
        }
        /// <summary>
        /// Updates the spacecraft and it's children.
        /// </summary>
        public override void Update(double dt)
        {
            ComputeCachedProperties();

            double altitude = GetRelativeAltitude();

            if (GravitationalParent == null)
            {
                IspMultiplier = 1;
            }
            else
            {
                IspMultiplier = GravitationalParent.GetIspMultiplier(altitude);
            }

            if (Parent == null)
            {
                UpdateEngines(dt);

                if (Thrust > 0 && _isReleased)
                {
                    var thrustVector = new DVector2(Math.Cos(Pitch) * Math.Cos(Yaw), Math.Sin(Pitch) * Math.Cos(Yaw));
                    var yawVector    = new DVector2(Math.Cos(Pitch) * Math.Sin(Yaw), Math.Sin(Pitch) * Math.Sin(Yaw));

                    AccelerationN += (thrustVector * Thrust) / Mass;
                    AccelerationY += (yawVector * Thrust) / Mass;
                }

                if (_requiresStaging)
                {
                    // Simulate simple staging mechanism
                    double sAngle = StageOffset.Angle();

                    DVector2 stagingNormal = DVector2.FromAngle(Pitch + sAngle + Constants.PiOverTwo);

                    AccelerationN += stagingNormal * StagingForce;

                    _requiresStaging = false;
                }

                if (_isReleased)
                {
                    // Integrate acceleration
                    Velocity += AccelerationG * dt;
                    Velocity += AccelerationD * dt;
                    Velocity += AccelerationL * dt;
                    Velocity += AccelerationN * dt;

                    LateralVelocity += AccelerationY * dt;
                    LateralPosition += LateralVelocity * dt;
                }

                // Re-normalize FTL scenarios
                if (Velocity.LengthSquared() > Constants.SpeedLightSquared)
                {
                    Velocity.Normalize();

                    Velocity *= Constants.SpeedOfLight;
                }

                // If the craft is on the ground with high time warpd don't update the position as normal.
                // Instead just keep putting the ship at the correct spot on it's gravitational body based on rotation.
                if (OnGround && dt > 5)
                {
                    DVector2 parentOffset = GravitationalParent.Position - Position;
                    parentOffset.Normalize();

                    Position = GravitationalParent.Position + parentOffset * GravitationalParent.SurfaceRadius;
                }
                else
                {
                    // Integrate velocity
                    Position += Velocity * dt;
                }

                MachNumber = GetRelativeVelocity().Length() * 0.0029411764;

                foreach (ISpaceCraft child in Children)
                {
                    child.UpdateChildren(Position, Velocity);
                }

                _trailTimer += dt;

                // Somewhat arbitrary conditions for launch trails
                if (dt < 0.1666666666 && !InOrbit && !OnGround && _cachedAltitude > 50 && _cachedAltitude < GravitationalParent.AtmosphereHeight * 2 && _trailTimer > 1)
                {
                    string parentName = GravitationalParent.ToString();

                    if (!_launchTrails.ContainsKey(parentName))
                    {
                        _launchTrails.Add(parentName, new LaunchTrail());
                    }

                    _launchTrails[parentName].AddPoint(Position, GravitationalParent, Throttle > 0);
                    _trailTimer = 0;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Updates the spacecraft and it's children.
        /// </summary>
        public override void Update(double dt)
        {
            ComputeCachedProperties();

            double altitude = GetRelativeAltitude();

            IspMultiplier = GravitationalParent.GetIspMultiplier(altitude);

            if (Parent == null)
            {
                UpdateEngines(dt);

                if (Thrust > 0)
                {
                    var thrustVector = new DVector2(Math.Cos(Pitch), Math.Sin(Pitch));

                    AccelerationN += (thrustVector * Thrust) / Mass;
                }

                if (_requiresStaging)
                {
                    // Simulate simple staging mechanism
                    double sAngle = StageOffset.Angle();

                    DVector2 stagingNormal = DVector2.FromAngle(Pitch + sAngle + Math.PI * 0.5);

                    AccelerationN += stagingNormal * StagingForce;

                    _requiresStaging = false;
                }

                // Integrate acceleration
                Velocity += (AccelerationG * dt);
                Velocity += (AccelerationD * dt);
                Velocity += (AccelerationN * dt);
                Velocity += (AccelerationL * dt);

                // Re-normalize FTL scenarios
                if (Velocity.LengthSquared() > Constants.SpeedLightSquared)
                {
                    Velocity.Normalize();

                    Velocity *= Constants.SpeedOfLight;
                }

                // Integrate velocity
                Position += (Velocity * dt);

                MachNumber = GetRelativeVelocity().Length() * 0.0029411764;

                foreach (ISpaceCraft child in Children)
                {
                    child.UpdateChildren(Position, Velocity);
                }

                _trailTimer += dt;

                // Somewhat arbitrary conditions for launch trails
                if (dt < 0.1666666666 && !InOrbit && _cachedAltitude > 50 && _cachedAltitude < GravitationalParent.AtmosphereHeight * 2 && _trailTimer > 1)
                {
                    string parentName = GravitationalParent.ToString();

                    if (!_launchTrails.ContainsKey(parentName))
                    {
                        _launchTrails.Add(parentName, new LaunchTrail());
                    }

                    _launchTrails[parentName].AddPoint(Position, GravitationalParent, Throttle > 0);
                    _trailTimer = 0;
                }
            }
        }