コード例 #1
0
ファイル: Ship.cs プロジェクト: veyvin/SystemWars
        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;
            }
        }