Exemplo n.º 1
0
 public void draw()
 {
     //Calls the draw method in each mesh object within all of the entity models.
     foreach (Entity ent in projectiles)
     {
         foreach (ModelMesh mesh in ent.model.Meshes)
         {
             foreach (BasicEffect e in mesh.Effects)
             {
                 //The effect is modified to be accurate to the tick's updates.
                 e.World = mesh.ParentBone.ModelTransform;
                 e.View  = camera.getLookMatrix();
             }
             mesh.Draw();
         }
     }
     foreach (Entity ent in targets)
     {
         foreach (ModelMesh mesh in ent.model.Meshes)
         {
             foreach (BasicEffect e in mesh.Effects)
             {
                 e.World = mesh.ParentBone.ModelTransform;
                 e.View  = camera.getLookMatrix();
             }
             mesh.Draw();
         }
     }
     foreach (Entity ent in obstacles)
     {
         foreach (ModelMesh mesh in ent.model.Meshes)
         {
             foreach (BasicEffect e in mesh.Effects)
             {
                 e.World = mesh.ParentBone.ModelTransform;
                 e.View  = camera.getLookMatrix();
             }
             mesh.Draw();
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            rasterizerState                = new RasterizerState();
            rasterizerState.CullMode       = CullMode.None;
            rasterizerState.FillMode       = FillMode.Solid;
            GraphicsDevice.RasterizerState = rasterizerState;

            font = Content.Load <SpriteFont>("Font/Verdana");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //The camera 3D class represents a position and look vector as well as a field of view matrix and methods to simplify looking around.
            Camera3D camera = new Camera3D(Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight, 0.1f, 100.0f), new Vector3(8.0f, 8.0f, 2.0f), new Vector3(-1.0f, -1.0f, 0.0f));

            world = new World(camera);


            //The effect class defines how everything will be drawn, it contains simple lighting as well as the transformation matrices needed to draw to the screen
            effect                    = new BasicEffect(GraphicsDevice);
            effect.World              = Matrix.Identity;
            effect.View               = camera.getLookMatrix();
            effect.Projection         = camera.getFOVMatrix();
            effect.VertexColorEnabled = true;
            effect.LightingEnabled    = true;
            effect.EnableDefaultLighting();

            r = new Random();



            //Very messy, manually making a map for the player to interact with. While it should be in a file and loaded in, this was used for testing
            //and I had to cut planned features.

            Color          c        = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            Color          c1       = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            Color          c2       = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            Color          c3       = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            Color          c4       = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            Color          c5       = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            List <Polygon> polygons = new List <Polygon>();
            Polygon        p        = new Polygon(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Color[] { c, c, c });

            polygons = Util.makeCube(0.5F, c);

            List <ModelMesh> meshes   = new List <ModelMesh>();
            ModelBone        rootBone = new ModelBone();

            rootBone.Transform      = Matrix.CreateTranslation(0, 0, 0);
            rootBone.ModelTransform = Matrix.CreateTranslation(0, 0, 0);
            meshes.Add(Util.makeMeshFromPolygonList(polygons, GraphicsDevice, rootBone));

            Model m = Util.makeModel(meshes, GraphicsDevice, effect, rootBone);

            m.Tag = new PhysicsObject(m, 1.0f, world);
            ((PhysicsObject)m.Tag).addImpulse(new Vector3(0, 0.0f, 0.0f), 1);

            Projectile target = new Projectile(m, world);

            world.registerEntity(target);

            List <Polygon> polyList = new List <Polygon>();

            c        = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            polyList = Util.makeRectPrism(7.0f, 3.0f, 2.0f, c);

            List <ModelMesh> meshList = new List <ModelMesh>();

            meshList.Add(Util.makeMeshFromPolygonList(polyList, GraphicsDevice));

            Model modelObj = Util.makeModel(meshList, GraphicsDevice, effect);

            modelObj.Tag = new PhysicsObject(modelObj, 80.0f, world)
            {
                gravity = false, position = new Vector3(0, 0, -3.0f)
            };
            ((PhysicsObject)modelObj.Tag).addImpulse(new Vector3(0, -0.0f, -0.0f), 1);


            Obstacle wallHorizontal = new Obstacle(modelObj, world);

            world.registerEntity(wallHorizontal);

            List <Polygon> polygonList = new List <Polygon>();

            c           = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
            polygonList = Util.makeRectPrism(4.0f, 4.0f, 2.0f, c);

            List <ModelMesh> modelMeshList = new List <ModelMesh>();

            modelMeshList.Add(Util.makeMeshFromPolygonList(polygonList, GraphicsDevice));

            Model modelObject = Util.makeModel(modelMeshList, GraphicsDevice, effect);

            modelObject.Tag = new PhysicsObject(modelObject, 80.0f, world)
            {
                gravity = false, position = new Vector3(0, 0, 3.0f)
            };

            Obstacle wallVertical = new Obstacle(modelObject, world);

            world.registerEntity(wallVertical);

            c = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());

            polygonList = Util.makeMultiColRectPrism(30.0f, 30.0f, 30.0f, c, c1, c2, c3, c4, c5);

            modelMeshList = new List <ModelMesh>();

            modelMeshList.Add(Util.makeMeshFromPolygonList(polygonList, GraphicsDevice));

            modelObject     = Util.makeModel(modelMeshList, GraphicsDevice, effect);
            modelObject.Tag = new PhysicsObject(modelObject, 1.0f, world)
            {
                gravity = false, staticPhysics = true
            };

            Obstacle terrain = new Obstacle(modelObject, world);

            world.registerEntity(terrain);
        }