Exemplo n.º 1
0
        /// <summary>
        /// Updates the physics bodies and resolves all forces.
        /// </summary>
        private void Update(TimeStep timeStep)
        {
            ResolveMassiveBodyParents();
            _spaceCraftManager.ResolveGravitionalParents(_massiveBodies);
            AdjustSpeedForBurns(timeStep);

            double targetDt = _isPaused ? 0 : timeStep.Dt;

            // Update all bodies according to the timestep
            for (int i = 0; i < timeStep.UpdateLoops; i++)
            {
                // Resolve n body massive body forces
                foreach (IMassiveBody bodyA in _massiveBodies)
                {
                    bodyA.ResetAccelerations();

                    foreach (IMassiveBody bodyB in _massiveBodies)
                    {
                        if (bodyA == bodyB)
                        {
                            continue;
                        }

                        bodyA.ResolveGravitation(bodyB);
                    }
                }

                _spaceCraftManager.ResolveForces(_massiveBodies);
                _spaceCraftManager.Update(timeStep, targetDt);

                // Update bodies
                foreach (IGravitationalBody gravitationalBody in _gravitationalBodies)
                {
                    gravitationalBody.Update(targetDt);
                }

                _totalElapsedSeconds += targetDt;
            }

            _camera.Update(TimeStep.RealTimeDt);
            _eventManager.Update(TimeStep.RealTimeDt);

            // Fixed update all gravitational bodies
            foreach (IGravitationalBody body in _gravitationalBodies)
            {
                body.FixedUpdate(timeStep);
            }

            var targetSpaceCraft = _gravitationalBodies[_targetIndex] as ISpaceCraft;

            if (targetSpaceCraft != null)
            {
                if (targetSpaceCraft.Controller.IsPrograde)
                {
                    _progradeButton.Enable();
                }
                else
                {
                    _progradeButton.Disable();
                }

                if (targetSpaceCraft.Controller.IsRetrograde)
                {
                    _retrogradeButton.Enable();
                }
                else
                {
                    _retrogradeButton.Disable();
                }
            }

            _scrollRate = MathHelper.Lerp(_scrollRate, _targetScrollRate, 0.1f);

            _targetScrollRate = MathHelper.Lerp(_targetScrollRate, 0, 0.1f);

            if (_camera.Zoom > 1)
            {
                double scroll = Math.Pow(_camera.Zoom, 1.05f) * _scrollRate;

                _camera.ChangeZoom(scroll);
            }
            else
            {
                _camera.ChangeZoom(_scrollRate);
            }

            SetCameraRotation();
        }
Exemplo n.º 2
0
        private void LoadSolarSystem()
        {
            _sun = new Sun();

            var mercury = new Mercury();
            var venus   = new Venus();

            var earth = new Earth();
            var moon  = new Moon(earth.Position, earth.Velocity);

            var mars = new Mars();

            var jupiter  = new Jupiter();
            var callisto = new Callisto(jupiter.Position, jupiter.Velocity);
            var europa   = new Europa(jupiter.Position, jupiter.Velocity);
            var ganymede = new Ganymede(jupiter.Position, jupiter.Velocity);
            var io       = new Io(jupiter.Position, jupiter.Velocity);

            var saturn = new Saturn();

            _massiveBodies = new List <IMassiveBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, callisto, europa, ganymede, io, saturn
            };

            ResolveMassiveBodyParents();

            _gravitationalBodies = new List <IGravitationalBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, callisto, europa, ganymede, io, saturn
            };

            _spaceCraftManager = new SpaceCraftManager(_gravitationalBodies);
            _structures        = new List <StructureBase>();

            MissionConfig primaryMission = MissionConfig.Load(ProfilePaths[0]);

            _originTime = primaryMission.GetLaunchDate();

            UpdateLoadingPercentage(20);

            OrbitHelper.SimulateToTime(_massiveBodies, _originTime, 300, UpdateLoadingPercentage);

            UpdateLoadingPercentage(80);

            // Load missions
            for (int i = 0; i < ProfilePaths.Count; i++)
            {
                MissionConfig missionConfig = MissionConfig.Load(ProfilePaths[i]);

                if (missionConfig.ClockDelay > _clockDelay)
                {
                    _clockDelay = missionConfig.ClockDelay;
                }

                IMassiveBody targetPlanet = LocatePlanet(missionConfig.ParentPlanet);

                // Get the launch angle relative to the sun for the given time at the origin
                // and offset each vehicle by a certain amount on the surface
                double launchAngle = targetPlanet.GetSurfaceAngle(_originTime, _sun) + i * 0.00002;

                _spaceCraftManager.Add(SpacecraftFactory.BuildSpaceCraft(targetPlanet, launchAngle, missionConfig, ProfilePaths[i]));

                _structures.AddRange(StructureFactory.Load(targetPlanet, launchAngle, ProfilePaths[i]));
            }

            _spaceCraftManager.Initialize(_eventManager, _clockDelay);

            // Target the spacecraft
            _targetIndex = _gravitationalBodies.IndexOf(_spaceCraftManager.First);

            _spaceCraftManager.ResolveGravitionalParents(_massiveBodies);

            UpdateLoadingPercentage(90);
        }