The color-coded picking result.

Representing a primitive.

Inheritance: IPickedGeometry
コード例 #1
0
        private PickedGeometry SearchPoint(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, ZeroIndexPointSearcher searcher)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

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

            return(pickedGeometry);
        }
コード例 #2
0
        /// <summary>
        /// 是三角形,就pick一个三角形;是四边形,就pick一个四边形,是多边形,就pick一个多边形。
        /// </summary>
        /// <param name="stageVertexId"></param>
        /// <param name="lastIndexId"></param>
        /// <param name="typeOfMode"></param>
        /// <returns></returns>
        private PickedGeometry PickWhateverItIs(uint stageVertexId, RecognizedPrimitiveIndex lastIndexId, GeometryType typeOfMode)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.GeometryType  = typeOfMode;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From          = this;
            pickedGeometry.Indexes       = lastIndexId.IndexIdList.ToArray();
            pickedGeometry.Positions     = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return(pickedGeometry);
        }
コード例 #3
0
        private PickedGeometry SearchLine(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, RecognizedPrimitiveIndex lastIndexId, OneIndexLineSearcher searcher)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.From          = this;
            pickedGeometry.GeometryType  = GeometryType.Line;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.Indexes       = searcher.Search(arg, x, y, lastIndexId, this);
            pickedGeometry.Positions     = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return(pickedGeometry);
        }
コード例 #4
0
        private PickedGeometry PickPoint(uint stageVertexId, uint lastVertexId)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.GeometryType  = GeometryType.Point;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From          = this;
            pickedGeometry.Indexes       = new uint[] { lastVertexId, };
            pickedGeometry.Positions     = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return(pickedGeometry);
        }
コード例 #5
0
        /// <summary>
        /// 是三角形,就pick一个三角形;是四边形,就pick一个四边形,是多边形,就pick一个多边形。
        /// </summary>
        /// <param name="stageVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="typeOfMode"></param>
        /// <returns></returns>
        private PickedGeometry PickWhateverItIs(uint stageVertexId, RecognizedPrimitiveInfo primitiveInfo, GeometryType typeOfMode)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();

            pickedGeometry.GeometryType  = typeOfMode;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From          = this;
            pickedGeometry.VertexIds     = primitiveInfo.VertexIds;
            pickedGeometry.Positions     = FillPickedGeometrysPosition(pickedGeometry.VertexIds);

            return(pickedGeometry);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <returns></returns>
        public virtual PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId)
        {
            PickedGeometry result = null;

            PickerBase picker = this.picker;

            if (picker != null)
            {
                result = picker.GetPickedGeometry(arg, stageVertexId);
            }

            return(result);
        }
コード例 #7
0
ファイル: PickingAction.cs プロジェクト: skyformat99/CSharpGL
        /// <summary>
        /// Pick geometry at specified positon.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="geometryTypes"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public PickedGeometry Pick(int x, int y, PickingGeometryTypes geometryTypes, int width, int height)
        {
            if (x < 0 || width <= x)
            {
                return(null);
            }
            if (y < 0 || height <= y)
            {
                return(null);
            }
            if (geometryTypes == 0)
            {
                return(null);
            }

            PickedGeometry pickedGeometry = null;

            Framebuffer framebuffer = GetPickingFramebuffer(width, height);

            framebuffer.Bind();
            {
                const float one = 1.0f;
                GL.Instance.ClearColor(one, one, one, one);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                var arg = new PickingEventArgs(this.Scene, x, y, geometryTypes);
                this.RenderForPicking(this.Scene.RootElement, arg);

                uint stageVertexId = ColorCodedPicking.ReadStageVertexId(x, y);

                pickedGeometry = SearchGeometry(stageVertexId, arg, this.Scene.RootElement);

                if (pickedGeometry != null)
                {
                    var      depth  = new float[1];
                    GCHandle pinned = GCHandle.Alloc(depth, GCHandleType.Pinned);
                    IntPtr   header = pinned.AddrOfPinnedObject();
                    // same with: IntPtr header = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0);
                    GL.Instance.ReadPixels(x, y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, header);
                    pinned.Free();

                    pickedGeometry.PickedPosition = new vec3(x, y, depth[0]);
                }
            }
            framebuffer.Unbind();

            return(pickedGeometry);
        }
コード例 #8
0
        /// <summary>
        /// Pick
        /// </summary>
        /// <param name="mousePosition">mouse position.</param>
        /// <param name="pickingGeometryType">target's geometry type.</param>
        /// <returns></returns>
        public PickedGeometry ColorCodedPicking(Point mousePosition, GeometryType pickingGeometryType)
        {
            Rectangle clientRectangle = this.Canvas.ClientRectangle;

            if (mousePosition.X < 0 || clientRectangle.Width <= mousePosition.X || mousePosition.Y < 0 || clientRectangle.Height <= mousePosition.Y)
            {
                return(null);
            }

            Rectangle rect = new Rectangle(mousePosition.X, mousePosition.Y, 1, 1);

            if (!PickedSomething(rect, clientRectangle))
            {
                return(null);
            }

            lock (this.synObj)
            {
                var arg = new RenderEventArgs(RenderModes.ColorCodedPicking, clientRectangle, this.Camera, pickingGeometryType);
                List <IColorCodedPicking> pickableRendererList = Render4Picking(arg);

                List <Tuple <Point, uint> > stageVertexIdList = ReadPixels(rect, clientRectangle.Height);

                var result = new List <Tuple <Point, PickedGeometry> >();
                foreach (var tuple in stageVertexIdList)
                {
                    int x = tuple.Item1.X;
                    int y = tuple.Item1.Y;
                    //if (x < 0 || clientRectangle.Width <= x || y < 0 || clientRectangle.Height <= y) { continue; }

                    uint           stageVertexId  = tuple.Item2;
                    PickedGeometry pickedGeometry = GetPickGeometry(arg,
                                                                    x, y, stageVertexId, pickableRendererList);
                    if (pickedGeometry != null)
                    {
                        result.Add(new Tuple <Point, PickedGeometry>(tuple.Item1, pickedGeometry));
                    }
                }

                if (result.Count > 0)
                {
                    return(result[0].Item2);
                }
            }

            return(null);
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="singleNodeVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(PickingEventArgs arg, uint singleNodeVertexId, uint stageVertexId, RecognizedPrimitiveInfo primitiveInfo, DrawElementsPointSearcher searcher)
        {
            uint id = searcher.Search(arg, primitiveInfo, singleNodeVertexId, stageVertexId, this);

            if (id == uint.MaxValue)
            {
                return(null);
            }                                        // Scene's changed before second rendering for picking>

            uint baseId    = stageVertexId - singleNodeVertexId;
            var  vertexIds = new uint[] { (id - baseId) };

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

            return(pickedGeometry);
        }
コード例 #10
0
        /// <summary>
        /// get picked primitive
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="pickableElements"></param>
        /// <returns></returns>
        private static PickedGeometry PickGeometry(RenderEventArgs arg,
                                                   int x, int y,
                                                   uint stageVertexId,
                                                   params IColorCodedPicking[] pickableElements)
        {
            PickedGeometry pickedGeometry = null;

            foreach (var item in pickableElements)
            {
                pickedGeometry = item.Pick(arg, stageVertexId,
                                           x, y);
                if (pickedGeometry != null)
                {
                    break;
                }
            }

            return(pickedGeometry);
        }
コード例 #11
0
        /// <summary>
        /// get picked geometry.
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="x">mouse position</param>
        /// <param name="y">mouse position</param>
        /// <param name="stageVertexId"></param>
        /// <param name="pickableRendererList"></param>
        /// <returns></returns>
        private static PickedGeometry GetPickGeometry(RenderEventArgs arg,
                                                      int x, int y,
                                                      uint stageVertexId,
                                                      List <IColorCodedPicking> pickableRendererList)
        {
            PickedGeometry pickedGeometry = null;

            foreach (var item in pickableRendererList)
            {
                pickedGeometry = item.GetPickedGeometry(arg, stageVertexId, x, y);

                if (pickedGeometry != null)
                {
                    break;
                }
            }

            return(pickedGeometry);
        }
コード例 #12
0
        /// <summary>
        /// Pick geometry at specified positon.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="pickTriangle"></param>
        /// <param name="pickQuad"></param>
        /// <param name="pickPolygon"></param>
        /// <returns></returns>
        public PickedGeometry Pick(int x, int y, bool pickTriangle, bool pickQuad, bool pickPolygon)
        {
            PickingGeometryTypes geometryTypes = 0;

            if (pickTriangle)
            {
                geometryTypes |= PickingGeometryTypes.Triangle;
            }
            if (pickQuad)
            {
                geometryTypes |= PickingGeometryTypes.Quad;
            }
            if (pickPolygon)
            {
                geometryTypes |= PickingGeometryTypes.Polygon;
            }
            if (geometryTypes == 0)
            {
                return(null);
            }

            PickedGeometry pickedGeometry = null;

            Framebuffer framebuffer = GetPickingFramebuffer();

            framebuffer.Bind();
            {
                const float one = 1.0f;
                GL.Instance.ClearColor(one, one, one, one);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                var arg = new PickingEventArgs(this.Scene, x, y, geometryTypes);
                this.RenderForPicking(this.Scene.RootElement, arg);

                uint stageVertexId = ColorCodedPicking.ReadStageVertexId(x, y);

                pickedGeometry = Pick(stageVertexId, arg, this.Scene.RootElement);
            }
            framebuffer.Unbind();

            return(pickedGeometry);
        }
コード例 #13
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>
        /// <returns></returns>
        public PickedGeometry GetPickedGeometry(
            RenderEventArgs arg,
            uint stageVertexId,
            int x, int y)
        {
            InnerPickableRenderer renderer = this.innerPickableRenderer;

            if (renderer == null)
            {
                throw new Exception("InnerPickableRenderer is null!");
            }

            PickedGeometry result = this.innerPickableRenderer.GetPickedGeometry(arg, stageVertexId, x, y);

            if (result != null)
            {
                result.FromRenderer = this;
            }

            return(result);
        }
コード例 #14
0
        /// <summary>
        /// Color Coded Picking
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="rect">picking area.</param>
        /// <param name="pickableElements">picking among which elements?</param>
        /// <returns></returns>
        public static List <Tuple <Point, PickedGeometry> > Pick(
            RenderEventArgs arg,
            Rectangle rect,
            params PickableRenderer[] pickableElements)
        {
            var result = new List <Tuple <Point, PickedGeometry> >();

            if (pickableElements.Length == 0)
            {
                return(result);
            }
            if (!PickedSomething(rect, arg.CanvasRect))
            {
                return(result);
            }

            Render4Picking(arg, pickableElements);
            List <Tuple <Point, uint> > stageVertexIdList = ReadPixels(rect, arg.CanvasRect.Height);

            foreach (var tuple in stageVertexIdList)
            {
                int x = tuple.Item1.X;
                int y = tuple.Item1.Y;
                if (x < 0 || arg.CanvasRect.Width <= x || y < 0 || arg.CanvasRect.Height <= y)
                {
                    continue;
                }

                uint           stageVertexId  = tuple.Item2;
                PickedGeometry pickedGeometry = GetPickGeometry(arg,
                                                                x, y, stageVertexId, pickableElements);
                if (pickedGeometry != null)
                {
                    result.Add(new Tuple <Point, PickedGeometry>(new Point(x, y), pickedGeometry));
                }
            }

            return(result);
        }
コード例 #15
0
ファイル: PickingAction.cs プロジェクト: 91yuan/CSharpGL
        /// <summary>
        /// Pick geometry at specified positon.
        /// </summary>
        /// <param name="x">Left Down is (0, 0)</param>
        /// <param name="y">Left Down is (0, 0)</param>
        /// <param name="geometryType"></param>
        /// <returns></returns>
        public PickedGeometry Pick(int x, int y, GeometryType geometryType)
        {
            PickedGeometry pickedGeometry = null;

            Framebuffer framebuffer = GetPickingFramebuffer();

            framebuffer.Bind();
            {
                const float one = 1.0f;
                GL.Instance.ClearColor(one, one, one, one);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                var arg = new PickingEventArgs(this.Scene, x, y, geometryType.ToFlags());
                this.RenderForPicking(this.Scene.RootElement, arg);

                uint stageVertexId = ColorCodedPicking.ReadStageVertexId(x, y);

                pickedGeometry = Pick(stageVertexId, arg, this.Scene.RootElement);
            }
            framebuffer.Unbind();

            return(pickedGeometry);
        }
コード例 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <returns></returns>
        public virtual PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId)
        {
            PickedGeometry result = null;

            PickerBase[] picker = this.picker;
            if (picker != null)
            {
                var  pickable = this as IPickable;
                uint baseId   = pickable.PickingBaseId;
                for (int i = 0; i < picker.Length; i++)
                {
                    var blockVertexCount = (uint)picker[i].PositionBuffer.Length;
                    if (baseId <= stageVertexId && stageVertexId < baseId + blockVertexCount)
                    {
                        result = picker[i].GetPickedGeometry(arg, stageVertexId, baseId);
                        break;
                    }

                    baseId += blockVertexCount;
                }
            }

            return(result);
        }
コード例 #17
0
        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(typeOfMode, positions, vertexIds, stageVertexId, this);

            return(pickedGeometry);
        }
コード例 #18
0
        private PickedGeometry PickPoint(uint stageVertexId, uint lastVertexId)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();
            pickedGeometry.GeometryType = GeometryType.Point;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.From = this;
            pickedGeometry.Indexes = new uint[] { lastVertexId, };
            pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return pickedGeometry;
        }
コード例 #19
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="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, ZeroIndexPointSearcher searcher)
        {
            var vertexIds = new uint[] { searcher.Search(arg, x, y, lastVertexId, this), };
            vec3[] positions = FillPickedGeometrysPosition(vertexIds);
            var pickedGeometry = new PickedGeometry(arg.UsingViewPort, PickingGeometryType.Line, positions, vertexIds, stageVertexId, this);

            return pickedGeometry;
        }
コード例 #20
0
        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;
        }
コード例 #21
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.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);
        }
コード例 #22
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.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;
        }
コード例 #23
0
        private PickedGeometry SearchPoint(RenderEventArg arg, uint stageVertexId, int x, int y, uint lastVertexId, ZeroIndexPointSearcher searcher)
        {
            PickedGeometry pickedGeometry = new PickedGeometry();
            pickedGeometry.From = this;
            pickedGeometry.GeometryType = GeometryType.Line;
            pickedGeometry.StageVertexId = stageVertexId;
            pickedGeometry.Indexes = new uint[] { searcher.Search(arg, x, y, lastVertexId, this), };
            pickedGeometry.Positions = FillPickedGeometrysPosition(pickedGeometry.Indexes);

            return pickedGeometry;
        }
コード例 #24
0
        private PickedGeometry PickWhateverItIs(PickingEventArgs arg, uint stageVertexId, uint flatColorVertexId, 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 (flatColorVertexId == 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[] { flatColorVertexId, };
                    positions = FillPickedGeometrysPosition(flatColorVertexId, 1);
                    break;

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

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

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

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

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

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

            return(pickedGeometry);
        }
コード例 #25
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 SearchLine(RenderEventArgs arg, uint stageVertexId, int x, int y, uint lastVertexId, RecognizedPrimitiveInfo primitiveInfo, OneIndexLineSearcher searcher)
        {
            var vertexIds = searcher.Search(arg, x, y, primitiveInfo, this);
            vec3[] positions = FillPickedGeometrysPosition(vertexIds);
            var pickedGeometry = new PickedGeometry(arg.UsingViewPort, PickingGeometryType.Line, positions, vertexIds, stageVertexId, this);

            return pickedGeometry;
        }
コード例 #26
0
 private void PickingLastLineInLineLoop(PickedGeometry pickedGeometry)
 {
     const int vertexCount = 2;
     var offsets = new int[vertexCount] { (this.positionBufferPtr.Length - 1) * this.positionBufferPtr.DataSize * this.positionBufferPtr.DataTypeByteLength, 0, };
     pickedGeometry.Positions = new vec3[vertexCount];
     pickedGeometry.Indexes = new uint[vertexCount];
     for (int i = 0; i < vertexCount; i++)
     {
         OpenGL.BindBuffer(BufferTarget.ArrayBuffer, this.positionBufferPtr.BufferId);
         IntPtr pointer = OpenGL.MapBufferRange(BufferTarget.ArrayBuffer,
             offsets[i],
             1 * this.positionBufferPtr.DataSize * this.positionBufferPtr.DataTypeByteLength,
             MapBufferRangeAccess.MapReadBit);
         unsafe
         {
             var array = (vec3*)pointer.ToPointer();
             pickedGeometry.Positions[i] = array[0];
         }
         OpenGL.UnmapBuffer(BufferTarget.ArrayBuffer);
         pickedGeometry.Indexes[i] = (uint)offsets[i] / (uint)(this.positionBufferPtr.DataSize * this.positionBufferPtr.DataTypeByteLength);
     }
 }
コード例 #27
0
        /// <summary>
        /// 是三角形,就pick一个三角形;是四边形,就pick一个四边形,是多边形,就pick一个多边形。
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="typeOfMode"></param>
        /// <returns></returns>
        private PickedGeometry PickWhateverItIs(RenderEventArgs arg, uint stageVertexId, RecognizedPrimitiveInfo primitiveInfo, PickingGeometryType typeOfMode)
        {
            uint[] vertexIds = primitiveInfo.VertexIds;
            vec3[] positions = FillPickedGeometrysPosition(vertexIds);
            var pickedGeometry = new PickedGeometry(arg.UsingViewPort, typeOfMode, positions, vertexIds, stageVertexId, this);

            return pickedGeometry;
        }
コード例 #28
0
        private PickedGeometry PickPoint(RenderEventArgs arg, uint stageVertexId, uint lastVertexId)
        {
            var vertexIds = new uint[] { lastVertexId, };
            var positions = FillPickedGeometrysPosition(vertexIds);
            var pickedGeometry = new PickedGeometry(arg.UsingViewPort, PickingGeometryType.Point, positions, vertexIds, stageVertexId, this);

            return pickedGeometry;
        }