示例#1
0
文件: MeshObj.cs 项目: nanma80/MPUlt
 void SendVBuf(S3DirectX d3dDevice, PrimitiveType type, int nt)
 {
     VBuf.Unlock();
     if (nt != 0)
     {
         int sx = CustomVertex.PositionNormalColored.StrideSize;
         d3dDevice.Renderer.SetStreamSource(0, VBuf, 0, sx);
         d3dDevice.Renderer.VertexFormat = CustomVertex.PositionNormalColored.Format;
         d3dDevice.Renderer.DrawPrimitives(type, 0, nt);
     }
 }
示例#2
0
 public KeyboardState()
 {
     m_qLeftMouse  = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_LBUTTON) & 0x8000) != 0);
     m_qRightMouse = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_RBUTTON) & 0x8000) != 0);
     m_qUp         = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_UP) & 0x8000) != 0);
     m_qDown       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_DOWN) & 0x8000) != 0);
     m_qLeft       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_LEFT) & 0x8000) != 0);
     m_qRight      = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_RIGHT) & 0x8000) != 0);
     m_qPgUp       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_PGUP) & 0x8000) != 0);
     m_qPgDown     = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_PGDOWN) & 0x8000) != 0);
     m_qShift      = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_SHIFT) & 0x8000) != 0);
     m_qCtrl       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_CONTROL) & 0x8000) != 0);
     m_qAlt        = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_ALT) & 0x8000) != 0);
     m_qX          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_X) & 0x8000) != 0);
     m_qY          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_Y) & 0x8000) != 0);
     m_qZ          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_Z) & 0x8000) != 0);
     m_qA          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_A) & 0x8000) != 0);
 }
示例#3
0
 public KeyboardState(MouseEventArgs e)
 {
     m_qLeftMouse  = e.Button == MouseButtons.Left;
     m_qRightMouse = e.Button == MouseButtons.Right;
     m_qShift      = (Control.ModifierKeys & System.Windows.Forms.Keys.Shift) != 0;
     m_qCtrl       = (Control.ModifierKeys & System.Windows.Forms.Keys.Control) != 0;
     m_qAlt        = (Control.ModifierKeys & System.Windows.Forms.Keys.Alt) != 0;
     m_qX          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_X) & 0x8000) != 0);
     m_qY          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_Y) & 0x8000) != 0);
     m_qZ          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_Z) & 0x8000) != 0);
     m_qUp         = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_UP) & 0x8000) != 0);
     m_qDown       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_DOWN) & 0x8000) != 0);
     m_qLeft       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_LEFT) & 0x8000) != 0);
     m_qRight      = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_RIGHT) & 0x8000) != 0);
     m_qPgUp       = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_PGUP) & 0x8000) != 0);
     m_qPgDown     = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_PGDOWN) & 0x8000) != 0);
     m_qA          = ((S3DirectX.GetAsyncKeyState((int)VK_CODES.VK_A) & 0x8000) != 0);
 }
示例#4
0
 public abstract void ProcessMouseMove(S3DirectX scene, EAction action, ETarget tg, System.Drawing.Point pt, int DX, int DY, OnAction proc);
示例#5
0
文件: MeshObj.cs 项目: nanma80/MPUlt
        public void Render(S3DirectX d3dDevice)
        {
            int L = 30000;

            d3dDevice.Renderer.SetTransform(TransformType.World, Matrix.Identity);
            d3dDevice.SetupObjectMaterial(Color.FromArgb(unchecked ((int)0x10404040)));

            for (int i = 0; i < NF; i++)
            {
                BPln[i] = ((S4Camera)(d3dDevice.Camera)).AbovePlane(FPoles[i]);
            }

            if (VBuf == null)
            {
                VBuf = GetNewBuffer(d3dDevice.Renderer, L);
            }
            CustomVertex.PositionNormalColored[] cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
            int ptr = 0;

            for (int ns = 0; ns < NStk; ns++)
            {
                if (Stks[ns].ExtraTwist == null && BPln[Stks[ns].NFace])
                {
                    continue;
                }
                int l0 = Stks[ns].L2D();
                if (ptr + l0 > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.TriangleList, ptr / 3);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                Stks[ns].RecalcCoord((S4Camera)(d3dDevice.Camera));
                int m = 1 << Math.Min(11, Stks[ns].Base.Rank);
                if ((m & ShowRank) == 0)
                {
                    continue;
                }
                ptr = Stks[ns].SetBuffer2D((S4Camera)(d3dDevice.Camera), cbuf, ptr);
            }
            SendVBuf(d3dDevice, PrimitiveType.TriangleList, ptr / 3);

            cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
            ptr  = 0;
            for (int ns = 0; ns < NStk; ns++) // selected stickers
            {
                if (Stks[ns].ExtraTwist == null && BPln[Stks[ns].NFace])
                {
                    continue;
                }
                int u  = Cube.Field[ns];
                int cl = (u & 0x8000) != 0 ? -1 : unchecked ((int)0xff202020);
                if (ptr + Stks[ns].L1D() > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                int m = 1 << Math.Min(11, Stks[ns].Base.Rank);
                if ((m & ShowRank) == 0 && Stks[ns].Base.MinBDim != 0)
                {
                    continue;
                }
                ptr = Stks[ns].SetBuffer1D((S4Camera)(d3dDevice.Camera), cbuf, ptr, cl);
            }
            for (int ns = 0; ns < NF; ns++)
            {
                if (BPln[ns])
                {
                    continue;
                }
                StFaces[ns].RecalcCoord((S4Camera)(d3dDevice.Camera));
                int l0 = StFaces[ns].L1D();
                if (ptr + l0 > L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                ptr = StFaces[ns].SetBuffer1D((S4Camera)(d3dDevice.Camera), cbuf, ptr, -0x7f7f80);
            }
#if false
            int dim = Cube.Str.Dim;
            for (int i = 0; i < lVN; i += 4)
            {
                if (ptr == L)
                {
                    SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
                    cbuf = (CustomVertex.PositionNormalColored[])VBuf.Lock(0, 0);
                    ptr  = 0;
                }
                int f1 = VertNetwork[i], f2 = VertNetwork[i + 2];
                if (BPln[f1] || BPln[f2])
                {
                    continue;
                }
                Vector3 p1 = StFaces[f1].Coords3D[VertNetwork[i + 1] / dim];
                Vector3 p2 = StFaces[f2].Coords3D[VertNetwork[i + 3] / dim];
                if (p1.Z != StkMesh.WRONGPT && p2.Z != StkMesh.WRONGPT)
                {
                    cbuf[ptr++] = new CustomVertex.PositionNormalColored(p1, new Vector3(0, 0, 1), -0x7f7f80);
                    cbuf[ptr++] = new CustomVertex.PositionNormalColored(p2, new Vector3(0, 0, 1), -0x7f7f80);
                }
            }
#endif
            SendVBuf(d3dDevice, PrimitiveType.LineList, ptr / 2);
        }
示例#6
0
        public override void ProcessMouseMove(S3DirectX scene, EAction action, ETarget tg, Point pt, int DX, int DY, OnAction proc)
        {
            /*
             *          if(keys.qRightMouse){
             *              if(keys.qShift) _thisAction=EAction.ActionXYSlide; // WSlide, XY-rotate
             *              else _thisAction=EAction.ActionSlide; // WSlide, XY-rotate
             *              }else{
             *          if(keys.qCtrl) _thisAction=EAction.ActionMoveTo;     // Zoom
             *          else if(keys.qShift) _thisAction=EAction.ActionPan;  // WPan
             *          else _thisAction=EAction.ActionRotate;               // 3D rotate
             *          }
             */



            Vector3 vec  = new Vector3();
            Vector3 shft = new Vector3();
            int     wid  = scene.width;
            int     hgt  = scene.height;
            double  acf  = 3.0 / hgt; // pi/3 for half of screen

            double ddis = Math.Pow(0.5, DY * 3.0 / hgt);
            double wdis = Math.Pow(0.5, DX * 3.0 / wid);

            switch (action)
            {
            case EAction.ActionSlide:      // R
            case EAction.ActionXYSlide:    // Shift-R
                Trans.Rotate(2, 1, DX * 2 * Math.PI / wid);
                Trans.Rotate(0, 3, (double)DY * acf * Angle);
                break;

            case EAction.ActionMoveTo:      // Ctrl-L
                R = Math.Min(2 * R0, Math.Max(0.1 * R0, (R + R0) / ddis)) - R0;
                break;

            case EAction.ActionZoom:      // Ctrl-R
                Angle = (float)Math.Min(Math.PI, Angle / ddis);
                break;

            case EAction.ActionPan:     // Shift-L
                Trans.Rotate(0, 1, (double)DX * acf * Angle);
                Trans.Rotate(0, 2, (double)DY * acf * Angle);
                break;

            case EAction.ActionRotate: {      // L
                if (m_addMask != null)
                {
                    if (m_addMask[0])
                    {
                        goto case EAction.ActionPan;
                    }
                    if (m_addMask[1])
                    {
                        goto case EAction.ActionMoveTo;
                    }
                }
                double dx = (double)(DX * acf);
                double dy = (double)(DY * acf);
                Trans.Rotate(3, 1, dx * Angle);
                Trans.Rotate(3, 2, dy * Angle);
                break;
            }

            case EAction.ActionClick:
            case EAction.ActionShiftClick:
            case EAction.ActionAltClick:
            case EAction.ActionCtrlClick:
            case EAction.ActionCtrlShiftClick:
            case EAction.ActionCtrlAltClick:
            case EAction.ActionRClick:
            case EAction.ActionShiftRClick:
            case EAction.ActionAltRClick:
            case EAction.ActionCtrlShiftRClick:
            case EAction.ActionCtrlRClick: {
                double vx, vy;
                scene.DirAndOrig(pt.X, pt.Y, out vx, out vy);
                vec.Normalize();
                if (proc != null)
                {
                    proc(action, vx, vy, 0);
                }
                break;
            }
            }
            m_changed          = true;
            scene.SceneChanged = true;
        }