Пример #1
0
        }   // end of Setup()

        /// <summary>
        /// c'tor for use when targetting a point in space rather than an object.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="targetPosition"></param>
        /// <param name="launcher"></param>
        /// <param name="verbPayload"></param>
        /// <param name="trackingMode"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        static public CruiseMissile Create(
            Vector3 position,                                       // Starting position.
            Vector3 targetPosition,                                 // Location we're trying to hit.
            GameActor launcher,                                     // Actor that launched this missile.
            float initialRotation,                                  //
            GameThing.Verbs verbPayload,
            int damage,
            MissileChassis.BehaviorFlags behavior,
            Classification.Colors color,
            float desiredSpeed,
            float missileLifetime,
            bool wantSmoke)
        {
            CruiseMissile cm = NextAvailable();

            cm.Setup(
                position,
                launcher,
                initialRotation,
                verbPayload,
                damage,
                behavior,
                color,
                desiredSpeed,
                wantSmoke);

            //Vector3 forward = Vector3.Normalize(targetPosition - position);
            //Vector3 side = Vector3.Cross(Vector3.UnitZ, forward);
            //if (side.LengthSquared() < 0.01f)
            //{
            //    side = Vector3.Cross(Vector3.UnitY, forward);
            //}
            //side.Normalize();
            //Vector3 up = Vector3.Normalize(Vector3.Cross(forward, side));
            //Matrix l2w = Matrix.Identity;
            //l2w.Right = forward;
            //l2w.Up = up;
            //l2w.Forward = side;
            //l2w.Translation = position;
            //cm.Movement.LocalMatrix = l2w;

            MissileChassis missileChassis = cm.Chassis as MissileChassis;

            Vector3 direction = targetPosition - launcher.WorldCollisionCenter;
            Vector3 delta     = Vector3.Normalize(direction);

            float desiredPitch = (float)(Math.Atan2(delta.Z, new Vector2(delta.X, delta.Y).Length()));

            missileChassis.PitchAngle = desiredPitch;

            missileChassis.DeathTime      = Time.GameTimeTotalSeconds + missileLifetime * 1.1f;
            missileChassis.TargetPosition = position + delta * desiredSpeed * missileLifetime * 10f;
            missileChassis.TargetObject   = null;

            return(cm);
        }   // end of CruiseMissile Create
Пример #2
0
        }   // end of CruiseMissile Create

        /// <summary>
        /// c'tor to use when shooting at a particular object
        /// </summary>
        /// <param name="position"></param>
        /// <param name="targetPosition"></param>
        /// <param name="targetThing"></param>
        /// <param name="launcher"></param>
        /// <param name="verbPayload"></param>
        /// <param name="trackingMode"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        static public CruiseMissile Create(
            Vector3 position,                                       // Starting position.
            GameThing targetThing,                                  // Object we're trying to hit.
            GameActor launcher,                                     // Actor that launched this missile.
            float initialRotation,                                  //
            GameThing.Verbs verbPayload,
            int damage,
            MissileChassis.BehaviorFlags behavior,
            Classification.Colors color,
            float desiredSpeed,
            float missileLifetime,
            bool wantSmoke)
        {
            CruiseMissile cm = NextAvailable();

            cm.Setup(
                position,
                launcher,
                initialRotation,
                verbPayload,
                damage,
                behavior,
                color,
                desiredSpeed,
                wantSmoke);

            MissileChassis missileChassis = cm.Chassis as MissileChassis;

            // Set initial speed taking into account the velocity of the launcher.
            Vector3 missileVelocity = new Vector3((float)Math.Cos(initialRotation), (float)Math.Sin(initialRotation), 0);
            float   dot             = Vector3.Dot(missileVelocity, launcher.Movement.Velocity);

            missileChassis.Speed = Math.Max(desiredSpeed, dot);

            missileChassis.DeathTime      = Time.GameTimeTotalSeconds + missileLifetime;
            missileChassis.TargetPosition = targetThing.WorldCollisionCenter;
            missileChassis.TargetObject   = targetThing;

            return(cm);
        }   // end of CruiseMissile Create