示例#1
0
文件: Chunk.cs 项目: mrbaggins/Box
        private int AddVertexToMesh(Vector3 point, Color color, Vector3 normal)
        {
            //Make it into a vertex
            VertexPositionColorNormal v = new VertexPositionColorNormal(point, color, normal);

            //Check if vertex already exists
            //if (VertexList.Contains(v))
            //return VertexList.IndexOf(v);
            //else
            {
                VertexList.Add(v);
                return(VertexList.Count - 1);
            }
        }
示例#2
0
        private void ConstructCube()
        {
            vertices = new VertexPositionColorNormal[NUM_VERTICES];

            //Values are set from the bottomleftfront corner of a box.

            // Calculate the position of the vertices on the top face.
            Vector3 topLeftFront  = position + new Vector3(0.0f, 1.0f, 0.0f) * Size;
            Vector3 topLeftBack   = position + new Vector3(0.0f, 1.0f, 1.0f) * Size;
            Vector3 topRightFront = position + new Vector3(1.0f, 1.0f, 0.0f) * Size;
            Vector3 topRightBack  = position + new Vector3(1.0f, 1.0f, 1.0f) * Size;

            // Calculate the position of the vertices on the bottom face.
            Vector3 btmLeftFront  = position + new Vector3(0.0f, 0.0f, 0.0f) * Size;
            Vector3 btmLeftBack   = position + new Vector3(0.0f, 0.0f, 1.0f) * Size;
            Vector3 btmRightFront = position + new Vector3(1.0f, 0.0f, 0.0f) * Size;
            Vector3 btmRightBack  = position + new Vector3(1.0f, 0.0f, 1.0f) * Size;

            // Normal vectors for each face (needed for lighting / display)
            Vector3 normalFront  = new Vector3(0.0f, 0.0f, 1.0f) * Size;
            Vector3 normalBack   = new Vector3(0.0f, 0.0f, -1.0f) * Size;
            Vector3 normalTop    = new Vector3(0.0f, 1.0f, 0.0f) * Size;
            Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f) * Size;
            Vector3 normalLeft   = new Vector3(-1.0f, 0.0f, 0.0f) * Size;
            Vector3 normalRight  = new Vector3(1.0f, 0.0f, 0.0f) * Size;

            // UV texture coordinates
            Vector2 textureTopLeft     = new Vector2(1.0f * Size.X, 0.0f * Size.Y);
            Vector2 textureTopRight    = new Vector2(0.0f * Size.X, 0.0f * Size.Y);
            Vector2 textureBottomLeft  = new Vector2(1.0f * Size.X, 1.0f * Size.Y);
            Vector2 textureBottomRight = new Vector2(0.0f * Size.X, 1.0f * Size.Y);


            // Add the vertices for the FRONT face.
            vertices[0] = new VertexPositionColorNormal(topLeftFront, Color, normalFront);
            vertices[1] = new VertexPositionColorNormal(btmLeftFront, Color, normalFront);
            vertices[2] = new VertexPositionColorNormal(topRightFront, Color, normalFront);
            vertices[3] = new VertexPositionColorNormal(btmLeftFront, Color, normalFront);
            vertices[4] = new VertexPositionColorNormal(btmRightFront, Color, normalFront);
            vertices[5] = new VertexPositionColorNormal(topRightFront, Color, normalFront);

            // Add the vertices for the BACK face.
            vertices[6]  = new VertexPositionColorNormal(topLeftBack, Color, normalBack);
            vertices[7]  = new VertexPositionColorNormal(topRightBack, Color, normalBack);
            vertices[8]  = new VertexPositionColorNormal(btmLeftBack, Color, normalBack);
            vertices[9]  = new VertexPositionColorNormal(btmLeftBack, Color, normalBack);
            vertices[10] = new VertexPositionColorNormal(topRightBack, Color, normalBack);
            vertices[11] = new VertexPositionColorNormal(btmRightBack, Color, normalBack);

            // Add the vertices for the TOP face.
            vertices[12] = new VertexPositionColorNormal(topLeftFront, Color, normalTop);
            vertices[13] = new VertexPositionColorNormal(topRightBack, Color, normalTop);
            vertices[14] = new VertexPositionColorNormal(topLeftBack, Color, normalTop);
            vertices[15] = new VertexPositionColorNormal(topLeftFront, Color, normalTop);
            vertices[16] = new VertexPositionColorNormal(topRightFront, Color, normalTop);
            vertices[17] = new VertexPositionColorNormal(topRightBack, Color, normalTop);

            // Add the vertices for the BOTTOM face.
            vertices[18] = new VertexPositionColorNormal(btmLeftFront, Color, normalBottom);
            vertices[19] = new VertexPositionColorNormal(btmLeftBack, Color, normalBottom);
            vertices[20] = new VertexPositionColorNormal(btmRightBack, Color, normalBottom);
            vertices[21] = new VertexPositionColorNormal(btmLeftFront, Color, normalBottom);
            vertices[22] = new VertexPositionColorNormal(btmRightBack, Color, normalBottom);
            vertices[23] = new VertexPositionColorNormal(btmRightFront, Color, normalBottom);

            // Add the vertices for the LEFT face.
            vertices[24] = new VertexPositionColorNormal(topLeftFront, Color, normalLeft);
            vertices[25] = new VertexPositionColorNormal(btmLeftBack, Color, normalLeft);
            vertices[26] = new VertexPositionColorNormal(btmLeftFront, Color, normalLeft);
            vertices[27] = new VertexPositionColorNormal(topLeftBack, Color, normalLeft);
            vertices[28] = new VertexPositionColorNormal(btmLeftBack, Color, normalLeft);
            vertices[29] = new VertexPositionColorNormal(topLeftFront, Color, normalLeft);

            // Add the vertices for the RIGHT face.
            vertices[30] = new VertexPositionColorNormal(topRightFront, Color, normalRight);
            vertices[31] = new VertexPositionColorNormal(btmRightFront, Color, normalRight);
            vertices[32] = new VertexPositionColorNormal(btmRightBack, Color, normalRight);
            vertices[33] = new VertexPositionColorNormal(topRightBack, Color, normalRight);
            vertices[34] = new VertexPositionColorNormal(topRightFront, Color, normalRight);
            vertices[35] = new VertexPositionColorNormal(btmRightBack, Color, normalRight);

            _isConstructed = true;
        }