示例#1
0
        private PickedGeometry PickWhateverItIs(uint stageVertexId, uint lastVertexId, DrawMode mode, GeometryType typeOfMode)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.GeometryType  = typeOfMode;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From          = this;

            // Fill primitive's position information.
            int vertexCount = typeOfMode.GetVertexCount();

            if (vertexCount == -1)
            {
                vertexCount = this.PositionBufferPtr.Length;
            }
            if (lastVertexId == 0 && vertexCount == 2)
            {
                // This is when mode is GL_LINE_LOOP and picked last line(the loop back one)
                PickingLastLineInLineLoop(pickedGeometry);
                return(pickedGeometry);
            }

            // Other conditions
            switch (typeOfMode)
            {
            case GeometryType.Point:
                pickedGeometry.VertexIds = new uint[] { lastVertexId, };
                pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId, 1);
                break;

            case GeometryType.Line:
                pickedGeometry.VertexIds = new uint[] { lastVertexId - 1, lastVertexId, };
                pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 1, 2);
                break;

            case GeometryType.Triangle:
                if (mode == DrawMode.TriangleFan)
                {
                    pickedGeometry.VertexIds = new uint[] { 0, lastVertexId - 1, lastVertexId, };
                    pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.VertexIds);
                }
                else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
                {
                    pickedGeometry.VertexIds = new uint[] { lastVertexId - 4, lastVertexId - 2, lastVertexId, };
                    pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.VertexIds);
                }
                else
                {
                    pickedGeometry.VertexIds = new uint[] { lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                    pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 2, 3);
                }
                break;

            case GeometryType.Quad:
                pickedGeometry.VertexIds = new uint[] { lastVertexId - 3, lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 3, 4);
                break;

            case GeometryType.Polygon:
                pickedGeometry.VertexIds = new uint[vertexCount];
                for (uint i = 0; i < vertexCount; i++)
                {
                    pickedGeometry.VertexIds[i] = lastVertexId + i;
                }
                pickedGeometry.Positions = FillPickedGeometrysPosition(0, vertexCount);
                break;

            default:
                throw new NotImplementedException();
            }

            return(pickedGeometry);
        }
示例#2
0
        private PickedGeometry PickWhateverItIs(PickingEventArgs arg, uint stageVertexId, uint singleNodeVertexId, DrawMode mode, GeometryType 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 = (from item in this.Node.PickingRenderMethod.PositionBuffers select item.Length).Sum();
            }

            uint[] vertexIds; vec3[] positions;

            if (singleNodeVertexId == 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 GeometryType.Point:
                    vertexIds = new uint[] { singleNodeVertexId, };
                    positions = FillPickedGeometrysPosition(singleNodeVertexId, 1);
                    break;

                case GeometryType.Line:
                    vertexIds = new uint[] { singleNodeVertexId - 1, singleNodeVertexId, };
                    positions = FillPickedGeometrysPosition(singleNodeVertexId - 1, 2);
                    break;

                case GeometryType.Triangle:
                    if (mode == DrawMode.TriangleFan)
                    {
                        vertexIds = new uint[] { 0, singleNodeVertexId - 1, singleNodeVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
                    {
                        vertexIds = new uint[] { singleNodeVertexId - 4, singleNodeVertexId - 2, singleNodeVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else
                    {
                        vertexIds = new uint[] { singleNodeVertexId - 2, singleNodeVertexId - 1, singleNodeVertexId, };
                        positions = FillPickedGeometrysPosition(singleNodeVertexId - 2, 3);
                    }
                    break;

                case GeometryType.Quad:
                    vertexIds = new uint[] { singleNodeVertexId - 3, singleNodeVertexId - 2, singleNodeVertexId - 1, singleNodeVertexId, };
                    positions = FillPickedGeometrysPosition(singleNodeVertexId - 3, 4);
                    break;

                case GeometryType.Polygon:
                    vertexIds = new uint[vertexCount];
                    for (uint i = 0; i < vertexCount; i++)
                    {
                        vertexIds[i] = singleNodeVertexId + i;
                    }
                    positions = FillPickedGeometrysPosition(0, vertexCount);
                    break;

                default:
                    throw new NotDealWithNewEnumItemException(typeof(GeometryType));
                }
            }

            PickedGeometry pickedGeometry = new PickedGeometry(typeOfMode, positions, vertexIds, stageVertexId, this.Node);

            return(pickedGeometry);
        }
        private PickedGeometry PickWhateverItIs(uint stageVertexId, uint lastVertexId, DrawMode mode, GeometryType typeOfMode)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();
            pickedGeometry.GeometryType = typeOfMode;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From = this;

            // Fill primitive's position information.
            int vertexCount = typeOfMode.GetVertexCount();
            if (vertexCount == -1) { vertexCount = this.positionBufferPtr.Length; }
            if (lastVertexId == 0 && vertexCount == 2)
            {
                // This is when mode is GL_LINE_LOOP and picked last line(the loop back one)
                PickingLastLineInLineLoop(pickedGeometry);
                return pickedGeometry;
            }

            // Other conditions
            switch (typeOfMode)
            {
                case GeometryType.Line:
                    pickedGeometry.Indexes = new uint[] { lastVertexId - 1, lastVertexId, };
                    pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 1, 2);
                    break;
                case GeometryType.Triangle:
                    if (mode == DrawMode.TriangleFan)
                    {
                        pickedGeometry.Indexes = new uint[] { 0, lastVertexId - 1, lastVertexId, };
                        pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.Indexes);
                    }
                    else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
                    {
                        pickedGeometry.Indexes = new uint[] { lastVertexId - 4, lastVertexId - 2, lastVertexId, };
                        pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.Indexes);
                    }
                    else
                    {
                        pickedGeometry.Indexes = new uint[] { lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                        pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 2, 3);
                    }
                    break;
                case GeometryType.Quad:
                    pickedGeometry.Indexes = new uint[] { lastVertexId - 3, lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                    pickedGeometry.Positions = FillPickedGeometrysPosition(lastVertexId - 3, 4);
                    break;
                case GeometryType.Polygon:
                    pickedGeometry.Indexes = new uint[vertexCount];
                    for (uint i = 0; i < vertexCount; i++)
                    { pickedGeometry.Indexes[i] = lastVertexId + i; }
                    pickedGeometry.Positions = FillPickedGeometrysPosition(0, vertexCount);
                    break;
                default:
                    throw new NotImplementedException();
            }

            return pickedGeometry;
        }