public override List <Vertex> GenerateVertexList(int resolutionU, int resolutionV)
        {
            List <Vertex> startCapList = startCap.GenerateVertexList(resolutionU, resolutionU / 4);
            List <Vertex> shaftList    = shaft.GenerateVertexList(resolutionU, resolutionV);
            List <Vertex> endCapList   = endCap.GenerateVertexList(resolutionU, resolutionU / 4);

            return(startCapList.Concat(shaftList).Concat(endCapList).ToList());
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override List <Vertex> GenerateVertexList(int resolutionU, int resolutionV)
        {
            // Generate the vertices of two end caps, and a shaft in between:
            List <Vertex> startCapList = startCap.GenerateVertexList(resolutionU, resolutionU / 4);
            List <Vertex> endCapList   = endCap.GenerateVertexList(resolutionU, resolutionU / 4);

            // Using a slice, remove the first and last ring of vertices of the shaft, which overlap with the last
            // rings of the startCap and endCap respectively. Later we will stitch the shaft and end caps together with
            // triangles between them, during the GenerateIndexList() step.
            Slice <Vertex> shaftSlice = new Slice <Vertex>(
                shaft.GenerateVertexList(resolutionU, resolutionV),
                resolutionU,
                Cylinder.CalculateVertexCount(resolutionU, resolutionV) - 2 * resolutionU);

            // Recalculate the surface normal between the cylinder and the start cap:
            for (int i = 0; i < (resolutionU - 1); i++)
            {
                dvec3 surfacePosition = startCapList[(resolutionU / 4 - 1) * resolutionU + i + 1].Position;
                dvec3 du = surfacePosition - startCapList[(resolutionU / 4 - 1) * resolutionU + i + 1 + 1].Position;
                dvec3 dv = surfacePosition - shaftSlice[i].Position;

                // Calculate the position of the rings of vertices:
                dvec3 surfaceNormal = dvec3.Cross(du.Normalized, dv.Normalized);

                startCapList[(resolutionU / 4 - 1) * resolutionU + i + 1] = new Vertex((vec3)surfacePosition, (vec3)surfaceNormal);
            }

            // Stitch the end of the triangles:
            dvec3 surfacePosition2 = startCapList[(resolutionU / 4 - 1) * resolutionU + resolutionU].Position;
            dvec3 du2 = surfacePosition2 - startCapList[(resolutionU / 4 - 1) * resolutionU + 1].Position;
            dvec3 dv2 = surfacePosition2 - shaftSlice[resolutionU].Position;

            // Calculate the position of the rings of vertices:
            dvec3 surfaceNormal2 = dvec3.Cross(du2.Normalized, dv2.Normalized);

            startCapList[(resolutionU / 4 - 1) * resolutionU + resolutionU] = new Vertex((vec3)surfacePosition2, (vec3)surfaceNormal2);

            return(startCapList.Concat(shaftSlice).Concat(endCapList).ToList());
        }