Пример #1
0
        public override void Execute(GameTime gameTime)
        {
            base.Execute(gameTime);

            float targetAngle = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(ObjectToRotate.WorldPosition, Position);
            float distance    = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(ObjectToRotate, Position);

            if (distance < 0.005f)
            {
                // ObjectToRotate.WorldRotation = targetAngle;
                Completed = true;
                return;
            }

            float directionToRotate = Trigonometry.GetRotateDirectionForShortestRotation(ObjectToRotate, Position);

            if (!GlobalVariables.SIMPLEPHYSICS)
            {
                float distanceToStartDeccelerating = ObjectToRotate.RigidBody.AngularVelocity * (float)Math.Ceiling(ObjectToRotate.RigidBody.AngularVelocity / acceleration) * 0.5f;
                if (distance > distanceToStartDeccelerating)
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * acceleration;
                }
                else
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(ObjectToRotate.WorldRotation - targetAngle) * acceleration;
                }
            }
            else
            {
                ObjectToRotate.RigidBody.AngularVelocity = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * ObjectToRotate.RigidBody.MaxAngularVelocity;
            }
        }
Пример #2
0
        public override void Initialize()
        {
            base.Initialize();

            foreach (ShipAddOn shipAddOn in ShipAddOns.Values)
            {
                if (shipAddOn.ShipAddOnData.Orientable)
                {
                    // If our add on is orientable, orient it so that it is facing along the line made by the centre of the ship and the addon position - the order of stuff here matters!
                    // Crude, but I think it will suffice
                    shipAddOn.LocalOrientation = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(WorldPosition, shipAddOn.WorldPosition);
                    shipAddOn.LocalRotation    = shipAddOn.LocalOrientation;
                }
            }
        }
Пример #3
0
        public override void Execute(GameTime gameTime)
        {
            base.Execute(gameTime);

            float targetAngle = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(ObjectToRotate.WorldPosition, Target.WorldPosition);
            float distance    = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(ObjectToRotate, Target.WorldPosition);

            // Once we get sufficiently close to our target, we lock on and no longer use physics to drive the rotation
            if (distance < 0.005f || lockedOn)
            {
                lockedOn = true;
                // ObjectToRotate.WorldRotation = targetAngle;
                ObjectToRotate.RigidBody.FullAngularStop();

                return;
            }

            float directionToRotate = Trigonometry.GetRotateDirectionForShortestRotation(ObjectToRotate, Target.WorldPosition);

            if (!GlobalVariables.SIMPLEPHYSICS)
            {
                float distanceToStartDeccelerating = ObjectToRotate.RigidBody.AngularVelocity * (float)Math.Ceiling(ObjectToRotate.RigidBody.AngularVelocity / acceleration) * 0.5f;
                if (distance > distanceToStartDeccelerating)
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * acceleration;
                }
                else
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(ObjectToRotate.WorldRotation - targetAngle) * acceleration;
                }
            }
            else
            {
                ObjectToRotate.RigidBody.AngularVelocity = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * ObjectToRotate.RigidBody.MaxAngularVelocity;
            }
        }
Пример #4
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            LocalRotation = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(Camera.ScreenToGameCoords(WorldPosition), TargetPosition) - Parent.WorldRotation;
        }