/// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
                                                         int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveInfo lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId, x, y);

            if (lastIndexId == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]",
                                    lastVertexId, arg, stageVertexId, x, y));
                { return(null); }
            }

            PickingGeometryType geometryType = arg.PickingGeometryType;
            DrawMode            mode         = this.indexBuffer.Mode;
            PickingGeometryType typeOfMode   = mode.ToGeometryType();

            if (geometryType == PickingGeometryType.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == PickingGeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == PickingGeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == PickingGeometryType.Line)
            {
                // 获取pickedGeometry
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="lastVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, RecognizedPrimitiveInfo primitiveInfo, OneIndexPointSearcher searcher)
        {
            var vertexIds = new uint[] { searcher.Search(arg, x, y, primitiveInfo, this), };

            vec3[] positions      = FillPickedGeometrysPosition(vertexIds);
            var    pickedGeometry = new PickedGeometry(PickingGeometryType.Point, positions, vertexIds, stageVertexId, this);

            return(pickedGeometry);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId)
        {
            PickableNode node = this.Renderer;

            uint lastVertexId;

            if (!node.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveInfo lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId);

            if (lastIndexId == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]",
                                    lastVertexId, arg, stageVertexId));
                { return(null); }
            }

            PickingGeometryTypes geometryType = arg.GeometryType;
            DrawMode             drawMode     = node.PickingRenderUnit.VertexArrayObject.IndexBuffer.Mode;
            GeometryType         typeOfMode   = drawMode.ToGeometryType();

            if ((geometryType & PickingGeometryTypes.Point) == PickingGeometryTypes.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, drawMode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else if ((geometryType & PickingGeometryTypes.Line) == PickingGeometryTypes.Line)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point) // want a line when rendering GL_POINTS
                {
                    return(null);
                }
                if (typeOfMode == GeometryType.Line)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else
            {
                if (geometryType.Contains(typeOfMode)) // I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
        private static OneIndexPointSearcher GetPointSearcher(DrawMode mode)
        {
            OneIndexPointSearcher result = null;

            switch (mode)
            {
            case DrawMode.Points:
                break;

            case DrawMode.Lines:
                break;

            case DrawMode.LineLoop:
                break;

            case DrawMode.LineStrip:
                break;

            case DrawMode.Triangles:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStrip:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleFan:
                result = pointInTriangle;
                break;

            case DrawMode.Quads:
                result = pointInQuad;
                break;

            case DrawMode.QuadStrip:
                result = pointInQuad;
                break;

            case DrawMode.Polygon:
                result = pointInPolygon;
                break;

            case DrawMode.LinesAdjacency:
                break;

            case DrawMode.LineStripAdjacency:
                break;

            case DrawMode.TrianglesAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStripAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.Patches:
                break;

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

            return(result);
        }
Exemple #5
0
        private PickedGeometry SearchPoint(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, RecognizedPrimitiveIndex lastIndexId, OneIndexPointSearcher searcher)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.From          = this;
            pickedGeometry.GeometryType  = GeometryType.Line;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.Indexes       = new uint[] { searcher.Search(arg, x, y, lastIndexId, this), };
            pickedGeometry.Positions     = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return(pickedGeometry);
        }
Exemple #6
0
        private static OneIndexPointSearcher GetPointSearcher(DrawMode mode)
        {
            OneIndexPointSearcher result = null;

            switch (mode)
            {
            case DrawMode.Points:
                break;

            case DrawMode.Lines:
                break;

            case DrawMode.LineLoop:
                break;

            case DrawMode.LineStrip:
                break;

            case DrawMode.Triangles:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStrip:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleFan:
                result = pointInTriangle;
                break;

            case DrawMode.Quads:
                result = pointInQuad;
                break;

            case DrawMode.QuadStrip:
                result = pointInQuad;
                break;

            case DrawMode.Polygon:
                result = pointInPolygon;
                break;

            case DrawMode.LinesAdjacency:
                break;

            case DrawMode.LineStripAdjacency:
                break;

            case DrawMode.TrianglesAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStripAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.Patches:
                break;

            default:
                break;
            }

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <param name="lastVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, RecognizedPrimitiveInfo primitiveInfo, OneIndexPointSearcher searcher)
        {
            var vertexIds = new uint[] { searcher.Search(arg, x, y, primitiveInfo, this), };
            vec3[] positions = FillPickedGeometrysPosition(vertexIds);
            var pickedGeometry = new PickedGeometry(arg.UsingViewPort, PickingGeometryType.Point, positions, vertexIds, stageVertexId, this);

            return pickedGeometry;
        }