Beispiel #1
0
        private static void GetVerticesAndIndicesFromModel(Microsoft.Xna.Framework.Graphics.Model collisionModel, string collisionMesh, out Vector3[] vertices, out int[] indices)
        {
            if (string.IsNullOrEmpty(collisionMesh) || !collisionModel.Meshes.Any(mesh => mesh.Name == collisionMesh))
            {
                TriangleMesh.GetVerticesAndIndicesFromModel(collisionModel, out vertices, out indices);
                return;
            }

            var verticesList = new List <Vector3>();
            var indicesList  = new List <int>();
            var transforms   = new Matrix[collisionModel.Bones.Count];

            collisionModel.CopyAbsoluteBoneTransformsTo(transforms);

            Matrix transform;

            foreach (Microsoft.Xna.Framework.Graphics.ModelMesh mesh in collisionModel.Meshes)
            {
                if (mesh.Name == collisionMesh)
                {
                    if (mesh.ParentBone != null)
                    {
                        transform = transforms[mesh.ParentBone.Index];
                    }
                    else
                    {
                        transform = Matrix.Identity;
                    }
                    TriangleMesh.AddMesh(mesh, transform, verticesList, indicesList);
                }
            }

            vertices = verticesList.ToArray();
            indices  = indicesList.ToArray();
        }
Beispiel #2
0
        /// <param name="monoGameModel"><see cref="Microsoft.Xna.Framework.Graphics.Model"/> data loaded in MonoGame's format.</param>
        public Model(MonoGameModel monoGameModel)
        {
            MonoGameModel = monoGameModel;
            BoundingBox   = CalculateBoundingBox();

            var dimensions = BoundingBox.Max - BoundingBox.Min;

            Depth  = dimensions.Z;
            Height = dimensions.Y;
            Width  = dimensions.X;
        }
Beispiel #3
0
        public Barrack(byte a_id, Microsoft.Xna.Framework.Graphics.Model a_model, int a_hp, int a_maxHP, Vector3 a_position, addUnderAttackPosition a_function)
            : base(a_id, a_model, false, a_hp, a_maxHP, a_position, BuildTime, SupplyValue, Price, a_function)
        {
            m_type = ThingType.C_Barrack;

            m_size = new Vector3(3, 3, 2);

            m_actionbox[0, 2] = new ObjectAction("Cancel",
                                                 "Cancels the building from being built and returns ~75% of resources",
                                                 Microsoft.Xna.Framework.Input.Keys.Escape,
                                                 ObjectAction.Type.Instant, CancelMeFunction);
        }
Beispiel #4
0
 public static void UnloadStaticContent()
 {
     if (LoadedContentManagers.Count != 0)
     {
         LoadedContentManagers.RemoveAt(0);
         mRegisteredUnloads.RemoveAt(0);
     }
     if (LoadedContentManagers.Count == 0)
     {
         if (Model != null)
         {
             Model = null;
         }
     }
 }
Beispiel #5
0
 public static void LoadStaticContent(string contentManagerName)
 {
     if (string.IsNullOrEmpty(contentManagerName))
     {
         throw new System.ArgumentException("contentManagerName cannot be empty or null");
     }
     ContentManagerName = contentManagerName;
                 #if DEBUG
     if (contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager)
     {
         HasBeenLoadedWithGlobalContentManager = true;
     }
     else if (HasBeenLoadedWithGlobalContentManager)
     {
         throw new System.Exception("This type has been loaded with a Global content manager, then loaded with a non-global.  This can lead to a lot of bugs");
     }
                 #endif
     bool registerUnload = false;
     if (LoadedContentManagers.Contains(contentManagerName) == false)
     {
         LoadedContentManagers.Add(contentManagerName);
         lock (mLockObject)
         {
             if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
             {
                 FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ModelTestStaticUnload", UnloadStaticContent);
                 mRegisteredUnloads.Add(ContentManagerName);
             }
         }
         Model = FlatRedBall.FlatRedBallServices.Load <Microsoft.Xna.Framework.Graphics.Model>(@"content/entities/modeltest/model", ContentManagerName);
     }
     if (registerUnload && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
     {
         lock (mLockObject)
         {
             if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
             {
                 FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ModelTestStaticUnload", UnloadStaticContent);
                 mRegisteredUnloads.Add(ContentManagerName);
             }
         }
     }
     CustomLoadStaticContent(contentManagerName);
 }
Beispiel #6
0
        /// <summary>
        /// Add a player to the player list, overwriting any existing member
        /// whose key is also "key".
        /// </summary>
        /// <param name="key">Key of the tank. This is the tank's name. Should be unique.</param>
        /// <param name="value">The tank object stored.</param>
        public void Add(int key, PlayerTank value)
        {
            if (players.ContainsKey(key))
            {
                Remove(key);
            }

            if (value.RenderID != -1)
            {
                throw new Exception("Integrity error: Player already in renderer.");
            }

            int id = ServiceManager.Scene.Add(value, 2);

            value.RenderID = id;

            Microsoft.Xna.Framework.Graphics.Model turretModel =
                ServiceManager.Resources.GetModel(
                    "weapons\\" + value.Weapon.Model);
            Object3 turret = new Object3(turretModel,
                                         Vector3.Zero); // The turret's position shouldn't matter since it's being
                                                        // attached to the tank.

            int turretId = ServiceManager.Scene.Add(turret, 0);

            if (value.HealthBar != null)
            {
                int healthBarId = ServiceManager.Scene.Add(value.HealthBar, 4);
                value.HealthBarRenderID = healthBarId;
            }

            if (value.NameObject != null)
            {
                int nameBarId = ServiceManager.Scene.Add(value.NameObject, 4);
                value.NameObjectRenderID = nameBarId;
            }

            turret.Attach(value, Constants.TURRET_MOUNT);
            value.SetTurret(turretId, turret);
            players.Add(key, value);
        }
Beispiel #7
0
        /// <summary>
        /// Constructs the front end and the internal physics representation of the Vehicle.
        /// </summary>
        /// <param name="position">Position of the Vehicle.</param>
        /// <param name="space">Space to add the Vehicle to.</param>
        /// <param name="camera">Camera to attach to the Vehicle.</param>
        /// <param name="game">The running game.</param>
        /// <param name="drawer">Drawer used to draw the Vehicle.</param>
        /// <param name="wheelModel">Model of the wheels.</param>
        /// <param name="wheelTexture">Texture to use for the wheels.</param>
        public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Microsoft.Xna.Framework.Graphics.Model wheelModel, Microsoft.Xna.Framework.Graphics.Texture2D wheelTexture)
        {
            var bodies = new List <CompoundShapeEntry>
            {
                new CompoundShapeEntry(new BoxShape(2.5f, .75f, 4.5f), new Vector3(0, 0, 0), 60),
                new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new Vector3(0, .75f / 2 + .3f / 2, .5f), 1)
            };
            var body = new CompoundBody(bodies, 61);

            body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0);
            body.Position = position; //At first, just keep it out of the way.
            Vehicle       = new Vehicle(body);

            var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2);

            //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them.
            Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);

            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, 1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, -1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, 1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, -1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));


            foreach (Wheel wheel in Vehicle.Wheels)
            {
                //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes.
                wheel.Shape.FreezeWheelsWhileBraking = true;

                //By default, wheels use as many iterations as the space.  By lowering it,
                //performance can be improved at the cost of a little accuracy.
                //However, because the suspension and friction are not really rigid,
                //the lowered accuracy is not so much of a problem.
                wheel.Suspension.SolverSettings.MaximumIterationCount      = 1;
                wheel.Brake.SolverSettings.MaximumIterationCount           = 1;
                wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1;
                wheel.DrivingMotor.SolverSettings.MaximumIterationCount    = 1;
            }

            Space = space;

            Space.Add(Vehicle);
            ModelDrawer = drawer;
            DisplayModel model;

            WheelModels = new List <DisplayModel>();
            for (int k = 0; k < 4; k++)
            {
                Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject";
                model = new DisplayModel(wheelModel, ModelDrawer);
                ModelDrawer.Add(model);
                WheelModels.Add(model);
                model.Texture = wheelTexture;
            }



            CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game);
        }
		public static void UnloadStaticContent ()
		{
			if (LoadedContentManagers.Count != 0)
			{
				LoadedContentManagers.RemoveAt(0);
				mRegisteredUnloads.RemoveAt(0);
			}
			if (LoadedContentManagers.Count == 0)
			{
				if (Model != null)
				{
					Model= null;
				}
			}
		}
		public static void LoadStaticContent (string contentManagerName)
		{
			if (string.IsNullOrEmpty(contentManagerName))
			{
				throw new System.ArgumentException("contentManagerName cannot be empty or null");
			}
			ContentManagerName = contentManagerName;
			#if DEBUG
			if (contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager)
			{
				HasBeenLoadedWithGlobalContentManager = true;
			}
			else if (HasBeenLoadedWithGlobalContentManager)
			{
				throw new System.Exception("This type has been loaded with a Global content manager, then loaded with a non-global.  This can lead to a lot of bugs");
			}
			#endif
			bool registerUnload = false;
			if (LoadedContentManagers.Contains(contentManagerName) == false)
			{
				LoadedContentManagers.Add(contentManagerName);
				lock (mLockObject)
				{
					if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
					{
						FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ModelTestStaticUnload", UnloadStaticContent);
						mRegisteredUnloads.Add(ContentManagerName);
					}
				}
				Model = FlatRedBall.FlatRedBallServices.Load<Microsoft.Xna.Framework.Graphics.Model>(@"content/entities/modeltest/model", ContentManagerName);
			}
			if (registerUnload && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
			{
				lock (mLockObject)
				{
					if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
					{
						FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ModelTestStaticUnload", UnloadStaticContent);
						mRegisteredUnloads.Add(ContentManagerName);
					}
				}
			}
			CustomLoadStaticContent(contentManagerName);
		}
Beispiel #10
0
 public Barbarian(byte a_id, Microsoft.Xna.Framework.Graphics.Model a_model, int a_hp, int a_maxHP, Vector3 a_position, float a_speed, addUnderAttackPosition a_function)
     : base(a_id, a_model, true, a_hp, a_maxHP, a_position, a_speed, BuildTime, SupplyValue, Price, a_function)
 {
     m_type = ThingType.C_Barbarian;
     m_size = new Vector3(1);
 }