Ejemplo n.º 1
0
        public static MeshVertex[] CreatePyramid(Vector4 center, float width, float height, float depth,
            out ushort[] indices)
        {
            float halfWidth = width/2;
            float halfHeight = height/2;
            float halfDepth = depth/2;

            Vector4 v0 = new Vector4(0, halfHeight, 0, 0);
            Vector4 v1 = new Vector4(halfWidth, -halfHeight, halfDepth,0);
            Vector4 v2 = new Vector4(-halfWidth, -halfHeight, halfDepth,0);
            Vector4 v3 = new Vector4(halfWidth, -halfHeight, -halfDepth,0);
            Vector4 v4 = new Vector4(-halfWidth, -halfHeight, -halfDepth,0);
            Vector3 n0 = Normal(v0, v4, v2);
            Vector3 n1 = Normal(v0, v3, v4);
            Vector3 n2 = Normal(v0, v1, v3);
            Vector3 n3 = Normal(v0, v1, v2);
            Vector3 n4 = -Vector3.UnitY;

            Vector2 tV = new Vector2(0.5f, 0f); // Top Vertex
            Vector2 tF0 = new Vector2(0f, 1f); // Face Bottom Left
            Vector2 tF1 = new Vector2(1f, 1f); // Face Bottom Right
            Vector2 tB0 = new Vector2(0f,0f); // Base top left
            Vector2 tB1 = new Vector2(1f, 0f); // Base top Right

               MeshVertex[] vertices = new MeshVertex[]
            {
                // Left face
                new MeshVertex(center + v2, n0, tF0),
                new MeshVertex(center + v0, n0, tV),
                new MeshVertex(center + v4, n0, tF1),

                // Front face
                new MeshVertex(center + v4, n1, tF0),
                new MeshVertex(center + v0, n1, tV),
                new MeshVertex(center + v3, n1, tF1),

                // Right Face
                new MeshVertex(center + v3, n2, tF0),
                new MeshVertex(center + v0, n2, tV),
                new MeshVertex(center + v1, n2, tF1),

                // Back Face
                new MeshVertex(center + v1, n3, tF0),
                new MeshVertex(center + v0, n3, tV),
                new MeshVertex(center + v2, n3, tF1),

                // Bottom Face
                new MeshVertex(center + v1, n4, tF0),
                new MeshVertex(center + v3, n4, tB0),
                new MeshVertex(center + v4, n4, tB1),
                new MeshVertex(center + v2, n4, tF1),
            };

            indices = new ushort[] {
                2, 1, 0,
                5, 4, 3,
                8, 7, 6,
                11, 10, 9,
                12, 13, 14,
                14, 15, 12
                };

            return vertices;
        }
Ejemplo n.º 2
0
        public static MeshVertex[] CreateBox(Vector4 center, float width, float height, float depth,
            out ushort[] indices)
        {
            Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f);

            Vector2 textureTopLeft = new Vector2(0.0f, 0.0f);
            Vector2 textureTopRight = new Vector2(1.0f, 0.0f);
            Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f);
            Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);

            Vector4 v0 = new Vector4(-width/2, -height/2, depth/2, 0);
            Vector4 v1 = new Vector4(-width/2, height/2, depth/2, 0);
            Vector4 v2 = new Vector4(width/2, -height/2, depth/2, 0);
            Vector4 v3 = new Vector4(width/2, height/2, depth/2, 0);
            Vector4 v4 = new Vector4(width/2, -height/2, -depth/2, 0);
            Vector4 v5 = new Vector4(width/2, height/2, -depth/2, 0);
            Vector4 v6 = new Vector4(-width/2, -height/2, -depth/2, 0);
            Vector4 v7 = new Vector4(-width/2, height/2, -depth/2, 0);

            MeshVertex[] vertices = new MeshVertex[]
            {
                // Front Surface
                new MeshVertex(center + v0, frontNormal, textureBottomLeft),
                new MeshVertex(center + v1,frontNormal,textureTopLeft),
                new MeshVertex(center + v2,frontNormal,textureBottomRight),
                new MeshVertex(center + v3,frontNormal,textureTopRight),

                // Back Surface
                new MeshVertex(center + v4,backNormal, textureBottomLeft),
                new MeshVertex(center +v5,backNormal, textureTopLeft),
                new MeshVertex(center +v6,backNormal, textureBottomRight),
                new MeshVertex(center +v7, backNormal, textureTopRight),

                // Left Surface
                new MeshVertex(center + v6, leftNormal, textureBottomLeft),
                new MeshVertex(center + v7,leftNormal, textureTopLeft),
                new MeshVertex(center + v0,leftNormal, textureBottomRight),
                new MeshVertex(center + v1,leftNormal, textureTopRight),

                // Right Surface
                new MeshVertex(center + v2,rightNormal, textureBottomLeft),
                new MeshVertex(center + v3,rightNormal, textureTopLeft),
                new MeshVertex(center + v4,rightNormal, textureBottomRight),
                new MeshVertex(center + v5,rightNormal, textureTopRight),

                // Top Surface
                new MeshVertex(center + v1,topNormal,textureBottomLeft),
                new MeshVertex(center + v7,topNormal,textureTopLeft),
                new MeshVertex(center + v3,topNormal,textureBottomRight),
                new MeshVertex(center + v5,topNormal,textureTopRight),

                // Bottom Surface
                new MeshVertex(center + v6, bottomNormal,textureBottomLeft),
                new MeshVertex(center + v0,bottomNormal,textureTopLeft),
                new MeshVertex(center + v4,bottomNormal,textureBottomRight),
                new MeshVertex(center + v2,bottomNormal,textureTopRight),
            };

            indices = new ushort[] {
                    0, 1, 2, 2, 1, 3,
                    4, 5, 6, 6, 5, 7,
                    8, 9, 10, 10, 9, 11,
                    12, 13, 14, 14, 13, 15,
                    16, 17, 18, 18, 17, 19,
                    20, 21, 22, 22, 21, 23
                };

            return vertices;
        }
Ejemplo n.º 3
0
 public bool Equals(MeshVertex other)
 {
     return other.Position.Equals(Position) && other.Normal.Equals(Normal) && other.TextureUV.Equals(TextureUV);
 }