public void Update(double dt) { if (_isInterpolating) { if (_interpolationTime > 1) { _isInterpolating = false; } // Interpolate using a logistic function // https://en.wikipedia.org/wiki/Logistic_function double sigmoidX = (_interpolationTime - 0.5) * 6; double sigmoidY = (1.0 / (1 + Math.Exp(-3.0 * sigmoidX))); // Lerp between the two targets _position = _lastTarget.Position * (1 - sigmoidY) + _target.Position * sigmoidY; _interpolationTime += dt; } else { _position = _target.Position; } }
public OrbitTrace(DVector2 start, double altitude) { Apogee = altitude; Perigee = altitude; _points = new List<DVector2> { start }; }
protected GravitationalBodyBase(DVector2 position, DVector2 velocity, double rotation) { Position = position; Velocity = velocity; Rotation = rotation; }
public FHBooster(int id, DVector2 position, DVector2 velocity) : base(position, velocity, 409500, "Textures/fhBooster" + id + ".png") { Id = id; if (Id == 1) { StageOffset = new DVector2(-4, 1.5); } else { StageOffset = new DVector2(4, 1.5); } Engines = new IEngine[9]; for (int i = 0; i < 9; i++) { double engineOffsetX = (i - 4.0) / 4.0; var offset = new DVector2(engineOffsetX * Width * 0.3, Height * 0.45); Engines[i] = new Merlin1D(i, this, offset); } }
public DragonV2Trunk(string craftDirectory, DVector2 position, DVector2 velocity) : base(craftDirectory, position, velocity, 0, 0, "Textures/dragonTrunkV2.png") { StageOffset = new DVector2(0, 4); Engines = new IEngine[0]; }
public DemoSat(string craftDirectory, DVector2 position, DVector2 velocity, double payloadMass) : base(craftDirectory, position, velocity, payloadMass, 0, "Textures/fairing.png") { _fairingMass = 1750; Engines = new IEngine[0]; }
public static PointF WorldToScreen(DVector2 point, RectangleD cameraBounds) { var normalizedPoint = new DVector2((point.X - cameraBounds.Left) / cameraBounds.Width, (point.Y - cameraBounds.Top) / cameraBounds.Height); return new PointF((float)(normalizedPoint.X * ScreenWidth), (float)(normalizedPoint.Y * ScreenHeight)); }
public double GetRelativeHeight(DVector2 position) { DVector2 difference = Position - position; double totalDistance = difference.Length(); return totalDistance - _proxy.SurfaceRadius; }
protected SpaceCraftBase(DVector2 position, DVector2 velocity, double propellantMass, string texturePath) : base(position, velocity, -Math.PI * 0.5) { Children = new List<ISpaceCraft>(); Texture = new Bitmap(texturePath); PropellantMass = propellantMass; }
protected EngineBase(int id, ISpaceCraft parent, DVector2 offset, EngineFlame flame) { _parent = parent; _offsetLength = offset.Length(); _offsetRotation = offset.Angle() - Math.PI / 2.0; _engineFlame = flame; }
protected GravitationalBodyBase(DVector2 position, DVector2 velocity, double pitch) { Position = position; Velocity = velocity; Pitch = pitch; OrbitTrace = new OrbitTrace(); }
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); }
public Camera(IPhysicsBody target, double zoom = 1) { _target = target; _lastTarget = target; _position = _target.Position.Clone(); Zoom = zoom; }
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"); }
public Dragon(DVector2 position, DVector2 velocity) : base(position, velocity, 1388, "Textures/dragonV2.png") { Engines = new IEngine[8]; for (int i = 0; i < 8; i++) { Engines[i] = new SuperDraco(i, this, DVector2.Zero); } }
public FH9S2(DVector2 position, DVector2 velocity) : base(position, velocity, 103500, "Textures/fh9S2.png") { StageOffset = new DVector2(0, 13.3); Engines = new IEngine[] { new Merlin1DVac(this, new DVector2(0, Height * 0.3)) }; }
public F9S2(string craftDirectory, DVector2 position, DVector2 velocity, double stageOffset) : base(craftDirectory, position, velocity, 0, 108185, "Textures/fh9S2.png") { StageOffset = new DVector2(0, stageOffset); Engines = new IEngine[] { new Merlin1DVac(this, new DVector2(0, Height * 0.3)) }; }
public void Update(TimeStep timeStep) { double rotation = _parent.Rotation -_offsetRotation; DVector2 offset = new DVector2(Math.Cos(rotation), Math.Sin(rotation)) * _offsetLength; double throttle = (IsActive && _parent.PropellantMass > 0) ? Throttle : 0; _engineFlame.Update(timeStep, _parent.Position - offset, _parent.Velocity, _parent.Rotation, throttle); }
protected StructureBase(DVector2 relativePosition, string texturePath, IMassiveBody parent) { _parent = parent; _initialDistance = relativePosition.Length(); _rotationOffset = relativePosition.Angle(); _initialRotation = parent.Rotation; _texture = new Bitmap(texturePath); }
public void Update(TimeStep timeStep, DVector2 shipPosition, DVector2 shipVelocity, double pitch, double heatingRate) { double rotation = pitch - _offsetAngle; DVector2 offset = new DVector2(Math.Cos(rotation), Math.Sin(rotation)) * _offsetLength; DVector2 shockPosition = shipPosition - offset; double normalizedHeating = Math.Max((heatingRate - 500000) * 0.0005, 0); int particles = (int)(normalizedHeating * _particleRate) / timeStep.UpdateLoops; // Add new particles if nessecary for (int i = 0; i < particles; i++) { if (_availableParticles.Count > 0) { double velocityFactor = _random.Next(50, 200); double spread = _random.NextDouble() * 2.5 - 1.25; DVector2 velocity = DVector2.FromAngle(rotation + spread); int id = _availableParticles.Dequeue(); Particle particle = _particles[id]; particle.IsActive = true; particle.Age = 0; particle.MaxAge = _random.NextDouble()*0.01 + 0.02; particle.Position = shockPosition.Clone(); particle.Velocity = shipVelocity.Clone() + velocity*velocityFactor; } } // Update the particles for (int i = 0; i < _particles.Length; i++) { Particle particle = _particles[i]; if (particle.IsActive) { particle.Position += particle.Velocity*timeStep.Dt; particle.Age += timeStep.Dt; if (particle.Age > particle.MaxAge) { particle.IsActive = false; _availableParticles.Enqueue(i); } } } }
public static void DrawLine(Graphics graphics, RectangleD cameraBounds, DVector2 start, DVector2 end, Color color) { PointF localStart = WorldToScreen(start, cameraBounds); PointF localEnd = WorldToScreen(end, cameraBounds); localStart.X = MathHelper.Clamp(localStart.X, 0, ScreenWidth); localStart.Y = MathHelper.Clamp(localStart.Y, 0, ScreenHeight); localEnd.X = MathHelper.Clamp(localEnd.X, 0, ScreenWidth); localEnd.Y = MathHelper.Clamp(localEnd.Y, 0, ScreenHeight); graphics.DrawLine(new Pen(color, 2), localStart, localEnd); }
public SpaceCraftProxy(DVector2 position, DVector2 velocity, SpaceCraftBase spaceCraft) : base(position, velocity, spaceCraft.Pitch) { PropellantMass = spaceCraft.PropellantMass; Engines = new IEngine[spaceCraft.Engines.Length]; for (int i = 0; i < spaceCraft.Engines.Length; i++) { Engines[i] = spaceCraft.Engines[i].Clone(); } _proxy = spaceCraft; }
public DragonV2(string craftDirectory, DVector2 position, DVector2 velocity, double payloadMass) : base(craftDirectory, position, velocity, payloadMass, 1388, "Textures/dragonV2.png", new ReEntryFlame(1000, 1, new DVector2(2.5, 0))) { Engines = new IEngine[] { new SuperDraco(0, this, new DVector2(-1.35, 0.1), -0.15), new SuperDraco(1, this, new DVector2(-1.35, 0.1), -0.15), new SuperDraco(2, this, new DVector2(-1.4, 0.1), -0.25), new SuperDraco(3, this, new DVector2(-1.4, 0.1), -0.25), new SuperDraco(4, this, new DVector2(1.35, 0.1), 0.15), new SuperDraco(5, this, new DVector2(1.35, 0.1), 0.15), new SuperDraco(6, this, new DVector2(1.4, 0.1), 0.25), new SuperDraco(7, this, new DVector2(1.4, 0.1), 0.25), }; }
public FH9S1(DVector2 position, DVector2 velocity) : base(position, velocity, 409500, "Textures/fh9S1.png") { StageOffset = new DVector2(0, 25.5); Engines = new IEngine[9]; for (int i=0; i < 9; i++) { double engineOffsetX = (i - 4.0) / 4.0; var offset = new DVector2(engineOffsetX * Width * 0.3, Height * 0.45); Engines[i] = new Merlin1D(i, this, offset); } }
public static RectangleF ComputeEllipseSize(DVector2 position, RectangleD cameraBounds, double radius) { double screenRadius = (radius / cameraBounds.Width) * ScreenWidth; DVector2 screenPosition = position - new DVector2(cameraBounds.Left, cameraBounds.Top); double screenU = screenPosition.X / cameraBounds.Width; double screenV = screenPosition.Y / cameraBounds.Height; double screenX = screenU * ScreenWidth; double screenY = screenV * ScreenHeight; return new RectangleF((float) (screenX - screenRadius), (float) (screenY - screenRadius), (float) (screenRadius*2.0), (float) (screenRadius*2.0)); }
public void AddPoint(DVector2 point, double altitude) { if (altitude > Apogee) { Apogee = altitude; _apogeeIndex = _points.Count; } else if (altitude < Perigee) { Perigee = altitude; _perigeeIndex = _points.Count; } _points.Add(point); }
public F9S1(string craftDirectory, DVector2 position, DVector2 velocity, double propellantMass = 398887) : base(craftDirectory, position, velocity, propellantMass, "Textures/f9S1.png") { StageOffset = new DVector2(0, 25.5); Engines = new IEngine[9]; for (int i=0; i < 9; i++) { double engineOffsetX = (i - 4.0) / 4.0; var offset = new DVector2(engineOffsetX * Width * 0.3, Height * 0.45); Engines[i] = new Merlin1D(i, this, offset); } }
public void Update(TimeStep timeStep, DVector2 enginePosition, DVector2 shipVelocity, double rotation, double throttle) { double retrograde = rotation + Math.PI; int particles = (int)((throttle * _particleRate) / timeStep.UpdateLoops); // Add new particles if nessecary for (int i = 0; i < particles; i++) { if (_availableParticles.Count > 0) { double velocityFactor = _random.Next(150, 250); double spread = _random.NextDouble() - 0.5; DVector2 velocity = DVector2.FromAngle(retrograde + spread * _spreadFactor); int id = _availableParticles.Dequeue(); Particle particle = _particles[id]; particle.IsActive = true; particle.Age = 0; particle.MaxAge = _random.NextDouble() * 0.1 + 0.05; particle.Position = enginePosition.Clone(); particle.Velocity = shipVelocity.Clone() + velocity * velocityFactor; } } // Update the particles for (int i = 0; i < _particles.Length; i++) { Particle particle = _particles[i]; if (particle.IsActive) { particle.Position += particle.Velocity * timeStep.Dt; particle.Age += timeStep.Dt; if (particle.Age > particle.MaxAge) { particle.IsActive = false; _availableParticles.Enqueue(i); } } } }
public static RectangleF ComputeBoundingBox(DVector2 position, RectangleD cameraBounds, double width, double height) { double screenWidth = (width / cameraBounds.Width) * ScreenWidth; double screenHeight = (height / cameraBounds.Height) * ScreenHeight; DVector2 screenPosition = position - new DVector2(cameraBounds.Left, cameraBounds.Top); double screenU = screenPosition.X / cameraBounds.Width; double screenV = screenPosition.Y / cameraBounds.Height; double screenX = screenU * ScreenWidth; double screenY = screenV * ScreenHeight; return new RectangleF((float) (screenX - screenWidth*0.5), (float) (screenY - screenHeight*0.5), (float) screenWidth, (float) screenHeight); }
public ITSBooster(string craftDirectory, DVector2 position, DVector2 velocity, double propellantMass = 6078138) : base(craftDirectory, position, velocity, 0, propellantMass, "Textures/itsBooster.png") { StageOffset = new DVector2(0, 59.5); Engines = new IEngine[42]; for (int i = 0; i < 42; i++) { double engineOffsetX = (i - 21.0) / 21.0; var offset = new DVector2(engineOffsetX * Width * 0.34, Height * 0.48); Engines[i] = new Raptor40(i, this, offset); } _spriteSheet = new SpriteSheet("Textures/itsBooster.png", 4, 12); }
public static DVector2 Lerp(DVector2 from, DVector2 to, double t) { return(new DVector2(from.X + t * (to.X - from.X), from.Y + t * (to.Y - from.Y))); }
public double Dot(DVector2 v) { return(X * v.X + Y * v.Y); }
public static double Distance(DVector2 v1, DVector2 v2) { return((v2 - v1).Length()); }
public double Cross(DVector2 v) { return(X * v.Y - Y * v.X); }
public void Accumulate(DVector2 other) { X += other.X; Y += other.Y; }