/// <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"/> is not in the range of this <paramref name="element"/>.</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> /// <para>Note: The result's positions property is not set up as there will be different kinds of storage mode for positions(float[], IntPtr, etc). You have to initialize the positions property and fill correct position information afterwards.</para> /// </summary> /// <typeparam name="T">Sub type 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> /// <returns></returns> public static T TryPick <T>( this IColorCodedPicking element, Enumerations.BeginMode mode, uint stageVertexID) where T : IPickedGeometry, new() { T pickedGeometry = default(T); if (element != null) { uint lastVertexID; if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID)) { pickedGeometry = new T(); pickedGeometry.GeometryType = mode.ToGeometryType(); pickedGeometry.StageVertexID = stageVertexID; pickedGeometry.From = element; } } return(pickedGeometry); }
/// <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, Enumerations.BeginMode 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]; } pickedGeometry.positions = geometryPositions; } } return(pickedGeometry); }