• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 94, comments - 250, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Nebula3的Input系統

            Posted on 2008-12-14 21:53 Condor 閱讀(1563) 評論(0)  編輯 收藏 引用

            相對于其他的子系統來說, 輸入系統是比較簡單的. 很多游戲根本就沒有對這一塊進行封裝, 而直接采用了Win32的消息機制.

            不過經過封裝的輸入系統使用起來很方便, 呵呵.

            N3中有三種輸入設備, 鍵盤, 鼠標, 手柄. 分別是基于Win32消息, DirectInput, XInput實現的. 這里有一個繼承圖能夠很好的說明輸入系統的組織結構:

            基本的消息處理機制是這樣的一個流程:

            InputServer里有默認的一個鍵盤, 一個鼠標, 一個手柄的"handler", 在每幀開始時InputServer會檢測當前的輸入消息,  得到一個InputEvent, 由相應的InputHandler來處理.  各個InputHandler都保存著當前幀各種輸入狀態的緩存(如鼠標左鍵是否按下), 因此, 在程序運行過程中, 我們只要在繪制結束前檢測各個InputHandler的狀態就相當于知道當前用戶是怎樣輸入的了.

            一般只需要關心這么幾個函數就夠了:

            1. ////////////////////// Mouse////////////////////////////
            2. /// return true if button is currently pressed
            3. bool ButtonPressed(Input::MouseButton::Code btn) const;
            4. /// return true if button was down at least once in current frame
            5. bool ButtonDown(Input::MouseButton::Code btn) const;
            6. /// return true if button was up at least once in current frame
            7. bool ButtonUp(Input::MouseButton::Code btn) const;
            8. /// return true if a button has been double clicked
            9. bool ButtonDoubleClicked(Input::MouseButton::Code btn) const;
            10. /// return true if mouse wheel rotated forward
            11. bool WheelForward() const;
            12. /// return true if mouse wheel rotated backward
            13. bool WheelBackward() const;
            14. /// get current absolute mouse position (in pixels)
            15. const Math::float2& GetPixelPosition() const;
            16. /// get current screen space mouse position (0.0 .. 1.0)
            17. const Math::float2& GetScreenPosition() const;
            18. /// get mouse movement
            19. const Math::float2& GetMovement() const;
            1. //////////////////////Keyboard//////////////////////
            2. /// return true if a key is currently pressed
            3. bool KeyPressed(Input::Key::Code keyCode) const;
            4. /// return true if key was down at least once in current frame
            5. bool KeyDown(Input::Key::Code keyCode) const;
            6. /// return true if key was up at least once in current frame
            7. bool KeyUp(Input::Key::Code keyCode) const;
            8. /// get character input in current frame
            9. const Util::String& GetCharInput() const;

            GamePad先略過, 原理相同

            測試例子, 在上一次的代碼中添加一段:

            1. void OnRenderFrame()
            2.     {
            3. if (this->inputServer->GetDefaultMouse()->ButtonDown(MouseButton::LeftButton))
            4.         {
            5.             MessageBoxA(this->displayDevice->GetHwnd(), "Left Button Down", NULL, 0);
            6.         }
            7. //...//
            8.     }

            效果:

            久久久久国产精品嫩草影院| 久久香蕉国产线看观看精品yw| 色综合久久久久| 久久精品国产99久久丝袜| 亚洲国产小视频精品久久久三级| 久久人人爽人人爽人人爽| 99999久久久久久亚洲| 久久精品国产亚洲一区二区三区| 免费无码国产欧美久久18| 国产精品久久久福利| 国产精品久久久久久久人人看| 7777久久亚洲中文字幕| 久久受www免费人成_看片中文| 久久综合丁香激情久久| 久久人人爽人人爽人人片AV不 | 精品熟女少妇av免费久久| 国产精品免费久久久久影院 | 久久精品午夜一区二区福利 | 亚洲国产精品无码久久| 久久人妻少妇嫩草AV蜜桃| 久久精品国产亚洲AV无码麻豆 | 777午夜精品久久av蜜臀| 久久久久久毛片免费看| 久久国产高清字幕中文| 久久婷婷五月综合国产尤物app| 久久免费视频一区| 精品久久久久久无码人妻热| 国内精品久久久久久野外| 色综合久久久久综合体桃花网| 国内精品伊人久久久久妇| 精品人妻伦一二三区久久| 青青青国产成人久久111网站| 97久久精品无码一区二区| 999久久久无码国产精品| 久久午夜无码鲁丝片| 久久99精品久久久久久动态图| 无码国内精品久久综合88| 亚洲综合熟女久久久30p| 亚洲色大成网站WWW久久九九| 久久综合鬼色88久久精品综合自在自线噜噜 | 国产一区二区久久久|