• <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)是比較簡單的. 很多游戲根本就沒有對這一塊進(jìn)行封裝, 而直接采用了Win32的消息機(jī)制.

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

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

            基本的消息處理機(jī)制是這樣的一個(gè)流程:

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

            一般只需要關(guān)心這么幾個(gè)函數(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先略過, 原理相同

            測試?yán)? 在上一次的代碼中添加一段:

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

            效果:

            中文字幕乱码久久午夜| 久久久无码精品亚洲日韩软件| 精品久久久久久无码人妻热| 久久久久久久尹人综合网亚洲 | 91久久香蕉国产熟女线看| 久久精品18| 久久婷婷五月综合色高清| 2020久久精品国产免费| 久久国产成人午夜aⅴ影院| 中文字幕久久久久人妻| 国内精品久久久久久中文字幕| 伊人久久大香线蕉av不卡| 久久久中文字幕| 国产69精品久久久久久人妻精品| 国产精品成人99久久久久91gav| 一本一本久久A久久综合精品 | 狠狠色丁香婷综合久久| 久久综合伊人77777麻豆| 精品久久久久久国产| 日韩乱码人妻无码中文字幕久久 | 久久国产精品无码一区二区三区| 日本久久中文字幕| 久久国产成人午夜AV影院| 色诱久久久久综合网ywww| 久久这里都是精品| 精品久久久久久无码不卡| 国产成人精品久久| 狠狠狠色丁香婷婷综合久久俺| 久久精品无码专区免费青青| 久久久久久一区国产精品| 品成人欧美大片久久国产欧美...| 久久免费视频网站| 久久99国产精品久久99| 久久综合九色综合欧美狠狠| 久久婷婷五月综合色奶水99啪 | 色综合久久综精品| 伊人久久大香线蕉精品| 日韩亚洲欧美久久久www综合网| 国产真实乱对白精彩久久| 激情久久久久久久久久| 色天使久久综合网天天|