• <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   管理


            亚洲国产精品嫩草影院久久| 国产精品成人99久久久久 | 久久久久亚洲?V成人无码| 久久国产V一级毛多内射| 精品无码久久久久国产动漫3d | 91麻精品国产91久久久久| 日本精品一区二区久久久| 国色天香久久久久久久小说| 69国产成人综合久久精品| 亚洲国产精品无码久久青草 | 精品久久久久中文字幕一区| 亚洲Av无码国产情品久久| 久久w5ww成w人免费| 色偷偷88欧美精品久久久 | 成人a毛片久久免费播放| 久久久久精品国产亚洲AV无码| 91精品国产91久久久久久蜜臀| 久久婷婷色综合一区二区| 狠狠精品久久久无码中文字幕| 少妇精品久久久一区二区三区| 久久996热精品xxxx| 伊人丁香狠狠色综合久久| 久久精品无码专区免费东京热 | 久久精品国产精品青草app| 久久久久久久久久久久久久| 久久99精品九九九久久婷婷| 亚洲国产另类久久久精品 | 久久人人爽人人爽人人片AV不| 99久久精品无码一区二区毛片| 久久亚洲私人国产精品| 香蕉久久av一区二区三区| 久久精品国产久精国产一老狼| 热久久国产欧美一区二区精品 | 久久国产高潮流白浆免费观看| 99久久国产综合精品女同图片| 亚洲国产成人久久综合区| 伊人久久五月天| 久久精品国产AV一区二区三区| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 久久99毛片免费观看不卡| 久久久久无码精品国产|