コード例 #1
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;
        }
コード例 #2
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();
        }
コード例 #3
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;
        }