Exemple #1
0
        internal void Update(GameTime gameTime)
        {
            ((DiffuseLight)SystemCore.ActiveScene.LightsInScene[0]).LightDirection = Vector3.Normalize(Sun.Transform.AbsoluteTransform.Translation);

            List <GameObject> planets = SystemCore.GameObjectManager.GetAllObjects().FindAll(x => x is Planet);

            SortForRendering(planets);

            bool inAtmostphere = false;

            foreach (Planet p in planets)
            {
                double distanceToPlanet = SolarSystem.CalculateDistanceToPlanet(p,
                                                                                PlayerShip.GetComponent <HighPrecisionPosition>().Position);
                if (distanceToPlanet < p.radius * 2)
                {
                    p.AddToInfluence(PlayerShip);

                    if (p.HasAtmosphere)
                    {
                        if (WithinAtmosphere(p, PlayerShip))
                        {
                            PlayerShip.SetInAtmosphere();
                            inAtmostphere = true;
                        }
                    }
                }
                else
                {
                    p.RemoveFromInfluence(PlayerShip);
                }
            }
            if (!inAtmostphere)
            {
                PlayerShip.ExitedAtmosphere();
            }
        }
Exemple #2
0
        public void Update(GameTime gameTime)
        {
            //determine max vel according to environment.
            float maxVelToUse = maxVelocitySpace;

            if (InOrbit)
            {
                maxVelToUse = maxVelocityOrbit;
            }

            if (InAtmosphere)
            {
                maxVelToUse = maxVelocityAtmoshpere;

                Vector3 realWorldPos = SolarSystem.GetRenderPosition(HighPrecisionPositionComponent.Position, CurrentPlanet.Position.Position);
                realWorldPos.Normalize();

                float downAngle = Vector3.Dot(Transform.AbsoluteTransform.Forward, realWorldPos);

                //increase max velocity as the nose points down, and vice versa.
                float velAdjustForGravity = MonoMathHelper.MapFloatRange(0, 2, 0.5f, 2f, downAngle + 1);
                maxVelToUse *= velAdjustForGravity;
            }



            if (desiredMainThrust > currentMainThrust)
            {
                currentMainThrust = MathHelper.Lerp(currentMainThrust, desiredMainThrust, mainThrustUpSpeed);
            }
            else
            {
                currentMainThrust = MathHelper.Lerp(currentMainThrust, desiredMainThrust, mainThrustDownSpeed);
            }


            if (desiredSuperThrust > currentSuperThrust)
            {
                currentSuperThrust = MathHelper.Lerp(currentSuperThrust, desiredSuperThrust, mainThrustUpSpeed);
            }
            else
            {
                currentSuperThrust = MathHelper.Lerp(currentSuperThrust, desiredSuperThrust, mainThrustDownSpeed);
            }


            rollThrust  = MathHelper.Lerp(rollThrust, desiredRollThrust, otherThrustAlterationSpeed * 2);
            pitchThrust = MathHelper.Lerp(pitchThrust, desiredPitchThrust, otherThrustAlterationSpeed);
            yawThrust   = MathHelper.Lerp(yawThrust, desiredYawThrust, otherThrustAlterationSpeed);


            if (currentMainThrust > 0)
            {
                Vector3 velChange = (maxVelToUse * currentMainThrust * Transform.AbsoluteTransform.Forward) / mass;
                velChange *= (100 - (mainThrustBleed * 100));
                velocity  += velChange;
            }

            velocity += lateralThrust;

            if (velocity.Length() > maxVelToUse)
            {
                float   overShootVel = velocity.Length() - maxVelToUse;
                Vector3 adjustment   = -Vector3.Normalize(velocity) * (overShootVel / 20f);
                velocity += adjustment;
            }

            if (currentSuperThrust > 0)
            {
                velocity += (currentSuperThrust) * superThrustVelocity * Transform.AbsoluteTransform.Forward;
            }



            movementAppliedLastFrame = velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Transform.HighPrecisionTranslate(movementAppliedLastFrame);


            if (rollThrust != 0)
            {
                Transform.Rotate(Transform.AbsoluteTransform.Forward,
                                 rollThrust * (float)gameTime.ElapsedGameTime.TotalSeconds * 100);
            }
            if (pitchThrust != 0)
            {
                Transform.Rotate(Transform.AbsoluteTransform.Left,
                                 pitchThrust * (float)gameTime.ElapsedGameTime.TotalSeconds * 100);
            }
            if (yawThrust != 0)
            {
                Transform.Rotate(Transform.AbsoluteTransform.Up,
                                 yawThrust * (float)gameTime.ElapsedGameTime.TotalSeconds * 100);
            }


            HandleCollision();

            SolarSystem.AdjustObjectsForRendering(HighPrecisionPositionComponent.Position);

            velocity           *= mainThrustBleed;
            lateralThrust      *= lateralThrustBleed;
            desiredRollThrust  *= orientationThrustBleed;
            desiredPitchThrust *= orientationThrustBleed;
            desiredYawThrust   *= orientationThrustBleed;
            pitchThrust        *= orientationThrustBleed;
            yawThrust          *= orientationThrustBleed;
            rollThrust         *= orientationThrustBleed;

            if (!LookMode)
            {
                shipCameraObject.Transform.AbsoluteTransform = Transform.AbsoluteTransform;
            }
        }