• <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 閱讀(1558) 評論(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.     }

            效果:

            无码国产69精品久久久久网站| 久久久久久噜噜精品免费直播| 亚洲AV无码久久精品狠狠爱浪潮| 国产精品免费看久久久| 国产精品成人99久久久久91gav| 久久久久国产一区二区| 国产精品99久久久精品无码| 久久久91精品国产一区二区三区 | 狠狠色丁香久久婷婷综合蜜芽五月 | 91精品国产乱码久久久久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 性做久久久久久久久久久| 久久婷婷五月综合国产尤物app| 久久精品成人免费看| 成人久久免费网站| 国产亚洲美女精品久久久| 久久精品国产99久久久| 亚洲欧美国产日韩综合久久| 久久久久亚洲AV无码麻豆| 一本久久精品一区二区| 很黄很污的网站久久mimi色| 99久久精品国内| 国产精品无码久久久久久| 伊人久久精品无码二区麻豆| 免费精品久久久久久中文字幕| 日韩精品久久久久久| 国产69精品久久久久777| 国产色综合久久无码有码| 中文成人久久久久影院免费观看| 国产精品无码久久四虎| 99热成人精品免费久久| 夜夜亚洲天天久久| 国产成人精品久久一区二区三区av | 久久本道久久综合伊人| 国产福利电影一区二区三区,免费久久久久久久精 | 青青青国产精品国产精品久久久久| 九九精品99久久久香蕉| 久久91精品国产91久久户| 狠狠色丁香久久婷婷综| 国产巨作麻豆欧美亚洲综合久久| 国产精品日韩深夜福利久久|