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

            效果:

            亚洲乱码精品久久久久..| 99久久婷婷国产综合亚洲| 亚洲午夜精品久久久久久人妖| 18岁日韩内射颜射午夜久久成人| 伊人久久精品无码二区麻豆| 久久久久女人精品毛片| 久久精品成人免费国产片小草| 久久青青色综合| 国产欧美久久久精品| 亚洲国产另类久久久精品| 国产精品久久国产精品99盘| 理论片午午伦夜理片久久| 久久久久无码精品国产| 久久久无码精品午夜| 国产精品一久久香蕉国产线看 | 青青草原综合久久大伊人精品| 久久久久亚洲爆乳少妇无| 99久久这里只有精品| 国产A级毛片久久久精品毛片| 久久久久亚洲AV成人网| 久久亚洲精品中文字幕三区| 一本色综合网久久| 美女久久久久久| 久久国产乱子伦精品免费午夜| 亚洲欧洲日产国码无码久久99| 综合久久一区二区三区| 热久久视久久精品18| 久久久久黑人强伦姧人妻| 88久久精品无码一区二区毛片| 久久精品午夜一区二区福利| 亚洲精品tv久久久久久久久 | 久久久久亚洲爆乳少妇无| 2020最新久久久视精品爱| 曰曰摸天天摸人人看久久久| 久久精品视频免费| 2021国产成人精品久久| 国产AⅤ精品一区二区三区久久 | 久久久国产精品| 日本精品久久久久影院日本| 人妻系列无码专区久久五月天| 中文精品久久久久人妻|