• <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.     }

            效果:

            久久久久无码精品国产不卡| www.久久99| 亚洲国产精品嫩草影院久久| 伊人久久亚洲综合影院| 亚洲精品乱码久久久久久 | 久久久国产视频| 亚洲午夜久久久影院| 26uuu久久五月天| 久久久无码精品亚洲日韩蜜臀浪潮| 亚洲中文精品久久久久久不卡| 久久精品国产免费一区| 久久久久久精品免费看SSS| 久久综合欧美成人| 亚洲va久久久噜噜噜久久男同 | 99久久人妻无码精品系列| 美女久久久久久| 97久久香蕉国产线看观看| 久久精品国产欧美日韩99热| 99久久免费只有精品国产| 日韩精品久久久久久免费| 久久国产亚洲精品| 久久久久国产一区二区| 91视频国产91久久久| 久久久久久久97| 伊人久久国产免费观看视频| 久久综合视频网站| 精品久久久久中文字幕一区| 九九久久99综合一区二区| 亚洲乱码精品久久久久..| 国产69精品久久久久观看软件| 国产精品欧美久久久久无广告| www久久久天天com| 久久精品国产精品青草app| 成人妇女免费播放久久久| 久久久亚洲欧洲日产国码aⅴ| 久久99热这里只有精品66| 无夜精品久久久久久| 久久www免费人成看片| 精品国产99久久久久久麻豆| 精品久久人人爽天天玩人人妻| 伊人久久久AV老熟妇色|