예제 #1
0
        private void SetCameraRotation()
        {
            IGravitationalBody target = _gravitationalBodies[_targetIndex];

            if (target is ISpaceCraft)
            {
                if (_rotateInOrbit)
                {
                    if (target.InOrbit)
                    {
                        if (!_targetInOrbit)
                        {
                            _camera.SetRotation(0, true);

                            _targetInOrbit = true;
                        }
                        else
                        {
                            _camera.SetRotation(0);
                        }
                    }
                    else
                    {
                        DVector2 craftOffset = target.GravitationalParent.Position - target.Position;
                        craftOffset.Normalize();

                        if (_targetInOrbit)
                        {
                            _camera.SetRotation(Constants.PiOverTwo - craftOffset.Angle(), true);

                            _targetInOrbit = false;
                        }
                        else
                        {
                            _camera.SetRotation(Constants.PiOverTwo - craftOffset.Angle());
                        }
                    }
                }
                else
                {
                    DVector2 craftOffset = target.GravitationalParent.Position - target.Position;
                    craftOffset.Normalize();
                    _camera.SetRotation(Constants.PiOverTwo - craftOffset.Angle());
                }
            }
            else
            {
                _camera.SetRotation(0);
            }
        }
예제 #2
0
        /// <summary>
        /// Stages the spacecraft according to its mounted angle by applying a normal force.
        /// </summary>
        public void Stage()
        {
            if (Children.Count > 0)
            {
                ISpaceCraft[] children = Children.ToArray();

                foreach (ISpaceCraft child in children)
                {
                    child.Stage();
                }
            }
            else if (Parent != null)
            {
                Parent.RemoveChild(this);
                Parent = null;

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

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

                _stagingForce    = stagingNormal * Mass * 0.005;
                _requiresStaging = true;
            }
        }
예제 #3
0
        public override double GetRelativePitch()
        {
            double altitude      = GetRelativeAltitude();
            double relativePitch = Pitch - GravitationalParent.Pitch;

            if (altitude > GravitationalParent.AtmosphereHeight)
            {
                return(relativePitch);
            }

            DVector2 difference = GravitationalParent.Position - Position;

            difference.Normalize();
            var    surfaceNormal = new DVector2(difference.Y, difference.X);
            double normal        = surfaceNormal.Angle();

            if (!double.IsNaN(normal))
            {
                if (altitude > 0.1)
                {
                    relativePitch += normal;
                }
                else
                {
                    relativePitch = normal;
                }
            }

            return(relativePitch);
        }
예제 #4
0
        public void SetRelativePitch(double pitch)
        {
            double altitude = GetRelativeAltitude();

            if (altitude > GravitationalParent.AtmosphereHeight)
            {
                Pitch = GravitationalParent.Pitch + pitch;
            }
            else
            {
                DVector2 difference = GravitationalParent.Position - Position;
                difference.Normalize();
                var    surfaceNormal = new DVector2(difference.Y, difference.X);
                double normal        = surfaceNormal.Angle();
                if (double.IsNaN(normal))
                {
                    Pitch = GravitationalParent.Pitch + pitch;
                }
                else
                {
                    Pitch = GravitationalParent.Pitch + pitch - normal;
                }
            }

            foreach (ISpaceCraft child in Children)
            {
                child.SetRelativePitch(pitch);
            }
        }
예제 #5
0
        // Interpolate between current and target orientation over the duration
        public override void Update(double elapsedTime, SpaceCraftBase spaceCraft)
        {
            double altitude         = spaceCraft.GetRelativeAltitude();
            double atmosphereheight = spaceCraft.GravitationalParent.AtmosphereHeight;

            DVector2 retrograde = spaceCraft.GetRelativeVelocity();

            if (altitude > atmosphereheight)
            {
                retrograde = spaceCraft.GetInertialVelocity();
            }

            retrograde.Negate();
            retrograde.Normalize();

            double retrogradeAngle = retrograde.Angle();

            double adjustRatio = (elapsedTime - StartTime) / _adjustmentTime;

            if (adjustRatio > 1)
            {
                spaceCraft.SetPitch(retrogradeAngle);
            }
            else
            {
                double interpolatedAdjust = MathHelper.LerpAngle(_curentOrientation, retrogradeAngle, adjustRatio);

                spaceCraft.SetPitch(interpolatedAdjust);
            }
        }
예제 #6
0
        // Interpolate between current and target orientation over the duration
        public override void Update(double elapsedTime, SpaceCraftBase spaceCraft)
        {
            DVector2 prograde = spaceCraft.GetRelativeVelocity();

            prograde.Normalize();

            double retrogradeAngle = prograde.Angle();

            if (retrogradeAngle > 0)
            {
                retrogradeAngle -= Math.PI * 2;
            }

            double adjustRatio = (elapsedTime - StartTime) / _adjustmentTime;

            if (adjustRatio > 1)
            {
                spaceCraft.SetPitch(retrogradeAngle);
            }
            else
            {
                double interpolatedAdjust = MathHelper.LerpAngle(_curentOrientation, retrogradeAngle, adjustRatio);

                spaceCraft.SetPitch(interpolatedAdjust);
            }
        }
예제 #7
0
        public GridFin(ISpaceCraft parent, DVector2 offset, int block, bool isLeft)
            : base(parent, GenerateTexturePath(block, isLeft))
        {
            if (block == 6)
            {
                Width  = 2.4;
                Height = 4.0;
            }
            else if (block == 5)
            {
                Width  = 1.3;
                Height = 2.0;
            }
            else
            {
                Width  = 1.2192;
                Height = 1.79806518;
            }

            DrawingOffset = 0.6;

            _isLeft = isLeft;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Constants.PiOverTwo;
        }
예제 #8
0
        public SSGridFin(ISpaceCraft parent, DVector2 offset, bool isLeft)
            : base(parent, GenerateTexturePath(isLeft))
        {
            _isLeft = isLeft;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Constants.PiOverTwo;
        }
예제 #9
0
        public LandingLeg(ISpaceCraft parent, DVector2 offset, int block, bool isLeft)
            : base(parent, GenerateTexturePath(block, isLeft))
        {
            _isLeft = isLeft;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Constants.PiOverTwo;
        }
예제 #10
0
        public NGLandingLeg(ISpaceCraft parent, DVector2 offset, bool isLeft)
            : base(parent, GenerateTexturePath(isLeft))
        {
            _parent = parent;
            _isLeft = isLeft;

            _offsetLength = -offset.Length();
            _offsetRotation = offset.Angle() + Math.PI / 2.0;
        }
예제 #11
0
        public void AddPoint(DVector2 point, IMassiveBody parentBody, bool isPowered)
        {
            DVector2 offset = point - parentBody.Position;

            _trailAngles.Add(offset.Angle() - parentBody.Pitch);
            _trailDistances.Add(offset.Length());

            _trailPowered.Add(isPowered);
        }
예제 #12
0
        public DrogueChute(ISpaceCraft parent, DVector2 offset)
        {
            _parent = parent;

            _offsetLength   = offset.Length();
            _offsetRotation = _offsetRotation = offset.Angle() - Math.PI / 2.0;

            _texture = new Bitmap("Textures/Spacecrafts/Falcon/Common/drogueChute.png");
        }
예제 #13
0
        public override double GetRelativePitch()
        {
            DVector2 difference = GravitationalParent.Position - Position;

            difference.Normalize();
            double surfaceNormal = difference.Angle() - Constants.PiOverTwo;

            return(Pitch - surfaceNormal);
        }
예제 #14
0
파일: EngineBase.cs 프로젝트: ap0r/SpaceSim
        protected EngineBase(ISpaceCraft parent, DVector2 offset, EngineFlame flame)
        {
            _parent = parent;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Math.PI / 2.0;

            _engineFlame = flame;
        }
예제 #15
0
        public LandingLeg(ISpaceCraft parent, DVector2 offset, bool isLeft)
        {
            _parent = parent;
            _isLeft = isLeft;

            _offsetLength   = offset.Length();
            _offsetRotation = _offsetRotation = offset.Angle() - Math.PI / 2.0;

            _texture = isLeft ? new Bitmap("Textures/landingLegLeft.png") : new Bitmap("Textures/landingLegRight.png");
        }
예제 #16
0
        protected EngineBase(ISpaceCraft parent, DVector2 offset, Plume plume)
        {
            Parent = parent;
            Offset = offset;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Math.PI / 2.0;

            _plume = plume;
        }
예제 #17
0
        public double GetSurfaceAngle(DateTime localTime, IMassiveBody sun)
        {
            DVector2 sunDifference = sun.Position - Position;

            double noonAngle = sunDifference.Angle();

            TimeSpan noonOffset = new TimeSpan(localTime.Hour, localTime.Minute, localTime.Second) - new TimeSpan(12, 0, 0);

            return(noonAngle + noonOffset.TotalSeconds * RotationRate);
        }
예제 #18
0
        public ReEntryFlame(int maxParticles, double particleRate, DVector2 offset)
            : base(maxParticles, Color.FromArgb(50, 255, 255, 0))
        {
            _random = new Random();

            _particleRate = particleRate;

            _offsetAngle  = offset.Angle();
            _offsetLength = offset.Length();
        }
예제 #19
0
        public void ResolveAtmopsherics(IMassiveBody body)
        {
            DVector2 difference = body.Position - Position;

            double distance = difference.Length();

            difference.Normalize();

            double altitude = distance - body.SurfaceRadius;

            // The object is in the atmosphere of body B
            if (altitude < body.AtmosphereHeight)
            {
                var surfaceNormal = new DVector2(-difference.Y, difference.X);

                double altitudeFromCenter = altitude + body.SurfaceRadius;

                // Distance of circumference at this altitude ( c= 2r * pi )
                double pathCirumference = 2 * Math.PI * altitudeFromCenter;

                double rotationalSpeed = pathCirumference / body.RotationPeriod;

                // Simple collision detection
                if (altitude <= 0)
                {
                    var normal = new DVector2(-difference.X, -difference.Y);

                    Position = body.Position + normal * (body.SurfaceRadius);

                    Velocity = (body.Velocity + surfaceNormal * rotationalSpeed);

                    Rotation = normal.Angle();

                    AccelerationN.X = -AccelerationG.X;
                    AccelerationN.Y = -AccelerationG.Y;
                }

                double atmosphericDensity = body.GetAtmosphericDensity(altitude);

                DVector2 relativeVelocity = (body.Velocity + surfaceNormal * rotationalSpeed) - Velocity;

                double velocityMagnitude = relativeVelocity.LengthSquared();

                if (velocityMagnitude > 0)
                {
                    relativeVelocity.Normalize();

                    // Drag ( Fd = 0.5pv^2dA )
                    DVector2 dragForce = relativeVelocity * (0.5 * atmosphericDensity * velocityMagnitude * DragCoefficient * CrossSectionalArea);

                    AccelerationD += dragForce / Mass;
                }
            }
        }
예제 #20
0
파일: Skid.cs 프로젝트: tdandrade/SpaceSim
        public Skid(ISpaceCraft parent, DVector2 offset, bool isLeft)
        {
            _parent = parent;
            _isLeft = isLeft;

            _offsetLength   = -offset.Length();
            _offsetRotation = offset.Angle() + Math.PI / 2.0;

            _texture = isLeft ? new Bitmap("Textures/Spacecrafts/NewGlenn/landingLegLeft.png") :
                       new Bitmap("Textures/Spacecrafts/NewGlenn/landingLegRight.png");
        }
예제 #21
0
        protected StructureBase(DVector2 relativePosition, string texturePath, IMassiveBody parent)
        {
            _parent = parent;

            _initialDistance = relativePosition.Length();

            _rotationOffset  = relativePosition.Angle();
            _initialRotation = parent.Rotation;

            _texture = new Bitmap(texturePath);
        }
예제 #22
0
        public GridFin(ISpaceCraft parent, DVector2 offset, bool isLeft)
        {
            _parent = parent;
            _isLeft = isLeft;

            _offsetLength   = offset.Length();
            _offsetRotation = _offsetRotation = offset.Angle() - Math.PI / 2.0;

            _texture = isLeft ? new Bitmap("Textures/Spacecrafts/Falcon/Common/gridFinLeft.png") :
                       new Bitmap("Textures/Spacecrafts/Falcon/Common//gridFinRight.png");
        }
예제 #23
0
        public Parachute(ISpaceCraft parent, DVector2 offset)
        {
            _parent = parent;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle();

            //Pitch = -Math.PI / 2.0;
            Pitch = Math.PI / 2.0 + Math.PI / 12.0;

            _texture = new Bitmap("Textures/Spacecrafts/Falcon/Common/parachutes.png");
        }
예제 #24
0
        public void SetRelativePitch(double pitch)
        {
            DVector2 difference = GravitationalParent.Position - Position;

            difference.Normalize();
            double surfaceNormal = difference.Angle() - Constants.PiOverTwo;

            Pitch = surfaceNormal + pitch;

            foreach (ISpaceCraft child in Children)
            {
                child.SetRelativePitch(pitch);
            }
        }
예제 #25
0
파일: Fin.cs 프로젝트: stauders/SpaceSim
        public Fin(ISpaceCraft parent, DVector2 offset, DVector2 size, double dihedral = 0.0, string texturePath = "Textures/Spacecrafts/ITS/Fin.png")
            : base(parent, texturePath)
        {
            _width  = size.X;
            _height = size.Y;

            Width  = _width;
            Height = _height;

            Dihedral = dihedral;

            DrawingOffset = 0.0;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Constants.PiOverTwo;
        }
예제 #26
0
        public Parachute(ISpaceCraft parent, DVector2 offset, bool isLeft)
        {
            _parent = parent;

            _offsetLength   = offset.Length();
            _offsetRotation = offset.Angle() - Math.PI / 2.0;

            if (isLeft)
            {
                _texture = new Bitmap("Textures/Spacecrafts/Falcon/Common/parachuteLeft.png");
            }
            else
            {
                _texture = new Bitmap("Textures/Spacecrafts/Falcon/Common/parachuteRight.png");
            }
        }
예제 #27
0
        public ReEntryFlame(int maxParticles, double particleRate, DVector2 offset)
        {
            _random = new Random();

            _particles = new Particle[maxParticles];

            _availableParticles = new Queue <int>(maxParticles);

            for (int i = 0; i < maxParticles; i++)
            {
                _particles[i] = new Particle();

                _availableParticles.Enqueue(i);
            }

            _particleRate = particleRate;

            _offsetAngle  = offset.Angle();
            _offsetLength = offset.Length();
        }
예제 #28
0
        // Interpolate between current and target orientation over the duration
        public override void Update(double elapsedTime, ISpaceCraft spaceCraft)
        {
            DVector2 prograde = spaceCraft.GetRelativeVelocity();

            prograde.Normalize();

            double retrogradeAngle = prograde.Angle();

            double adjustRatio = (elapsedTime - StartTime) / _adjustmentTime;

            if (adjustRatio > 1)
            {
                spaceCraft.SetRotation(retrogradeAngle);
            }
            else
            {
                double interpolatedAdjust = _curentOrientation * (1 - adjustRatio) + retrogradeAngle * adjustRatio;

                spaceCraft.SetRotation(interpolatedAdjust);
            }
        }
예제 #29
0
        public virtual void Update(double dt)
        {
            ElapsedTime += dt;

            if (IsPrograde)
            {
                DVector2 prograde = SpaceCraft.GetRelativeVelocity();
                prograde.Normalize();

                SpaceCraft.SetRotation(prograde.Angle());
            }

            if (IsRetrograde)
            {
                DVector2 retrograde = SpaceCraft.GetRelativeVelocity();
                retrograde.Negate();
                retrograde.Normalize();

                SpaceCraft.SetRotation(retrograde.Angle());
            }
        }
예제 #30
0
        /// <summary>
        /// Stages the spacecraft according to its mounted angle by applying a normal force.
        /// </summary>
        public void Stage()
        {
            if (Children.Count > 0)
            {
                ISpaceCraft[] children = Children.ToArray();

                foreach (ISpaceCraft child in children)
                {
                    child.Stage();
                }
            }
            else if (Parent != null)
            {
                Parent.RemoveChild(this);
                Parent = null;

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

                DVector2 stagingVector = DVector2.FromAngle(Rotation + sAngle + Math.PI * 0.5);

                AccelerationN += stagingVector * 1000;
            }
        }