コード例 #1
0
ファイル: Manipulator.cs プロジェクト: bondjames12/spheregame
        private void Pick()
        {
            Viewport vp = mGraphics.GraphicsDevice.Viewport;

            mGraphics.GraphicsDevice.Viewport = mInput.Viewport;

            mPickBuffer.PushMatrix(MatrixMode.View, ViewMatrix);
            mPickBuffer.PushMatrix(MatrixMode.Projection, ProjectionMatrix);
            mPickBuffer.PushMatrix(MatrixMode.World, WorldMatrix);
            mPickBuffer.PushVertexDeclaration(mVertexDeclaration);

            foreach (TransformationMode mode in mDrawFunctions.Keys)
            {
                TransformationMode local_mode = mode;

                if ((mEnabledModes & local_mode) != local_mode)
                {
                    continue;
                }

                foreach (AxisFlags flags in mDrawFunctions[local_mode].Keys)
                {
                    AxisFlags local_flags = flags;

                    mPickBuffer.PushPickID(((uint)local_mode << 8) | (uint)flags);
                    mPickBuffer.QueueRenderFunction(delegate(GraphicsDevice device)
                    {
                        mDrawFunctions[local_mode][local_flags](local_flags);
                    });
                    mPickBuffer.PopPickID();
                }
            }

            mPickBuffer.PopVertexDeclaration();
            mPickBuffer.PopMatrix(MatrixMode.View);
            mPickBuffer.PopMatrix(MatrixMode.Projection);
            mPickBuffer.PopMatrix(MatrixMode.World);

            // render the pick buffer queue
            mPickBuffer.Render();

            // pick using current mouse position and convert picked
            // value back into an Axis value (safe, as the default pick buffer
            // id is 0 (AxisFlags.None) and only AxisFlags values are being rendered as
            // pick ids in the above render pass
            uint pick_id = mPickBuffer.Pick(mInput.X, mInput.Y);

            mSelectedAxes = (AxisFlags)(pick_id & 0xFF);
            mActiveMode   = (TransformationMode)((pick_id >> 8) & 0xFF);

            mGraphics.GraphicsDevice.Viewport = vp;
        }
コード例 #2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (mManipulator.Focused)
            {
                return;
            }

            if ((GraphicsDevice == null) || GraphicsDevice.IsDisposed)
            {
                return;
            }

            Viewport vp = GraphicsDevice.Viewport;

            GraphicsDevice.Viewport = mInput.Viewport;

            mPickBuffer.PushMatrix(MatrixMode.View, camera.ViewMatrix);
            mPickBuffer.PushMatrix(MatrixMode.Projection, camera.ProjectionMatrix);

            //draw each Component into pick buffer
            foreach (XComponent comp in X.Components)
            {
                comp.DrawPick(mPickBuffer, camera);
            }

            mPickBuffer.PopMatrix(MatrixMode.View);
            mPickBuffer.PopMatrix(MatrixMode.Projection);

            mPickBuffer.Render();

            uint pick_id = mPickBuffer.Pick(e.X, e.Y);
            //find the xcomponent we selected
            XComponent component = X.Components.Find(delegate(XComponent obj) { return(obj.ComponentID == pick_id); });

            if (component != null && (component is XITransform))
            {//we selected a valid component we should update our windows UI
                mManipulator.Transform = (XITransform)component;
                //fire change event
                if (OnSelectedComponentChange != null)
                {
                    OnSelectedComponentChange(this, component);
                }
            }


            this.GraphicsDevice.Viewport = vp;
        }