• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Nebula3的Input系統(tǒng)

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

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

            不過經(jīng)過封裝的輸入系統(tǒng)使用起來很方便, 呵呵.

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

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

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

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

            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伊人| 97久久综合精品久久久综合| 久久精品一区二区| 99久久国产综合精品女同图片| 一本大道久久东京热无码AV| 久久久久亚洲AV综合波多野结衣| 91性高湖久久久久| 国产亚洲精午夜久久久久久| 国产 亚洲 欧美 另类 久久 | 久久亚洲美女精品国产精品| 综合久久精品色| 77777亚洲午夜久久多喷| 久久九九兔免费精品6| 精品久久久中文字幕人妻| 无码伊人66久久大杳蕉网站谷歌 | 久久精品国产免费观看三人同眠| 无码任你躁久久久久久| 狠狠色丁香婷婷久久综合五月 | 精品人妻伦九区久久AAA片69 | 国产精品9999久久久久| 午夜不卡888久久| 欧美日韩成人精品久久久免费看 | 精品熟女少妇av免费久久| 久久青青草原国产精品免费| 久久精品免费网站网| 久久久亚洲欧洲日产国码是AV| 亚洲愉拍99热成人精品热久久 | 久久久国产乱子伦精品作者| 2020最新久久久视精品爱| 香蕉99久久国产综合精品宅男自 | 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 精品久久久久久中文字幕| 狠狠人妻久久久久久综合蜜桃| 色天使久久综合网天天| 亚洲va久久久噜噜噜久久天堂| 亚洲国产成人久久综合碰碰动漫3d| 久久久久香蕉视频| 77777亚洲午夜久久多喷| 国産精品久久久久久久| 人妻精品久久无码专区精东影业| 久久精品国产精品亚洲|