示例#1
0
        /// <summary>
        /// 在三角形图元中拾取指定位置的Line
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="lastVertexId">三角形图元的最后一个顶点</param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        uint lastVertexId, ZeroIndexPicker picker)
        {
            // 创建临时索引
            OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 6, DrawMode.Lines, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 1; array[1] = lastVertexId - 0;
                array[2] = lastVertexId - 2; array[3] = lastVertexId - 1;
                array[4] = lastVertexId - 0; array[5] = lastVertexId - 2;
                buffer.UnmapBuffer();
            }
            // 用临时索引渲染此三角形图元(仅渲染此三角形图元)
            picker.Renderer.Render4InnerPicking(arg, buffer);
            // id是拾取到的Line的Last Vertex Id
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            // 对比临时索引,找到那个Line
            if (id + 2 == lastVertexId)
            {
                return(new uint[] { id + 2, id, });
            }
            else
            {
                return(new uint[] { id - 1, id, });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="lastVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        uint lastVertexId, ZeroIndexPicker picker)
        {
            OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 8, DrawMode.Lines, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 1; array[1] = lastVertexId - 0;
                array[2] = lastVertexId - 2; array[3] = lastVertexId - 1;
                array[4] = lastVertexId - 3; array[5] = lastVertexId - 2;
                array[6] = lastVertexId - 0; array[7] = lastVertexId - 3;
                buffer.UnmapBuffer();
            }
            picker.Node.Render4InnerPicking(arg, buffer);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (id + 3 == lastVertexId)
            {
                return(new uint[] { id + 3, id, });
            }
            else
            {
                return(new uint[] { id - 1, id, });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></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="modernRenderer"></param>
        /// <returns></returns>
        internal override uint[] Search(RenderEventArgs arg,
                                        int x, int y,
                                        uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 6, DrawMode.Lines, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 2; array[1] = lastVertexId - 0;
                array[2] = lastVertexId - 4; array[3] = lastVertexId - 2;
                array[4] = lastVertexId - 0; array[5] = lastVertexId - 4;
                buffer.UnmapBuffer();
            }

            modernRenderer.Render4InnerPicking(arg, buffer);
            uint id = ColorCodedPicking.ReadStageVertexId(x, y);

            buffer.Dispose();

            if (id + 4 == lastVertexId)
            {
                return(new uint[] { id + 4, id, });
            }
            else
            {
                return(new uint[] { id - 2, id, });
            }
        }
示例#4
0
        public IndexBuffer GetIndexBuffer()
        {
            if (this.indexBuffer == null)
            {
                int            length = this.SideLength * (this.SideLength - 1) * 2;
                OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.TriangleStrip, BufferUsage.StaticDraw);
                unsafe
                {
                    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                    var    array   = (uint *)pointer;
                    for (int k = 0; k < this.SideLength - 1; k++)
                    {
                        for (int i = 0; i < this.SideLength; i++)
                        {
                            if (k % 2 == 0)
                            {
                                array[(i + k * this.SideLength) * 2 + 0] = (uint)(i + (k + 1) * this.SideLength);
                                array[(i + k * this.SideLength) * 2 + 1] = (uint)(i + (k + 0) * this.SideLength);
                            }
                            else
                            {
                                array[(i + k * this.SideLength) * 2 + 0] = (uint)(this.SideLength - 1 - i + (k + 0) * this.SideLength);
                                array[(i + k * this.SideLength) * 2 + 1] = (uint)(this.SideLength - 1 - i + (k + 1) * this.SideLength);
                            }
                        }
                    }
                    buffer.UnmapBuffer();
                }
                this.indexBuffer = buffer;
            }

            return(this.indexBuffer);
        }
示例#5
0
        public unsafe IndexBuffer GetIndexBuffer()
        {
            if (this.indexBuffer != null)
            {
                return(this.indexBuffer);
            }

            int            vertexCount = (faceCount * 2 + 2) * (this.pipeline.Count - 1);
            int            length      = vertexCount + (this.pipeline.Count - 1);
            OneIndexBuffer buffer      = CSharpGL.Buffer.Create(IndexBufferElementType.UInt, length, DrawMode.QuadStrip, BufferUsage.StaticDraw);

            unsafe
            {
                IntPtr pointer       = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                var    array         = (uint *)pointer.ToPointer();
                uint   positionIndex = 0;
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (i % (faceCount * 2 + 2 + 1) == (faceCount * 2 + 2))
                    {
                        array[i] = uint.MaxValue;//分割各个圆柱体
                    }
                    else
                    {
                        array[i] = positionIndex++;
                    }
                }
                this.indexBuffer = buffer;
            }

            return(this.indexBuffer);
        }
示例#6
0
        public IndexBuffer GetIndexBuffer()
        {
            if (this.indexBuffer == null)
            {
                OneIndexBuffer buffer = CSharpGL.GLBuffer.Create(IndexBufferElementType.UInt, 3 * 3, DrawMode.Triangles, BufferUsage.StaticDraw);
                unsafe
                {
                    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                    var    array   = (uint *)pointer;
                    array[0] = 0; array[1] = 1; array[2] = 3;
                    array[3] = 0; array[4] = 3; array[5] = 2;
                    array[6] = 1; array[7] = 3; array[8] = 2;
                    buffer.UnmapBuffer();
                }
                this.indexBuffer = buffer;
            }

            return(this.indexBuffer);
        }
示例#7
0
        public override IndexBuffer GetIndexBuffer()
        {
            if (this.indexBuffer == null)
            {
                int            dimSize = this.DataSource.DimenSize;
                int            length  = dimSize * 2 * (Marshal.SizeOf(typeof(HalfHexahedronIndex)) / sizeof(uint));
                OneIndexBuffer buffer  = CSharpGL.GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.QuadStrip, BufferUsage.StaticDraw);
                unsafe
                {
                    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                    var    array   = (HalfHexahedronIndex *)pointer;
                    for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                    {
                        array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                        array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                        array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                        array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                        array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                        array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                        array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                        array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                        array[gridIndex * 2].restartIndex = uint.MaxValue;

                        array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                        array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                        array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                        array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                        array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                        array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                        array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                        array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                        array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
                    }
                    buffer.UnmapBuffer();
                }
                this.indexBuffer = buffer;
            }

            return(this.indexBuffer);
        }
示例#8
0
        public IndexBuffer GetIndexBuffer()
        {
            if (this.indexBuffer == null)
            {
                int            uCount = GetUCount(interval);
                int            vCount = GetVCount(interval);
                int            length = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount;
                OneIndexBuffer buffer = CSharpGL.Buffer.Create(IndexBufferElementType.UInt, length, DrawMode.LineStrip, BufferUsage.StaticDraw);
                unsafe
                {
                    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
                    var    array   = (uint *)pointer;
                    int    index   = 0;
                    // vertical lines.
                    for (int i = 0; i < vCount; i++)
                    {
                        for (int j = 0; j < uCount; j++)
                        {
                            array[index++] = (uint)(i + j * vCount);
                        }
                        array[index++] = uint.MaxValue;// primitive restart index.
                    }
                    // horizontal lines.
                    for (int i = 0; i < uCount; i++)
                    {
                        for (int j = 0; j < vCount; j++)
                        {
                            array[index++] = (uint)(j + i * vCount);
                        }
                        array[index++] = (uint)(0 + i * vCount);
                        array[index++] = uint.MaxValue;// primitive restart index.
                    }
                    buffer.UnmapBuffer();
                }
                this.indexBuffer = buffer;
            }

            return(this.indexBuffer);
        }