青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

清源游民  gameogre@gmail.com
在第一部分里分析了 ExampleFrameListener 大部內容,不過沒有窮盡,它其實也包含了輸入部分。因為 CEGUI 本身沒輸入偵測功能,他需要外部力量的幫助。在 ogre1.4 之間的 demo 中,輸入部分是 ogre 自帶的,功能有限(對于我這個菜鳥,暫時還用不到特別的功能 ^_^ )。新版本里,干脆把這部分去掉了,輸入部分采用了新的類庫 OIS - Object-oriented Input Library . 他的作者本身就是 OGRE team 的成員,我們可以相信,他可以與 Ogre 一起工作得很好 .OIS 支持鍵盤,鼠標,游戲桿,最后一項暫時不討論 . 在 windows 平臺下, OIS 提供了對 DirectInput 的封裝,基本的輸入功能是由后者來實現的。既然是學習,我們不防先大概理解一下 DirectInput 基本功能與使用流程以及 OIS 是如何將這些功能封裝進去的。我的目的是要討論 CEGUI 的,現在轉到了 OIS, 又轉到了 DirectxInput, 似乎是離目標越來越遠了。呵,在菜鳥的眼中,什么東西都是菜,都有營養,不防咀嚼個一下下。 CEGUI 固然是好東西,但是如果我們菜鳥整天只會學一堆堆沒完沒了的類庫,那么我們可能永遠就只是個菜鳥了,一句話,知道他做了些什么,比光知道他怎么用那可是相當有效!費話少說了,先看一下 DirectInput, 從 MSDN 上直接抄了一段, 懶得翻譯了: 下面第一段話,說了理解directInput需要了解的一些基本概念與術語,因為以前看過一點,大概知道是些什么。而我現在主要是做學習筆記,不是教程,所以不解釋了。
To understand DirectInput, it is essential to understand the following terms.?
DirectInput object: The root DirectInput interface. ·?Device: A keyboard, mouse, joystick, or other input device. ·? DirectInputDevice object: Code representing a keyboard, mouse, joystick, or other input device.·??
Device object: Code representing a key, button, trigger, and so on found on a DirectInput device object. Also called device object instance.
第二段話說明了使用 DirectInput 的基本步驟, OIS 把這些東西封裝起來了 .
The following steps represent a simple implementation of DirectInput in which the application takes responsibility for ascertaining what device object (button, axis, and so on) generated each item of data.

1.? Create the DirectInput object. You use methods of this object to enumerate devices and create DirectInput device objects.

2.? Enumerate devices. This is not an essential step if you intend to use only the system mouse or keyboard. To ascertain what other input devices are available on the user's system, have DirectInput enumerate them. Each time DirectInput finds a device that matches the criteria you set, it gives you the opportunity to examine the device's capabilities. It also retrieves a unique identifier that you can use to create a DirectInput device object representing the device.

3.? Create a DirectInputDevice object for each device you want to use. To do this, you need the unique identifier retrieved during enumeration. For the system mouse or keyboard, you can use a standard GUID.

4.? Set up the device. For each device, first set the cooperative level, which determines the way the device is shared with other applications or the system. You must also set the data format used for identifying device objects, such as buttons and axes, within data packets. If you intend to retrieve buffered data—that is, events rather than states—you also need to set a buffer size. Optionally, at this stage you can retrieve information about the device and tailor the application's behavior accordingly. You can also set properties such as the range of values returned by joystick axes.

5.? Acquire the device. At this stage you tell DirectInput that you are ready to receive data from the device.

6.? Retrieve data. At regular intervals, typically on each pass through the message loop or rendering loop, get either the current state of each device or a record of events that have taken place since the last retrieval. If you prefer, you can have DirectInput notify you whenever an event occurs.

7.? Act on the data. The application can respond either to the state of buttons and axes or to events such as a key being pressed or released.

8.? Close DirectInput. Before exiting, your application should unacquire all devices and release them, then release the DirectInput object.

了解了這些基本步驟,下面我們打開OIS的源碼,看看上面這8步驟封裝到了哪里。然后我們返回 ExampleFrameListener, 看看 demo 中是如何使用 OIS 的 .
第一個要看的是InputManager類。他提供了平臺無關的接口,負責輸入系統的創建。沒啥好說的,看源碼吧(只列出核心代碼):
InputManager * InputManager::createInputSystem( ParamList &paramList )
{????
???? ?InputManager* im = 0;
????? #elif defined OIS_WIN32_PLATFORM?
?????? ??? im = newWin32InputManager();
??? #endif?
?????? im->_initialize(paramList);?
??? return im;
}
自然,我們只關心windows平臺下的。于是找到源碼繼續看:
void Win32InputManager::_initialize( ParamList &paramList )
{?
? //Create the device?
?? hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&mDirectInput, NULL );
?? /Ok, now we have DirectInput, parse whatever extra settings were sent to us?
??? _parseConfigSettings( paramList );?
??? _enumerateDevices();
}

首先,完成了8步驟中的第1步, Create the DirectInput object 。 在_parseConfigSettings ( paramList ); 中對以后將要創建的設備(鍵盤,鼠標等)的屬性,例如獨占模式,前臺模式等。這些屬性列表paramList?? 經過處理后,之后在創建設備的時候傳入。
void Win32InputManager::_enumerateDevices()
{???? //Enumerate all attached devices?
??? mDirectInput->EnumDevices(NULL, _DIEnumKbdCallback, this, DIEDFL_ATTACHEDONLY);
}

完成了8步驟中的第2 部分 Enumerate devices ,它是針對游戲桿這類設計的,對于鍵盤,鼠標并不需要。InputManager 創建之后,就可以用它來創建鍵盤,鼠標了。它提供了如下的方法:
Object * Win32InputManager::createInputObject( TypeiType, boolbufferMode )
{???
? Object* obj = 0;???
??? switch( iType )?
??? {?
??? case OISKeyboard: obj = newWin32Keyboard( this, mDirectInput, bufferMode, kbSettings ); break;?
??? case OISMouse: obj = newWin32Mouse( this, mDirectInput, bufferMode, mouseSettings ); break;?
??? obj->_initialize();?
??? return obj;
}

鼠標,鍵盤都有各自的類封裝。下面以鍵盤為例,看看它的源碼中都做了些什么:
void Win32Keyboard::_initialize()
{

1????? mDirectInput->CreateDevice(GUID_SysKeyboard, &mKeyboard, NULL);

2????? mKeyboard->SetDataFormat(&c_dfDIKeyboard)

3????? HWNDhwin = ((Win32InputManager*)mCreator)->getWindowHandle();

4????? mKeyboard->SetCooperativeLevel( hwin, coopSetting)))

5????? mKeyboard ->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph )))

6????? HRESULThr = mKeyboard->Acquire();?

}

這里可是做了不少的工作,看看方法名就可以明白。為說明方便加上了標號。
1, 它做了8步驟中的第3步, Create a DirectInputDevice object for each device you want to use 。
2, 3 4,5它們共同做了8步驟中的第4步- Set up the device 。這里面包括:設置鍵盤的數據格式,協作模式,其他屬性。很明顯,6做了8 步步驟中的第5步- Acquire the device 。 意思是告訴DirectInput,我準備從設備上獲取數據了,給我做好生伺侯著。準備工作都做好了,可以獲取數據了,通過設備提供的下面這個方法來做這件事。這就是8 步驟中的第6件事- Retrieve data
void Win32Keyboard::capture()
{???? if( mBuffered )?
?????? _readBuffered();?
???? ? else?
?????? _read();
}

從源碼中我們可以看到,根據數據的不同,進行了不同的處理。呵,什么不同呢,再從MSDN上抄一段吧,一看就明白: Buffered and Immediate Data
DirectInput supplies two types of data: buffered and immediate. Buffered data is a record of events that are stored until an application retrieves them. Immediate data is a snapshot of the current state of a device. You might use immediate data in an application that is concerned only with the current state of a device - for example, a flight combat simulation that responds to the current position of the joystick and the state of one or more buttons. Buffered data might be the better choice where events are more important than states - for example, in an application that responds to movement of the mouse and button clicks. You can also use both types of data, as you might, for example, if you wanted to get immediate data for joystick axes but buffered data for the buttons.

呵,清楚了吧。繼續看代碼, capture()有兩個分枝,分別處理緩沖數據與立即數據。
首先是緩沖數據,主干代碼如下:
void Win32Keyboard::_readBuffered()
{
? DIDEVICEOBJECTDATA diBuff[KEYBOARD_DX_BUFFERSIZE];?
??? DWORD entries = KEYBOARD_DX_BUFFERSIZE;??
?? mKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );?
??? //Update keyboard and modifier states.. And, if listener, fire events?
??? for(unsignedinti = 0; i < entries; ++i )?
??? {?
?????? KeyCode kc = (KeyCode)diBuff[ i ].dwOfs;?
???????????????????? if( diBuff[ i ].dwData & 0x80 )?
?????? {?
?? ?????? if( listener )?
??????????? istener->keyPressed( KeyEvent( this,kc,_translateText(kc) ) );?
?????? }?
?????? else
?????? {?
?????????? //Fire off event?
?????????? if( listener )?
??????????? listener->keyReleased( KeyEvent( this, kc, 0 ) );?
?????? }?
??? }
}

這段代碼中,GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );取得了緩沖數據,添入了一個數組:尺寸是EYBOARD_DX_BUFFERSIZE,可以看到entries也等于此值。Entries的作用除了開始調用時說明數組的大小,同時在函數調用返回時說明數組里有多少個數據填入(沒有足夠多的緩沖數據,當然填不滿啦,假如entries返回6,說明還有6個按鍵信息在緩沖里等待處理)。很明顯,for循環就是對這些未處理的信息進行處理。KeyCode kc = (KeyCode)diBuff[ i ].dwOfs; 這是看看,這個事件是由哪個鍵引走.KeyCode是個枚舉型:
enum KeyCode?
??? {?
???  ? C_1?????????? = 0x02,?
?????? KC_2??????????? = 0x03,?
?????? KC_3??????????? = 0x04,?
?????? KC_A??????????? = 0x1E,?
?????? KC_S??????????? = 0x1F,?
?????? KC_D??????????? = 0x20,?
??? }

確定了是哪個鍵,接下來就要問了,是按下還是釋放?
?if ( diBuff[ i ].dwData & 0x80 )  回答了這個問題,下面做的是
if ( listener )?
??????????? istener->keyPressed( KeyEvent( this,kc,_translateText(kc) ) );

它把相關的信息內容包裝成KeyEvent,作為參數發給了,已經注冊了的偵聽者.可能不太明白,解釋一下:當我們按下了某個鍵,可以認為是發生了個KeyEvent,程序里會響應這個事件,方法就是把某個類實例注冊為偵聽者(listener),說白了就是告訴OIS,當鍵盤按下釋放的時候你告訴我啊,我要響應他。這里OIS檢測到按鍵事件發生了,根據偵聽者的請求,調用偵聽者的方法(keyPressed)。也許有疑問,OIS 怎么知道偵聽者實現了keypressed()方法呢?不急先看以下代碼,在GUI demo里:
class GuiFrameListener : publicExampleFrameListener, publicOIS::KeyListener, publicOIS::MouseListener
看到了吧,它繼承自? OIS:KeyListener ,從OIS的源碼中找到它:
class _OISExport KeyListener?
??? {?
??? public:?
?????? virtual ~KeyListener() {}?
?????? virtual bool keyPressed( constKeyEvent &arg ) = 0;?
?????? virtual bool keyReleased( constKeyEvent &arg ) = 0;????
??? };
哈哈,他正是定義了這兩個接口,既然繼承自他,當然也就擁有了這兩個接口,于是GuiFrameListener成了合理合法的Listener了。
哦,它在哪里注冊的呢?很簡單.在GuiFrameListener的構造函數里我們看到:
{
?????? mMouse ->setEventCallback(this);?
?????? mKeyboard->setEventCallback(this);
}
繼續挖源碼:
virtual void Keyboard : :setEventCallback ( KeyListener *keyListener ) {listener=keyListener;}
這下應該就明白了吧。很明顯GUI Demo里使用了緩沖模式.
剩下來就是立即模式的數據了,他很好理解:
void Win32Keyboard::_read()
{?
? mKeyboard->GetDeviceState( sizeof(KeyBuffer), &KeyBuffer );?
}
它把鍵盤當下的狀態保存到緩沖中去,要想知道哪個鍵是否按下,只要對照緩沖“按圖索驥”就可以了。
?bool Win32Keyboard::isKeyDown( KeyCodekey )
{?
??? return (KeyBuffer[key] & 0x80) != 0;
}
這個鍵按下了嗎?那個鍵按下了嗎?那那個呢?呵,真啰嗦,得一個個的問。
于是我們 GUI Demo 中可以看到下列的代碼:
virtual bool processUnbufferedKeyInput(const FrameEvent& evt)?
?????? {?

??????????? if(mKeyboard->isKeyDown(KC_A))?
???????????????????? ?mTranslateVector.x = -mMoveScale;??? // Move camera left?
??????????? if(mKeyboard->isKeyDown(KC_D))?
?????????????????? ?mTranslateVector.x = mMoveScale;????? // Move camera RIGHT?
????????????? if(mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) )?
???????????????????? mTranslateVector.z = -mMoveScale;???? // Move camera forward?
????????????? if(mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S) )??
??????? ??????????? mTranslateVector.z = mMoveScale;????? // Move camera backward

我們用鍵盤要不是緩沖模式,要么立即模式,不可能一起上,這所有在 demo 中都能看到, demo 的作者懶得多寫代碼 ( 嘿嘿 ) ,它繼承了 ExampleFrameListener 的許多功能,而 ExampleFrameListener 也實現了些立即模式的按鍵處理。 Demo 沒有用到。寫了這么多了,還得 8  大步驟?? 該第 7 步了吧: ―― Act on the data , 這有什么好說的呢?愛咋咋地!最后一步,第 8 步――天龍八部 ! 呵錯了,是 Close DirectInput????? 其實很簡單, OIS 把他們封裝在各個類的析構函數里了,想當然,源碼也不用貼了 . 說了 OIS  如何把 DirectInput 封裝起來,參考 8 大步驟,如何使用 OIS 也基本很明白了。OIS ,就學到這里,接下來該主角上場 CEGUI?得休息了,打字,翻資料,看代碼,很累了。


posted on 2007-03-02 15:27 清源游民 閱讀(3657) 評論(0)  編輯 收藏 引用 所屬分類: OGRE
<2007年3月>
25262728123
45678910
11121314151617
18192021222324
25262728293031
1234567

留言簿(35)

隨筆分類(78)

隨筆檔案(74)

文章檔案(5)

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            激情综合色综合久久| 欧美福利视频在线| 国产老肥熟一区二区三区| 午夜电影亚洲| 亚洲欧美另类在线| 国内精品伊人久久久久av一坑| 久久久99国产精品免费| 久久免费的精品国产v∧| 亚洲国产一区二区三区高清| 亚洲精品久久久久久一区二区| 欧美激情国产精品| 欧美一区二区成人6969| 久久国产乱子精品免费女| 亚洲国产精品www| 亚洲美女视频网| 国产欧美精品| 亚洲高清自拍| 国产精品麻豆va在线播放| 久久久久综合一区二区三区| 蜜桃av一区| 性做久久久久久久免费看| 欧美在线免费观看亚洲| 亚洲麻豆一区| 欧美一区二区三区视频在线| 亚洲精品欧美专区| 亚洲欧美国产毛片在线| 91久久在线播放| 亚洲免费在线观看| 91久久在线视频| 欧美一区网站| 亚洲深夜福利网站| 久久人人爽人人爽爽久久| 亚洲一卡久久| 欧美va亚洲va日韩∨a综合色| 亚洲一区二区成人在线观看| 噜噜噜久久亚洲精品国产品小说| 午夜精品久久久久久久99樱桃| 老司机午夜精品视频| 欧美亚洲日本网站| 欧美日韩国产综合一区二区| 蜜臀av一级做a爰片久久| 国产精品久久亚洲7777| 亚洲国产日韩欧美一区二区三区| 国产一区日韩一区| 亚洲视频1区2区| 日韩一区二区免费看| 久久久国产一区二区| 午夜精品视频在线观看一区二区 | 亚洲一区二区在线播放| 麻豆成人在线播放| 久久亚洲一区二区| 国产亚洲第一区| 亚洲一区二区三区四区五区午夜 | 久久色中文字幕| 国产伦精品一区二区三区四区免费 | 亚洲一区二区三区激情| 欧美成人一品| 亚洲成色最大综合在线| 在线观看日韩| 久久久国产午夜精品| 久久久久久色| 韩国三级在线一区| 欧美在线三区| 久久夜色精品亚洲噜噜国产mv| 国产欧美一区视频| 欧美一区在线直播| 久久久噜噜噜| 亚洲成色777777女色窝| 久久午夜精品一区二区| 亚洲大片在线| 亚洲黑丝在线| 欧美激情一区二区在线| 亚洲精品久久久蜜桃| 中国成人亚色综合网站| 亚洲视频导航| 国产精品免费看久久久香蕉| 久久精品二区亚洲w码| 国产一区二区三区最好精华液| 在线精品视频一区二区| 亚洲永久免费观看| 国产精品久久久久久久久久直播| 亚洲二区免费| 亚洲福利在线观看| 亚洲精品中文在线| 欧美精品激情在线观看| 夜夜精品视频一区二区| 亚洲欧美国产毛片在线| 国产欧美日韩精品丝袜高跟鞋| 欧美在线free| 欧美福利电影在线观看| 中日韩午夜理伦电影免费| 国产精品入口日韩视频大尺度| 午夜免费久久久久| 亚洲盗摄视频| 欧美亚洲日本国产| 91久久亚洲| 国产欧美精品久久| 欧美成人午夜免费视在线看片| 亚洲美女黄色片| 久久久国产精品一区| 99国产一区| 精品51国产黑色丝袜高跟鞋| 欧美激情亚洲自拍| 欧美亚洲午夜视频在线观看| 亚洲国产精品成人一区二区| 西西人体一区二区| 亚洲乱码久久| 在线观看成人小视频| 国产精品极品美女粉嫩高清在线 | 欧美成人午夜77777| 亚洲欧美日本视频在线观看| 亚洲级视频在线观看免费1级| 欧美亚洲第一页| 农村妇女精品| 久久成人综合视频| 一本久久综合亚洲鲁鲁五月天| 美日韩精品免费| 欧美在线综合视频| 日韩午夜精品视频| 亚洲国产高清aⅴ视频| 国产麻豆综合| 国产精品美女| 欧美日韩久久不卡| 免费永久网站黄欧美| 欧美中文在线视频| 先锋影音国产精品| 中文一区在线| av成人免费在线观看| 亚洲欧洲久久| 亚洲二区在线| 欧美国产激情| 欧美好骚综合网| 免费成人av在线看| 鲁大师影院一区二区三区| 久久久久久免费| 久久久久国产成人精品亚洲午夜| 午夜精品久久久久久99热软件| 亚洲午夜视频在线观看| 在线一区观看| 亚洲一区二区三区乱码aⅴ| 99pao成人国产永久免费视频| 亚洲国产精品一区二区第四页av | 欧美少妇一区| 欧美日在线观看| 欧美午夜三级| 国产精品入口福利| 国产一级精品aaaaa看| 国产一区日韩一区| 亚洲第一视频网站| 亚洲国产日韩欧美一区二区三区| 在线播放日韩| 亚洲精品影视在线观看| 一本色道久久综合亚洲精品高清| 亚洲免费av网站| 亚洲一区二区黄| 性一交一乱一区二区洋洋av| 久久精品日产第一区二区| 狂野欧美激情性xxxx| 欧美夫妇交换俱乐部在线观看| 欧美国产日本韩| 99国产精品久久久久久久成人热| 一区二区电影免费观看| 午夜视频在线观看一区| 久久九九99视频| 欧美激情精品久久久| 国产精品成人一区二区三区吃奶 | 国产精品日韩在线播放| 国产自产v一区二区三区c| 亚洲国产美国国产综合一区二区| 亚洲精品老司机| 羞羞色国产精品| 欧美激情女人20p| 一区二区电影免费观看| 久久久国产一区二区三区| 欧美日本三区| 国产一区二区三区四区| 日韩一区二区精品| 久久久久国产精品厨房| 亚洲欧洲另类国产综合| 亚洲欧美日韩综合| 女女同性精品视频| 国产女人aaa级久久久级| 亚洲国产精品久久久久久女王| 亚洲一区欧美一区| 欧美韩日亚洲| 亚洲欧美国产高清| 欧美日韩高清不卡| 国语自产偷拍精品视频偷| 亚洲午夜一区二区三区| 欧美成年网站| 午夜亚洲性色视频| 欧美日韩亚洲一区二区三区在线| 国产一区二区按摩在线观看| 一级日韩一区在线观看| 欧美aⅴ一区二区三区视频| 一本色道久久综合亚洲91| 看欧美日韩国产| 国产区在线观看成人精品| 一本大道久久精品懂色aⅴ| 美女精品自拍一二三四|