Ejemplo n.º 1
0
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            base.LoadContent(content);

            BlockData.Initialize(Device, content);

            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);


            map = new Map(Device);

            partition = new MapPartition(map);
            engine = new PhysicsEngine3D(partition);

            MeshBuilder mb = new MeshBuilder(Device);
            sphere = mb.CreateSphere(0.1f, 10, 10);
            marker = new MeshNode(sphere);

            placeType = 1;

            primBatch = new PrimitiveBatch(Device);


        }
Ejemplo n.º 2
0
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager c, Microsoft.Xna.Framework.Graphics.GraphicsDevice g)
        {
            base.LoadContent(c, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            balls = new List<Ball>();

            for (int i = 0; i < 50; i++)
            {
                balls.Add(new Ball(new Vector3(i * 2, 2, 2), new Vector3(i + 1, -i, i % 2) * 0.1f, 0.5f));
            }

            planes = new List<Plane>();

            planes.Add(new Plane(Vector3.Right, 0));
            planes.Add(new Plane(Vector3.Up, 0));
            planes.Add(new Plane(new Vector3(0, 0, 1), 0));
            planes.Add(new Plane(Vector3.Left, -10));
            planes.Add(new Plane(Vector3.Down, -10));
            planes.Add(new Plane(new Vector3(0, 0, -1), -10));

            MeshBuilder mb = new MeshBuilder(g);
            sphere = mb.CreateSphere(1f, 10, 10);
        }
Ejemplo n.º 3
0
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            base.LoadContent(content);

            map = new Map(Device, "startPosTest.txt");
            //        map = new Map();
            BlockData.Initialize(Device, content);
            primBatch = new PrimitiveBatch(Device);

            MeshBuilder mb = new MeshBuilder(Device);
            mb.Begin();

            //mb.AddCylinder(1, 1, 50);
            mb.AddSphere(1, 20, 20);
            testMesh = mb.End();

            mNode = new MeshNode(testMesh);
            mNode.SetPivot(new Vector3(0, -1f, 0));
            mNode.SetScl(new Vector3(1, 5, 1));
            MeshNode child = new MeshNode(testMesh);
            child.SetPos(new Vector3(0, 2, 0));
            MeshNode another = new MeshNode(testMesh);
            another.SetPos(new Vector3(0, 2, 0));

            //Mesh sphere = mb.CreateSphere(0.1f, 10, 10);
            //startMarker = new MeshNode(sphere);
            //startMarker.SetPos(map.StartPos);
            //child.AddChild(another);
            //mNode.AddChild(child);
        }
Ejemplo n.º 4
0
        //A scenegraph is composed of SceneNodes
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new FirstPersonCamera(0.5f, 5f);        //0.5f is the turn speed for the camera, and 5f is the translational speed
            cam.Pos = new Vector3(3, 3, 13);              //Move our camera to the point (3, 3, 13)
            primBatch = new PrimitiveBatch(g);            //Initialize our PrimitiveBatch

            //Define the objects in our scene
            Mesh sphere, cylinder, box;                   //Define the meshes we will use for the robot arm
                                                          //A mesh holds a list of vertices, and a list of indices which represent triangles

            MeshNode arm, elbow, forearm, wrist, hand;    //Define all the parts of the robot arm we will use

            MeshBuilder mb = new MeshBuilder(g);          //MeshBuilder is a helper class for generating 3D geometry
                                                          //It has some built in functions to create primitives, as well as
                                                          //functions to create your own arbitrary meshes

            //Genererate our geometry
            //All geometry created is centered around the origin in its local coordinate system
            sphere = mb.CreateSphere(0.5f, 15, 15);       //Create a sphere mesh, with radius 0.5 and with 15 subdivisions
            cylinder = mb.CreateCylinder(0.3f, 2.0f, 15); //Create a cylinder with radius 0.3, a height of 2, and 15 subdivisions
            box = mb.CreateBox(0.8f, 1.4f, 0.1f);         //Create a box with width 0.8, height of 1.4, and depth of 0.1

            shoulder = new MeshNode(sphere);              //Assign the sphere mesh to our shoulder node

            arm = new MeshNode(cylinder);                 //Assign the cylinder mesh to our arm node
            arm.SetPos(new Vector3(0, -1, 0));            //Translate the arm down 1 on the y axis

            elbow = new MeshNode(sphere);                 //Assign a sphere to our elbow node
            elbow.SetPos(new Vector3(0, -2, 0));          //Translate the elbow down 2 on the y axis

            forearm = new MeshNode(cylinder);             //Assign a cylinder to our forearm node
            forearm.SetPos(new Vector3(0, -1, 0));        //Translate the forearm down 1 on the y axis

            wrist = new MeshNode(sphere);                 //Assign a sphere for the wrist node
            wrist.SetPos(new Vector3(0, -2, 0));          //Translate the wrist down 2 on the y axis

            hand = new MeshNode(box);                     //Assign the box to the hand node
            hand.SetPos(new Vector3(0, -0.7f, 0));        //Translate the hand down 0.7 (half the height of the box) on the y axis

            shoulder.AddChild(arm);                       //The shoulder is the root of this scene, in our case. It is the parent
            shoulder.AddChild(elbow);                     //of both the arm and the elbow

            elbow.AddChild(forearm);                      //The elbow is the parent of the forearm and wrist
            elbow.AddChild(wrist);

            wrist.AddChild(hand);                         //The wrist is the parent of the hand

            shoulder.SetPos(new Vector3(0, 5, 0));        //This call effectively translates the entire arm up 5 on the y axis
        }
Ejemplo n.º 5
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            MeshBuilder mb = new MeshBuilder(g);
            sphere = mb.CreateSphere(1f, 10, 10);

            setupEngine();
        }
Ejemplo n.º 6
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new FirstPersonCamera(0.5f, 5f);
            cam.Pos = new Vector3(5, 1, 10);
            primBatch = new PrimitiveBatch(g);

            animation = Animation.Parse("Content/MotionCaptures/BriskWalk1_All.tsv");

            spheres = new List<MeshNode>();
            MeshBuilder mb = new MeshBuilder(Device);

            for (int i = 0; i < animation.GetNumMarkers(); i++)
            {
                spheres.Add(new MeshNode(mb.CreateSphere(0.06f, 10, 10)));
            }
        }
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new ThirdPersonCamera(targetPos, 5.0f, 0.2f);

            primBatch = new PrimitiveBatch(g);            //Initialize our PrimitiveBatch
            MeshBuilder mb = new MeshBuilder(g);
            Mesh triangle;// = mb.CreateSphere(0.3f, 15, 15);
            mb.Begin();
             //       mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), true);
             //       mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 1), true);
            mb.AddQuad(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(2, 1, 0), new Vector3(1, 0, 0), true, new Vector2(0, 0), new Vector2(1, 1), new Vector2(2, 1), new Vector2(1, 0));
            triangle = mb.End();

            triangle.Texture = content.Load<Texture2D>("Cube");
            target = new MeshNode(triangle);
            target.SetPos(targetPos);
        }
Ejemplo n.º 8
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            renderer = new DeferredRenderer(g, content);

            MeshBuilder mb = new MeshBuilder(g);
            Mesh box = mb.CreateBox(1, 1, 1);
            mb.Begin();
            mb.AddQuad(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(100, 0, 100), new Vector3(-100, 0, 100), false, Vector2.Zero, Vector2.One);
            Mesh floor = mb.End();
            box.Texture = content.Load<Texture2D>("Cube");
            floor.Texture = content.Load<Texture2D>("Cube");
            meshes.Add(box);
            meshes.Add(floor);
        }
Ejemplo n.º 9
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            MeshBuilder mb = new MeshBuilder(Device);
            mb.Begin();
            mb.AddSphere(radius, 20, 20);
            Mesh sphereMesh = mb.End();

            sphere = new MeshNode(sphereMesh);
            sphere.SetPos(new Vector3(5, 5, 5));

            planes = new List<Plane>();
            planes.Add(new Plane(Vector3.Right, 0));
            planes.Add(new Plane(Vector3.Up, 0));
            planes.Add(new Plane(new Vector3(0, 0, 1), 0));
            planes.Add(new Plane(Vector3.Left, -10));
            planes.Add(new Plane(Vector3.Down, -10));
            planes.Add(new Plane(new Vector3(0, 0, -1), -10));
        }
Ejemplo n.º 10
0
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            base.LoadContent(content);

            BlockData.Initialize(Device, content);

            //map = new Map(Device, "Content/Levels/ramps.txt"); //Load map
            map = new Map(Device, "Content/Levels/Level1-1.txt");

            MeshBuilder mb = new MeshBuilder(Device);

            buildWalls(mb, content);

            setupNormalMapEffect(content);

            if (singleplayer)
            {
                objectiveLocation = map.getNextObjective(new Vector3(-1, -1, -1)); //get first objective
            }

            partition = new MapPartition(map);

            player = new Player(new Vector3(map.Width/2,20,map.Depth - 2)); //spawn player

            initializePhysicsEngine();

            //Misc initialization stuff
            sphere = mb.CreateSphere(1f, 10, 10);
            destination = mb.CreateSphere(0.5f, 12, 12); //sphere to draw at objective
            destination.Texture = content.Load<Texture2D>("Textures/BlockTextures/Destination");

            sBatch = new SpriteBatch(Device);
            sf = content.Load<SpriteFont>("Fonts/Helvetica");
            primBatch = new PrimitiveBatch(Device);

            playerColor = new Vector3((int.Parse(localPlayerName) % 5) / 5.0f, (int.Parse(localPlayerName) % 3) / 3.0f, (int.Parse(localPlayerName) % 2) / 2.0f);
        }
Ejemplo n.º 11
0
 private void buildWalls(MeshBuilder mb, ContentManager content)
 {
     mb.Begin();
     //add back wall
     mb.AddQuad(new Vector3(1, map.Height - 1, 1), new Vector3(map.Width - 1, map.Height - 1, 1), new Vector3(map.Width - 1, 1, 1), new Vector3(1, 1, 1), false, Vector2.Zero, new Vector2(map.Width, map.Height));
     //add front wall
     mb.AddQuad(new Vector3(map.Width - 1, map.Height - 1, map.Depth - 1), new Vector3(1, map.Height - 1, map.Depth - 1), new Vector3(1, 1, map.Depth - 1), new Vector3(map.Width - 1, 1, map.Depth - 1), false, Vector2.Zero, new Vector2(map.Width, map.Height));
     //add left wall
     mb.AddQuad(new Vector3(1, map.Height - 1, map.Depth - 1), new Vector3(1, map.Height - 1, 1), new Vector3(1, 1, 1), new Vector3(1, 1, map.Depth - 1), false, Vector2.Zero, new Vector2(map.Depth, map.Height));
     //add right wall
     mb.AddQuad(new Vector3(map.Width - 1, map.Height - 1, 1), new Vector3(map.Width - 1, map.Height - 1, map.Depth - 1), new Vector3(map.Width - 1, 1, map.Depth - 1), new Vector3(map.Width - 1, 1, 1), false, Vector2.Zero, new Vector2(map.Depth, map.Height));
     //add floor
     mb.AddQuad(new Vector3(1, 1, 1), new Vector3(map.Width - 1, 1, 1), new Vector3(map.Width - 1, 1, map.Depth - 1), new Vector3(1, 1, map.Depth - 1), false, Vector2.Zero, new Vector2(map.Width, map.Depth));
     walls = mb.End();
     walls.Texture = content.Load<Texture2D>("Textures/BlockTextures/Walls");
     walls.NormalMap = content.Load<Texture2D>("Textures/BlockTextures/WallsN");
 }
Ejemplo n.º 12
0
        private static Mesh BuildConvexRamp(MeshBuilder mb, ContentManager c)
        {
            mb.Begin();
            //mb.AddQuad(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 Vector3(-0.5f, -0.5f, -0.5f), false);
            mb.AddQuad(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 Vector3(0.5f, -0.5f, -0.5f), false, left[0], left[1], left[2], left[3]);
            mb.AddQuad(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 Vector3(-0.5f, -0.5f, -0.5f), false, bottom[0], bottom[1], bottom[2], bottom[3]);

            for (int i = 0; i < sphereIterations; i++)
            {
                //Draw the curved surface, and the two sides
                float angle = ((float)i / sphereIterations) * MathHelper.PiOver2;
                float nextAngle = ((float)(i + 1) / sphereIterations) * MathHelper.PiOver2;
                Vector3 offset = new Vector3(-0.5f);

                Vector3 v1 = new Vector3(0, (float)Math.Cos(angle), (float)Math.Sin(angle)) + offset;
                Vector3 v2 = new Vector3(1, (float)Math.Cos(angle), (float)Math.Sin(angle)) + offset;
                Vector3 v3 = new Vector3(1, (float)Math.Cos(nextAngle), (float)Math.Sin(nextAngle)) + offset;
                Vector3 v4 = new Vector3(0, (float)Math.Cos(nextAngle), (float)Math.Sin(nextAngle)) + offset;

                mb.AddQuad(v1, v2, v3, v4, true, new Vector2(0.5f, i * (0.5f / sphereIterations)), new Vector2(1, (i + 1) * (0.5f / sphereIterations)));

                //Draw the two sides
                v1 = new Vector3(1, 0, 0) + offset;
                v2 = new Vector3(1, (float)Math.Cos(nextAngle), (float)Math.Sin(nextAngle)) + offset;
                v3 = new Vector3(1, (float)Math.Cos(angle), (float)Math.Sin(angle)) + offset;

                //calculate texture coordinates
                Vector2 v1Tex = new Vector2(v1.Z + .5f, -v1.Y + .5f);
                Vector2 v2Tex = new Vector2(v2.Z + .5f, -v2.Y + .5f);
                Vector2 v3Tex = new Vector2(v3.Z + .5f, -v3.Y + .5f);
                v1Tex /= 2;
                v2Tex /= 2;
                v3Tex /= 2;

                //add back side
                mb.AddTriangle(v1, v2, v3, new Vector2(v1Tex.X + .5f, v1Tex.Y + .5f), new Vector2(v2Tex.X + .5f, v2Tex.Y + .5f), new Vector2(v3Tex.X + .5f, v3Tex.Y + .5f), false);
                offset = new Vector3(-1, 0, 0);
                //add front side
                mb.AddTriangle(v1 + offset, v3 + offset, v2 + offset, new Vector2(v1Tex.X + .5f, v1Tex.Y + .5f), new Vector2(v3Tex.X + .5f, v3Tex.Y + .5f), new Vector2(v2Tex.X + .5f, v2Tex.Y + .5f), false);
            }

            mb.RotateAllVerts(Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));

            Mesh m = mb.End();
            m.Texture = c.Load<Texture2D>("Textures/BlockTextures/Block5");
            m.NormalMap = c.Load<Texture2D>("Textures/BlockTextures/Block5N");

            return m;
        }
Ejemplo n.º 13
0
        private static Mesh BuildHalfBoxMesh(MeshBuilder mb, ContentManager c)
        {
            float width = 1f;
            float height = 0.5f;
            float depth = 1f;

            Vector2[] localFront = new Vector2[4];
            Vector2[] localLeft = new Vector2[4];
            Array.Copy(front, localFront, localFront.Length);
            Array.Copy(left, localLeft, localLeft.Length);

            for (int i = 0; i < 2; i++)
            {
                localFront[i].Y = (front[i].Y - 1) / 2 + 1;
                localLeft[i].Y = (left[i].Y - 1) / 2 + 1;
            }

            mb.Begin();
            //front
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), false, localFront[0], localFront[1], localFront[2], localFront[3]);
            //left
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, localLeft[0], localLeft[1], localLeft[2], localLeft[3]);
            //back
            mb.AddQuad(new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), false, localFront[1], localFront[0], localFront[3], localFront[2]);
            //right
            mb.AddQuad(new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), false, localLeft[1], localLeft[0], localLeft[3], localLeft[2]);
            //top
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), false, top[0], top[1], top[2], top[3]);
            //bottom
            mb.AddQuad(new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, bottom[0], bottom[1], bottom[2], bottom[3]);
            mb.OffsetAllVerts(new Vector3(0, -0.25f, 0)); //Offset the verts, because the above code centers the tile over the wrong position

            Mesh m = mb.End();
            m.Texture = c.Load<Texture2D>("Textures/BlockTextures/Block2");
            m.NormalMap = c.Load<Texture2D>("Textures/BlockTextures/Block1N");

            return m;
        }
Ejemplo n.º 14
0
        private static Mesh BuildQuarterBoxMesh(MeshBuilder mb, ContentManager c)
        {
            float width = 1f;
            float height = 0.5f;
            float depth = 0.5f;

            mb.Begin();
            //front
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), false, front[0] + new Vector2(0, .25f), front[1] + new Vector2(0, .25f), front[2], front[3]);
            //left
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, left[0] + new Vector2(0, .25f), left[1] + new Vector2(0, .25f), left[2], left[3]);
            //back
            mb.AddQuad(new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), false, front[1] + new Vector2(0, .25f), front[0] + new Vector2(0, .25f), front[3], front[2]);
            //right
            mb.AddQuad(new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), false, left[1] + new Vector2(0, .25f), left[0] + new Vector2(0, .25f), left[3], left[2]);
            //top
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), false, top[0], top[1], top[2] - new Vector2(0, .25f), top[3] - new Vector2(0, .25f));
            //bottom
            mb.AddQuad(new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, bottom[0] + new Vector2(0, .25f), bottom[1] + new Vector2(0, .25f), bottom[2], bottom[3]);
            mb.OffsetAllVerts(new Vector3(0, -0.25f, -0.25f)); //Offset the verts, because the above code centers the tile over the wrong position
            Mesh m = mb.End();
            m.Texture = c.Load<Texture2D>("Textures/BlockTextures/Block2");
            m.NormalMap = c.Load<Texture2D>("Textures/BlockTextures/Block1N");

            return m;
        }
Ejemplo n.º 15
0
        private static Mesh BuildSlope2Ramp(MeshBuilder mb, ContentManager c)
        {
            float width = 1f;
            float height = 1f;
            float depth = 1f;

            float widthHalf = width / 2;
            float heightHalf = height / 2;
            float depthHalf = depth / 2;

            mb.Begin();
            //front
            mb.AddTriangle(new Vector3(-widthHalf, (heightHalf), (depthHalf)), new Vector3((0), -(heightHalf), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), (depthHalf)), front[0], front[2] - new Vector2(.25f, 0), front[3], false);
            //left
            mb.AddQuad(new Vector3(-widthHalf, (heightHalf), -(depthHalf)), new Vector3(-widthHalf, (heightHalf), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), false, left[0], left[1], left[2], left[3]);
            //back
            mb.AddTriangle(new Vector3(-widthHalf, (heightHalf), -(depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), new Vector3((0), -(heightHalf), -(depthHalf)), front[0], front[3], front[2] - new Vector2(.25f, 0), false);
            //right
            mb.AddQuad(new Vector3(-widthHalf, heightHalf, (depthHalf)), new Vector3(-widthHalf, heightHalf, -(depthHalf)), new Vector3((0), -(heightHalf), -(depthHalf)), new Vector3((0), -(heightHalf), (depthHalf)), false, top[0], top[1], top[2], top[3]);
            //bottom
            mb.AddQuad(new Vector3(-widthHalf, -(heightHalf), (depthHalf)), new Vector3(0, -(heightHalf), (depthHalf)), new Vector3((0), -(heightHalf), -(depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), false, bottom[0], bottom[1] - new Vector2(.25f, 0), bottom[2] - new Vector2(.25f, 0), bottom[3]);

            Mesh m = mb.End();
            m.Texture = c.Load<Texture2D>("Textures/BlockTextures/Block7");
            m.NormalMap = c.Load<Texture2D>("Textures/BlockTextures/Block7N");

            return m;
        }
Ejemplo n.º 16
0
        private static Mesh BuildSlopeHalfRamp(MeshBuilder mb, ContentManager c)
        {
            float width = 1f;
            float height = 1f;
            float depth = 1f;

            float widthHalf = width / 2;
            float heightHalf = height / 2;
            float depthHalf = depth / 2;

            mb.Begin();
            //front
            mb.AddTriangle(new Vector3(-widthHalf, (0), (depthHalf)), new Vector3((widthHalf), -(heightHalf), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), (depthHalf)), false);
            //left
            mb.AddQuad(new Vector3(-widthHalf, (0), -(depthHalf)), new Vector3(-widthHalf, (0), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), (depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), false);
            //back
            mb.AddTriangle(new Vector3(-widthHalf, (0), -(depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), new Vector3((widthHalf), -(heightHalf), -(depthHalf)), false);
            //right
            mb.AddQuad(new Vector3(-widthHalf, 0, (depthHalf)), new Vector3(-widthHalf, 0, -(depthHalf)), new Vector3((widthHalf), -(heightHalf), -(depthHalf)), new Vector3((widthHalf), -(heightHalf), (depthHalf)), false);
            //bottom
            mb.AddQuad(new Vector3(-widthHalf, -(heightHalf), (depthHalf)), new Vector3(widthHalf, -(heightHalf), (depthHalf)), new Vector3((widthHalf), -(heightHalf), -(depthHalf)), new Vector3(-(widthHalf), -(heightHalf), -(depthHalf)), false);
            return mb.End();
        }
Ejemplo n.º 17
0
        /*The following methods (BuildBoxMesh(), BuildHalfBoxMesh(), BuildSlopeHalfBase(), etc.)
         * each use MeshBuilder to build a mesh of the appropriate block type*/
        private static Mesh BuildBoxMesh(MeshBuilder mb, ContentManager c)
        {
            float width = 1f;
            float height = 1f;
            float depth = 1f;

            mb.Begin();
            //front
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), false, front[0], front[1], front[2], front[3]);
            //left
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, left[0], left[1], left[2], left[3]);
            //back
            mb.AddQuad(new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), false, front[1], front[0], front[3], front[2]);
            //right
            mb.AddQuad(new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), false, left[1], left[0], left[3], left[2]);
            //top
            mb.AddQuad(new Vector3(-(width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), -(depth / 2)), new Vector3((width / 2), (height / 2), (depth / 2)), new Vector3(-(width / 2), (height / 2), (depth / 2)), false, top[0], top[1], top[2], top[3]);
            //bottom
            mb.AddQuad(new Vector3(-(width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), (depth / 2)), new Vector3((width / 2), -(height / 2), -(depth / 2)), new Vector3(-(width / 2), -(height / 2), -(depth / 2)), false, bottom[0], bottom[1], bottom[2], bottom[3]);

            Mesh m = mb.End();
            m.Texture = c.Load<Texture2D>("Textures/BlockTextures/Block1");
            m.NormalMap = c.Load<Texture2D>("Textures/BlockTextures/Block1N");
            return m;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Uses MeshBuilder to create a mesh for each block type, storing them into an array
        /// </summary>
        /// <param name="g"></param>
        /// <param name="content"></param>
        public static void Initialize(GraphicsDevice g, ContentManager content)
        {
            front[0] = new Vector2(.5f, .5f);
            front[1] = new Vector2(1, .5f);
            front[2] = new Vector2(1, 1);
            front[3] = new Vector2(.5f, 1);

            left[0] = new Vector2(0, .5f);
            left[1] = new Vector2(.5f, .5f);
            left[2] = new Vector2(.5f, 1);
            left[3] = new Vector2(0, 1);

            top[0] = new Vector2(.5f, 0);
            top[1] = new Vector2(1, 0);
            top[2] = new Vector2(1, .5f);
            top[3] = new Vector2(.5f, .5f);

            bottom[0] = new Vector2(0, 0);
            bottom[1] = new Vector2(.5f, 0);
            bottom[2] = new Vector2(.5f, .5f);
            bottom[3] = new Vector2(0, .5f);

            MeshBuilder mb = new MeshBuilder(g);

            blockMeshes = new Mesh[20];
            blockMeshes[1] = BuildBoxMesh(mb, content);
            blockMeshes[2] = BuildHalfBoxMesh(mb, content);
            blockMeshes[3] = BuildQuarterBoxMesh(mb, content);
            blockMeshes[4] = BuildEighthBoxMesh(mb, content);
            blockMeshes[5] = BuildConvexRamp(mb, content);
            blockMeshes[6] = BuildSlope1Ramp(mb, content);
            blockMeshes[7] = BuildSlope2Ramp(mb, content);
            blockMeshes[8] = BuildSlopeHalfRamp(mb, content);
            blockMeshes[9] = BuildConcaveRamp(mb, content);
            blockMeshes[10] = BuildSlope2Base(mb, content);
            blockMeshes[11] = BuildSlopeHalfBase(mb, content);

            BuildRotations();
            AssembleBlockBodies();
        }