IPickedGeometry IColorCodedPicking.Pick(uint stageVertexID)
        {
            IColorCodedPicking    element        = this as IColorCodedPicking;
            PickedGeometryIndexed pickedGeometry = element.TryPick <PickedGeometryIndexed>(
                PrimitiveModes.TriangleStrip, stageVertexID);

            if (pickedGeometry == null)
            {
                return(null);
            }

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            uint lastVertexID;

            if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
            {
                pickedGeometry.CubeIndex = lastVertexID / 8;
                var vertexIndex = lastVertexID % 8;
                pickedGeometry.positions = new vec3[1] {
                    unitCubePos[vertexIndex]
                };
            }

            return(pickedGeometry);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the primitive of <paramref name="element"/> according to vertex's id.
        /// <para>Returns <code>null</code> if <paramref name="element"/> is null or <paramref name="stageVertexID"/> does not belong to any of this <paramref name="element"/>'s vertices.</para>
        /// <para>Note: the <paramref name="stageVertexID"/> refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</para>
        /// </summary>
        /// <typeparam name="T">Subclass of <see cref="IPickedGeometry"/></typeparam>
        /// <param name="element">the scene's element that contains the primitive.</param>
        /// <param name="mode">specifies what type of primitive it is.</param>
        /// <param name="stageVertexID">Refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</param>
        /// <param name="positions">element's vertices' position array.</param>
        /// <returns></returns>
        public static T TryPick <T>(
            this IColorCodedPicking element, PrimitiveModes mode, uint stageVertexID, float[] positions)
            where T : IPickedGeometry, new()
        {
            if (positions == null)
            {
                throw new ArgumentNullException("positions");
            }

            T pickedGeometry = element.TryPick <T>(mode, stageVertexID);

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            if (pickedGeometry != null)
            {
                uint lastVertexID;
                if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
                {
                    int vertexCount = pickedGeometry.GeometryType.GetVertexCount();
                    if (vertexCount == -1)
                    {
                        vertexCount = positions.Length / 3;
                    }
                    float[] geometryPositions = new float[vertexCount * 3];
                    uint    i = lastVertexID * 3 + 2;
                    for (int j = (geometryPositions.Length - 1); j >= 0; i--, j--)
                    {
                        if (i == uint.MaxValue)// This is when mode is GL_LINE_LOOP.
                        {
                            i = (uint)positions.Length - 1;
                        }
                        geometryPositions[j] = positions[i];
                    }

                    var poss = new vec3[vertexCount];
                    for (int t = 0; t < vertexCount; t++)
                    {
                        poss[t] = new vec3(geometryPositions[t * 3 + 0], geometryPositions[t * 3 + 1], geometryPositions[t * 3 + 2]);
                    }
                    pickedGeometry.positions = poss;
                }
            }

            return(pickedGeometry);
        }
        IPickedGeometry IColorCodedPicking.Pick(uint stageVertexID)
        {
            IColorCodedPicking    element        = this as IColorCodedPicking;
            PickedGeometryColored pickedGeometry = element.TryPick <PickedGeometryColored>(
                this.Model.Mode, stageVertexID, this.Model.Positions);

            if (pickedGeometry == null)
            {
                return(null);
            }

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            uint lastVertexID;

            if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
            {
                ScientificModel model = this.Model;

                int vertexCount = pickedGeometry.GeometryType.GetVertexCount();
                if (vertexCount == -1)
                {
                    vertexCount = model.VertexCount;
                }

                float[] geometryColors = new float[vertexCount * 3];

                float[] modelColors = model.Colors;

                uint i = lastVertexID * 3 + 2;
                for (int j = (geometryColors.Length - 1); j >= 0; i--, j--)
                {
                    if (i == uint.MaxValue)// This is when mode is GL_LINE_LOOP.
                    {
                        i = (uint)modelColors.Length - 1;
                    }
                    geometryColors[j] = modelColors[i];
                }

                pickedGeometry.colors = geometryColors;
            }

            return(pickedGeometry);
        }