Пример #1
0
        // Methods
        public void Pick(Scene scene, int x, int y)
        {
            scene.DrawScene(RenderState.Select);
            fbManager.ReadFBO(RenderState.Select);
            int[] viewport = new int[4];
            GL.GetInteger(GetPName.Viewport, viewport);
            int   height = viewport[3];
            Byte4 pixel  = new Byte4();

            GL.ReadPixels(x, height - y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, ref pixel);

            // Unselect previously selected object
            if (info.Selected != null)
            {
                info.Selected.IsSelected = false;
            }

            // Get newly selected object reference
            ISelectable newPick = PickRegister.Instance.LookupSelectable((int)pixel.ToUInt32());

            if (newPick != null)
            {
                pollingTimer.Start();
                info.Selected            = newPick;
                info.Selected.Moving     = false;
                info.Selected.Velocity   = Vector3.Zero;
                info.SurfaceCoordinate   = unProject(x, y);
                info.Selected.IsSelected = true;
                console.AddText("Cube Id #" + info.Selected.Id + " selected");
                info.SelectionOffset = info.Selected.Position - info.SurfaceCoordinate.Xyz;
                EnableDrag();
            }
            else
            {
                info.Selected = null;
            }
        }
Пример #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            scene1.DrawScene(RenderState.Render);
            if (showingSelectBuffer)
            {
                fbManager.ReadFBO(RenderState.Select);
                GL.BlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            }
            else
            {
                console.Draw();
            }

            GL.Flush();
            SwapBuffers();
        }