Ogre筆記八 基礎教程五 緩衝輸入

2021-05-28 05:35:42 字數 2142 閱讀 5040

沒太多好說的,這一章要實現的目標跟上一章一樣,但是用到的方法相比較而言高階一點,我懶得解釋直接複製教程裡的。

緩衝輸入的介紹:

在上一次課裡,我們使用的是無緩衝的輸入,也就是說,在每一幀裡我們查詢ois::keyboard和ois::mouse例項的狀態,以判斷它們是否被按下。而緩衝輸入使用了乙個listener介面,以便在事件發生時通知你的程式。比如,當乙個鍵被按下時,會觸發乙個 keylistener::keypressed 事件,而當這個鍵被釋放(不再按下)時,keylistener::keyreleased 事件被觸發給所有已註冊的keylistener類。這些能用在追蹤按鍵的時間,或判斷按鍵在上一幀中是否沒有被按下。

通過ois::joysticklistener 介面,ois也支援無緩衝的操縱桿事件,但在本課我們不會涉及到。

鍵盤監聽介面

ois的keylistener介面提供了兩個純虛函式。第乙個是keypressed函式(每次按下某個鍵時呼叫它),還乙個是keyreleased(每次離開某個鍵時呼叫它)。傳入這些函式的引數是乙個keyevent,它包含被按下/釋放的按鍵的鍵碼。

滑鼠監聽介面

mouselistener介面比keylistener介面要稍微複雜一些。它包含檢視何時滑鼠鍵被按下/釋放的函式:

mouselistener::mousepressed 和 mouselistener::mousereleased. 它還包含乙個mousemoved函式,當滑鼠移動時呼叫它。這些函式都接收乙個mouseevent物件,在"state"變數裡儲存著當前滑鼠的狀態。需要注意的是,mousestate物件即包含了滑鼠移動的相對xy座標(即,從上一次呼叫mouselistener::mousemoved開始,它所移動的距離),還包含了絕對xy座標(即,螢幕上的準確位置)。

** :

class tutorialframelistener : public exampleframelistener, public ois::mouselistener, public

ois::keylistener

bool framestarted(const frameevent &evt)

//mouselistener

bool mousemoved(const ois::mouseevent &e)

return true;

} bool mousepressed(const ois::mouseevent &e, ois::mousebuttonid id)

return true;

} bool mousereleased(const ois::mouseevent &e, ois::mousebuttonid id)

// keylistener

bool keypressed(const ois::keyevent &e)

return true;

} bool keyreleased(const ois::keyevent &e)

return true;

}protected:

real mrotate; // 旋轉常量

real mmove; // 運動常量

scenemanager *mscenemgr; // 當前的場景管理器

scenenode *mcamnode; // 當前攝像機附著的場景節點

bool mcontinue; // 是否要繼續渲染

vector3 mdirection; // 指向正確的移動方向

}; void createscene(void)

void createframelistener(void) };

#if ogre_platform == platform_win32 || ogre_platform == ogre_platform_win32

#define win32_lean_and_mean

#include "windows.h"

int winapi winmain(hinstance hinst, hinstance, lpstr strcmdline, int)

#else

int main(int argc, char **argv)

#endif

catch(exception& e)

return 0;

}

python基礎教程學習筆記五

第五章 條件 迴圈和其他語句 print 和import 的更多資訊 使用逗號輸出 print age 32 age 32 兩條列印語句在同一行輸出 name retacn saluation mr.greeting hello print greeting,saluation,name hello...

NLTK基礎教程學習筆記(五)

import nltk from nltk import word tokenize s i was watching tv print nltk.pos tag word tokenize s 結果 i prp was vbd watching vbg tv nn 中先將文字進行表示化處理,再呼叫...

php基礎教程筆記

然後在網上找到乙個電子版的php基礎教程4,非常適合php新手學習,以下是我的學習筆記,記錄下來供以後參考。一 實現輸出hello world的幾種方法 print hello world print r hello world eval echo hello world echo可以一次輸出多個值...