日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Nebula3的Input系统

發布時間:2025/5/22 windows 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nebula3的Input系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

不過經過封裝的輸入系統使用起來很方便, 呵呵.

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

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

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

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

  • // Mouse
  • /// return true if button is currently pressed
  • bool ButtonPressed(Input::MouseButton::Code btn) const;
  • /// return true if button was down at least once in current frame
  • bool ButtonDown(Input::MouseButton::Code btn) const;
  • /// return true if button was up at least once in current frame
  • bool ButtonUp(Input::MouseButton::Code btn) const;
  • /// return true if a button has been double clicked
  • bool ButtonDoubleClicked(Input::MouseButton::Code btn) const;
  • /// return true if mouse wheel rotated forward
  • bool WheelForward() const;
  • /// return true if mouse wheel rotated backward
  • bool WheelBackward() const;
  • /// get current absolute mouse position (in pixels)
  • const Math::float2& GetPixelPosition() const;
  • /// get current screen space mouse position (0.0 .. 1.0)
  • const Math::float2& GetScreenPosition() const;
  • /// get mouse movement
  • const Math::float2& GetMovement() const;
  • //Keyboard//
  • /// return true if a key is currently pressed
  • bool KeyPressed(Input::Key::Code keyCode) const;
  • /// return true if key was down at least once in current frame
  • bool KeyDown(Input::Key::Code keyCode) const;
  • /// return true if key was up at least once in current frame
  • bool KeyUp(Input::Key::Code keyCode) const;
  • /// get character input in current frame
  • const Util::String& GetCharInput() const;
  • GamePad先略過, 原理相同

    測試例子, 在上一次的代碼中添加一段:

  • void OnRenderFrame()
  • ??? {
  • if (this->inputServer->GetDefaultMouse()->ButtonDown(MouseButton::LeftButton))
  • ??????? {
  • ??????????? MessageBoxA(this->displayDevice->GetHwnd(), "Left Button Down", NULL, 0);
  • ??????? }
  • //...//
  • ??? }
  • 效果:

    轉載于:https://www.cnblogs.com/flying_bat/archive/2008/12/14/1354934.html

    總結

    以上是生活随笔為你收集整理的Nebula3的Input系统的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。