示例#1
0
        /// <summary>
        /// Creates the VBO and IBO for a cube.
        /// </summary>
        /// <returns>Returns the length of the IBO array.</returns>
        private int createCube()
        {
            //List of vertices for a cube.
            VertexN3fV3f[] VertexListCube = new VertexN3fV3f[]
            {
                //Bottom face vertices
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, -0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, -0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.5f, -0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.5f, -0.5f, 0.5f)),

                //Top face vertices
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(-0.5f, 0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(-0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, 0.5f, 0.5f)),

                //Left face vertices
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, -0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, -0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-0.5f, 0.5f, 0.5f)),

                //Right face vertices
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, -0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, -0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.5f, 0.5f, 0.5f)),

                //Front face vertices
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(-0.5f, -0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(-0.5f, 0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.5f, 0.5f, 0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.5f, -0.5f, 0.5f)),

                //Back face vertices
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, -1.0f), new Vector3(-0.5f, -0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, -1.0f), new Vector3(-0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, -1.0f), new Vector3(0.5f, 0.5f, -0.5f)),
                new VertexN3fV3f(new Vector3(0.0f, 0.0f, -1.0f), new Vector3(0.5f, -0.5f, -0.5f)),
            };

            //Element list for a cube using triangles and the VertexListCube.
            ushort[] ElementsListCube = new ushort[]
            {
                0, 1, 2, 2, 3, 0,         //bottom face
                4, 5, 6, 6, 7, 4,         //top face
                8, 9, 10, 10, 11, 8,      //left face
                12, 13, 14, 14, 15, 12,   //right face
                16, 17, 18, 18, 19, 16,   //front face
                20, 21, 22, 22, 23, 20    //back face
            };

            LoadIntoGraphicsMemory(VertexListCube, ElementsListCube);
            return(ElementsListCube.Length);
        }
示例#2
0
        private int createPyramid()
        {
            Vector3 bottomFront     = new Vector3(0.0f, (float)-Math.Sqrt(2) / 3 * SCALE, 1.0f * SCALE);
            Vector3 bottomLeftBack  = new Vector3((float)-Math.Cos(Math.PI / 6) * SCALE, (float)-Math.Sqrt(2) / 3 * SCALE, (float)-Math.Sin(Math.PI / 6) * SCALE);
            Vector3 bottomRightBack = new Vector3((float)Math.Cos(Math.PI / 6) * SCALE, (float)-Math.Sqrt(2) / 3 * SCALE, (float)-Math.Sin(Math.PI / 6) * SCALE);
            Vector3 top             = new Vector3(0.0f, (float)Math.Sqrt(2) * 2 / 3 * SCALE, 0.0f);

            Vector3 leftFaceNormal = Vector3.Cross(bottomLeftBack - top, bottomFront - top);

            leftFaceNormal.Normalize();

            Vector3 rightFaceNormal = Vector3.Cross(bottomFront - top, bottomRightBack - top);

            rightFaceNormal.Normalize();

            Vector3 backFaceNormal = Vector3.Cross(bottomRightBack - top, bottomLeftBack - top);

            backFaceNormal.Normalize();

            //List of vertices for a cube.
            VertexN3fV3f[] VertexListPyramid = new VertexN3fV3f[]
            {
                //Bottom face vertices
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), bottomFront),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), bottomLeftBack),
                new VertexN3fV3f(new Vector3(0.0f, -1.0f, 0.0f), bottomRightBack),

                //Left face vertices
                new VertexN3fV3f(leftFaceNormal, bottomFront),
                new VertexN3fV3f(leftFaceNormal, bottomLeftBack),
                new VertexN3fV3f(leftFaceNormal, top),

                //Right face vertices
                new VertexN3fV3f(rightFaceNormal, bottomFront),
                new VertexN3fV3f(rightFaceNormal, top),
                new VertexN3fV3f(rightFaceNormal, bottomRightBack),

                //Back face vertices
                new VertexN3fV3f(backFaceNormal, bottomLeftBack),
                new VertexN3fV3f(backFaceNormal, bottomRightBack),
                new VertexN3fV3f(backFaceNormal, top),
            };

            //Element list for a cube using triangles and the VertexListCube.
            ushort[] ElementsListPyramid = new ushort[]
            {
                0, 1, 2,         //bottom face
                3, 4, 5,         //left face
                6, 7, 8,         //right face
                9, 10, 11        //back face
            };

            LoadIntoGraphicsMemory(VertexListPyramid, ElementsListPyramid);
            return(ElementsListPyramid.Length);
        }