Example #1
0
        /// <summary>
        /// This method updates the connection data of skeleton points and is called when any frame is updated.
        /// </summary>
        /// <param name="handSkeletons">Bone point data of hand.</param>
        /// <param name="handSkeletonConnection">Data of connection between bone points of hand.</param>
        private void UpdateHandSkeletonLinesData(float[] handSkeletons, int[] handSkeletonConnection)
        {
            ShaderUtil.CheckGlError(TAG, "Update hand skeleton lines data start.");
            int pointsLineNum = 0;

            // Each point is a set of 3D coordinate. Each connection line consists of two points.
            float[] linePoint = new float[handSkeletonConnection.Length * 3 * 2];

            // The format of HandSkeletonConnection data is [p0,p1;p0,p3;p0,p5;p1,p2].
            // handSkeletonConnection saves the node indexes. Two indexes obtain a set
            // of connection point data. Therefore, j = j + 2. This loop obtains related
            // coordinates and saves them in linePoint.
            for (int j = 0; j < handSkeletonConnection.Length; j += 2)
            {
                linePoint[pointsLineNum * 3]     = handSkeletons[3 * handSkeletonConnection[j]];
                linePoint[pointsLineNum * 3 + 1] = handSkeletons[3 * handSkeletonConnection[j] + 1];
                linePoint[pointsLineNum * 3 + 2] = handSkeletons[3 * handSkeletonConnection[j] + 2];
                linePoint[pointsLineNum * 3 + 3] = handSkeletons[3 * handSkeletonConnection[j + 1]];
                linePoint[pointsLineNum * 3 + 4] = handSkeletons[3 * handSkeletonConnection[j + 1] + 1];
                linePoint[pointsLineNum * 3 + 5] = handSkeletons[3 * handSkeletonConnection[j + 1] + 2];
                pointsLineNum += 2;
            }
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);
            mPointsNum = pointsLineNum;

            // If the storage space is insufficient, apply for twice the memory each time.
            if (mVboSize < mPointsNum * BYTES_PER_POINT)
            {
                while (mVboSize < mPointsNum * BYTES_PER_POINT)
                {
                    mVboSize *= 2;
                }
                GLES20.GlBufferData(GLES20.GlArrayBuffer, mVboSize, null, GLES20.GlDynamicDraw);
            }
            FloatBuffer linePoints = FloatBuffer.Wrap(linePoint);

            Log.Debug(TAG, "Skeleton skeleton line points num: " + mPointsNum);
            Log.Debug(TAG, "Skeleton line points: " + linePoints.ToString());
            GLES20.GlBufferSubData(GLES20.GlArrayBuffer, 0, mPointsNum * BYTES_PER_POINT,
                                   linePoints);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);
            ShaderUtil.CheckGlError(TAG, "Update hand skeleton lines data end.");
        }