• <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 閱讀(1557) 評(píng)論(0)  編輯 收藏 引用

            相對(duì)于其他的子系統(tǒng)來說, 輸入系統(tǒng)是比較簡單的. 很多游戲根本就沒有對(duì)這一塊進(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會(huì)檢測當(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.     }

            效果:


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            亚洲精品tv久久久久久久久| 亚洲精品国产成人99久久| 欧洲性大片xxxxx久久久| 亚洲国产高清精品线久久| 精品国产日韩久久亚洲| 久久精品国产99久久无毒不卡| 狠色狠色狠狠色综合久久| 要久久爱在线免费观看| 久久精品国产亚洲av高清漫画 | 大美女久久久久久j久久| 久久精品不卡| 久久久久久亚洲Av无码精品专口 | 精品久久久中文字幕人妻| 久久99国产精品尤物| 久久人人爽人人爽人人片AV东京热| 国产成人精品综合久久久久| 久久久久久a亚洲欧洲aⅴ | 精品无码久久久久久国产| 97久久国产露脸精品国产| 久久久国产一区二区三区| 国产精品免费福利久久| 亚洲午夜精品久久久久久app| 久久国产免费观看精品| 国产成年无码久久久免费| 久久毛片免费看一区二区三区| 久久久久AV综合网成人 | 狠狠综合久久AV一区二区三区 | 国产高潮国产高潮久久久91 | 亚洲欧洲中文日韩久久AV乱码| av无码久久久久久不卡网站| 一本色道久久88综合日韩精品 | 欧美精品福利视频一区二区三区久久久精品 | 亚洲欧美另类日本久久国产真实乱对白 | 日韩精品久久久久久久电影| 久久精品国产亚洲精品| 91久久精品国产免费直播| 精品久久一区二区| 久久精品无码一区二区三区| 国内精品九九久久久精品| 国内精品人妻无码久久久影院| 精品久久久噜噜噜久久久|