private PickedGeometry PickWhateverItIs(RenderEventArgs arg, uint stageVertexId, uint lastVertexId, DrawMode mode, PickingGeometryType typeOfMode)
{
//PickedGeometry pickedGeometry = new PickedGeometry();
//pickedGeometry.GeometryType = typeOfMode;
//pickedGeometry.StageVertexId = stageVertexId;
//pickedGeometry.FromRenderer = this;
// Fill primitive's position information.
int vertexCount = typeOfMode.GetVertexCount();
if (vertexCount == -1) { vertexCount = this.PositionBuffer.Length; }
uint[] vertexIds; vec3[] positions;
if (lastVertexId == 0 && vertexCount == 2)
{
// This is when mode is GL_LINE_LOOP and picked last line(the loop back one)
PickingLastLineInLineLoop(out vertexIds, out positions);
}
else
{
// Other conditions
switch (typeOfMode)
{
case PickingGeometryType.Point:
vertexIds = new uint[] { lastVertexId, };
positions = FillPickedGeometrysPosition(lastVertexId, 1);
break;
case PickingGeometryType.Line:
vertexIds = new uint[] { lastVertexId - 1, lastVertexId, };
positions = FillPickedGeometrysPosition(lastVertexId - 1, 2);
break;
case PickingGeometryType.Triangle:
if (mode == DrawMode.TriangleFan)
{
vertexIds = new uint[] { 0, lastVertexId - 1, lastVertexId, };
positions = FillPickedGeometrysPosition(vertexIds);
}
else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
{
vertexIds = new uint[] { lastVertexId - 4, lastVertexId - 2, lastVertexId, };
positions = FillPickedGeometrysPosition(vertexIds);
}
else
{
vertexIds = new uint[] { lastVertexId - 2, lastVertexId - 1, lastVertexId, };
positions = FillPickedGeometrysPosition(lastVertexId - 2, 3);
}
break;
case PickingGeometryType.Quad:
vertexIds = new uint[] { lastVertexId - 3, lastVertexId - 2, lastVertexId - 1, lastVertexId, };
positions = FillPickedGeometrysPosition(lastVertexId - 3, 4);
break;
case PickingGeometryType.Polygon:
vertexIds = new uint[vertexCount];
for (uint i = 0; i < vertexCount; i++)
{ vertexIds[i] = lastVertexId + i; }
positions = FillPickedGeometrysPosition(0, vertexCount);
break;
default:
throw new NotImplementedException();
}
}
PickedGeometry pickedGeometry = new PickedGeometry(arg.UsingViewPort, typeOfMode, positions, vertexIds, stageVertexId, this);
return pickedGeometry;
}