CSharpGL.OneIndexRenderer.GetLastIndexId C# (CSharp) Method

GetLastIndexId() private method

在所有可能的图元(lastVertexId匹配)中, 逐个测试,找到最接近摄像机的那个图元, 返回此图元的最后一个索引在IndexBuffer中的索引(位置)。
private GetLastIndexId ( RenderEventArgs arg, List primitiveInfoList, int x, int y ) : RecognizedPrimitiveInfo
arg RenderEventArgs
primitiveInfoList List
x int mouse position(Left Down is (0, 0)).
y int mouse position(Left Down is (0, 0)).
return RecognizedPrimitiveInfo
        private RecognizedPrimitiveInfo GetLastIndexId(
            RenderEventArgs arg,
            List<RecognizedPrimitiveInfo> primitiveInfoList,
            int x, int y)
        {
            if (primitiveInfoList == null || primitiveInfoList.Count == 0) { return null; }
            #if DEBUG
            SameLengths(primitiveInfoList);
            #endif
            if (primitiveInfoList[0].VertexIds.Length == 1)// picking a point.
            {
                return primitiveInfoList[0];
            }

            int current = 0;
            #if DEBUG
            NoPrimitiveRestartIndex(primitiveInfoList);
            #endif
            for (int i = 1; i < primitiveInfoList.Count; i++)
            {
                OneIndexBuffer twoPrimitivesIndexBuffer;
                uint lastIndex0, lastIndex1;
                AssembleIndexBuffer(
                    primitiveInfoList[current], primitiveInfoList[i], this.indexBuffer.Mode,
                    out twoPrimitivesIndexBuffer, out lastIndex0, out lastIndex1);
                uint pickedIndex = Pick(arg, twoPrimitivesIndexBuffer,
                    x, y);
                if (pickedIndex == lastIndex1)
                { current = i; }
                else if (pickedIndex == lastIndex0)
                { /* nothing to do */}
                else if (pickedIndex == uint.MaxValue)// 两个候选图元都没有被拾取到
                { /* nothing to do */}
                else
                { throw new Exception("This should not happen!"); }
            }

            return primitiveInfoList[current];
        }