Beispiel #1
0
        /// <summary>
        /// This function is used to orient the mob towards an arbitrary point (step)
        /// </summary>
        /// <param name="step">Point the mob has to face</param>
        /// <param name="thresholdAngleCos">The cosine of the threshold angle, if the cos is inferior to this value, the mob will be rotated. 0.978f typically</param>
        /// <param name="turningSpeed">The angle in radiants the mob will be rotated to</param>
        /// <returns></returns>
        /// More efficient method and the source of this at...
        /// http://forums.create.msdn.com/forums/p/2693/13503.aspx
        public static Quaternion OrientTowardsVector3(Pawn mob, Vector3 step, float thresholdAngleCos, float turningSpeed)
        {
            Vector3 mobToTargetVector = new Vector3();
            Vector3 mobOrient = new Vector3();
            int rotationSign = 0;
            float mobToTargetAngle;
            Vector3 crossProduct = new Vector3();

            //We calculate the target to mob vector.
            mobToTargetVector = Vector3.Normalize(step - mob.Position);
            //We calculate the direction vector in the X,Y reference plane
            mobOrient = Vector3.Transform(new Vector3(0.0f, 1.0f, 0.0f), Matrix.CreateFromQuaternion(mob.Rotation));

            //The cross product gives out the cosine of the angle.
            mobToTargetAngle = Vector3.Dot(mobToTargetVector, mobOrient);

            if (mobToTargetAngle < thresholdAngleCos /*0.978f*/) // if the cosine value is inferior to a preset value, we have to turn
            {
                crossProduct = Vector3.Cross(mobToTargetVector, mobOrient);
                //If the cross product is positive regarding the z axis then we have to turn in the anti trigonometric sense
                //If the cross product is negative regarding the z axis then we have to turn in the trigonometric sense
                rotationSign = -Math.Sign(crossProduct.Z);
                return Quaternion.Concatenate(mob.Rotation, Quaternion.CreateFromAxisAngle(new Vector3(0f, 0f, 1f), rotationSign * turningSpeed));
            }
            else
            {
                // It is not necessary to turn, so we do not
                return mob.Rotation;
            }
        }
Beispiel #2
0
 //This shoots fireballs only right now!
 public void Shoot(Vector3 fromPosition, Quaternion fromRotation, Pawn shotBy, GameTime gameTime)
 {
     Fireball newBullet = new Fireball(GameState, fromPosition, fromRotation, shotBy);
     lastFired = gameTime.TotalGameTime.TotalMilliseconds;
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Init some misc stuff
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont = Content.Load<SpriteFont>("Fonts/SmallText");
            thumbstick = Content.Load<Texture2D>(GameConstants.TxtThumbsticks);
            ground = new Terrain(GameConstants.MdlGround, gameState);
            boundingSphere = new Pawn(GameConstants.MdlSphere, gameState);
            Fireball.Texture = Content.Load<Texture2D>(GameConstants.TxtFireball);
            frameRate.LoadContent(spriteBatch);

            //quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1);
            //quadTexture = Content.Load<Texture2D>("Textures/Glass");
            //quadEffect = new BasicEffect(graphics.GraphicsDevice);
            //quadEffect.EnableDefaultLighting();

            //quadEffect.World = Matrix.Identity;
            //quadEffect.View = gameCamera.ViewMatrix;
            //quadEffect.Projection = gameCamera.ProjectionMatrix;
            //quadEffect.TextureEnabled = true;
            //quadEffect.Texture = quadTexture;

            //myBoundingBox = new BoundingBox(new Vector3(0, 0, 0), new Vector3(8, 4, 15));

            //Init fuel cells
            gameState.FuelCells = new FuelCell[GameConstants.NumFuelCells];
            for (int index = 0; index < gameState.FuelCells.Length; index++)
                gameState.FuelCells[index] = new FuelCell(GameConstants.MdlFuelcell, gameState);

            //Init barriers
            gameState.Barriers = new Barrier[GameConstants.NumBarriers];
            int randomBarrier = random.Next(3);

            for (int index = 0; index < GameConstants.NumBarriers; index++)
            {
                BarrierType type = BarrierType.Cube;
                switch (randomBarrier)
                {
                    case 0:
                        type = BarrierType.Cube;
                        break;
                    case 1:
                        type = BarrierType.Cylinder;
                        break;
                    case 2:
                        type = BarrierType.Pryamid;
                        break;
                }
                gameState.Barriers[index] = Barrier.BarrierFromType(type, gameState);
                randomBarrier = random.Next(3);
            }
            PlaceFuelCellsAndBarriers();

            //Init fuel carrier
            gameState.Avatar = new FuelCarrier(GameConstants.MdlAvatar, gameState);
            gameState.WireFrameModel = boundingSphere;
            gameState.Projectiles = new List<Projectile>();
        }
Beispiel #4
0
 public Fireball(GameState state, Vector3 position, Quaternion rotation, Pawn parent)
     : base(state, position, rotation)
 {
     ShotBy = parent;
     GameState.Projectiles.Add(this);
 }