コード例 #1
0
ファイル: MapViewerPanel.cs プロジェクト: bschwind/Sky-Slider
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: BallDemo.cs プロジェクト: bschwind/Graphics-Demos
        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));
        }
コード例 #5
0
ファイル: MainGamePanel.cs プロジェクト: bschwind/Sky-Slider
 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");
 }
コード例 #6
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        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();
        }
コード例 #7
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        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;
        }
コード例 #8
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        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;
        }
コード例 #9
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        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;
        }
コード例 #10
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        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;
        }
コード例 #11
0
ファイル: BlockData.cs プロジェクト: bschwind/Sky-Slider
        /*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;
        }