コード例 #1
0
        /// <summary>
        /// Updates the physics bodies and resolves all forces.
        /// </summary>
        private void Update(TimeStep timeStep)
        {
            ResolveMassiveBodyParents();
            ResolveSpaceCraftParents();
            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);
                    }
                }

                // Reslove spacecraft forces
                foreach (SpaceCraftBase spaceCraft in _spaceCrafts)
                {
                    spaceCraft.ResetAccelerations();

                    foreach (MassiveBodyBase massiveBody in _massiveBodies)
                    {
                        spaceCraft.ResolveGravitation(massiveBody);

                        if (spaceCraft.GravitationalParent == massiveBody)
                        {
                            spaceCraft.ResolveAtmopsherics(massiveBody);
                        }
                    }
                }

                // Don't update the animations every frame
                if (timeStep.UpdateLoops < 16)
                {
                    foreach (ISpaceCraft spaceCraft in _spaceCrafts)
                    {
                        spaceCraft.UpdateAnimations(timeStep);
                    }
                }

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

                foreach (ISpaceCraft spaceCraft in _spaceCrafts)
                {
                    spaceCraft.UpdateController(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();
        }
コード例 #2
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();
        }