免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Ogre嵌入MFC傻瓜完全教程(三)
經(jīng)過前兩兩篇博文的講解,我們已經(jīng)完成了渲染工作,但只是渲染而沒有交互性,本篇博文我們就來加上事件的處理方法。
首先我們需要為項(xiàng)目添加一個(gè)幀監(jiān)聽類:CMyFrameListener,為了直觀,在這直接貼上代碼
頭文件
[cpp] view plaincopy
#pragma once
#include "ogre.h"
#include "OgreConfigFile.h"
#include "OgreFrameListener.h"
#include "OgreStringConverter.h"
#include "OIS.h"
#include "MyOgreApp.h"
#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>
#include <SdkTrays.h>
#include <SdkCameraMan.h>
using namespace Ogre;
class CMyFrameListener: public FrameListener, public OIS::MouseListener,public Ogre::WindowEventListener, public OIS::KeyListener
{
public:
CMyFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr, Light* light);
~CMyFrameListener(void);
bool frameRenderingQueued(const Ogre::FrameEvent& evt);
bool mouseMoved(const OIS::MouseEvent &e);
bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
bool keyPressed(const OIS::KeyEvent &e);
bool keyReleased(const OIS::KeyEvent &e);
protected:
Ogre::SceneManager *mSceneMgr;//場(chǎng)景管理器
Ogre::SceneNode* mCamNode;//攝像機(jī)節(jié)點(diǎn)
Ogre::Camera* mCamera;//攝像機(jī)
Ogre::RenderWindow* mWindow;//渲染窗口
Ogre::Light* light;//燈光
OIS::Keyboard* mKeyboard;//鍵盤
OIS::Mouse* mMouse;      //鼠標(biāo)
OIS::InputManager* mInputManager;//輸入管理器
//  OgreBites::SdkTrayManager* mTrayMgr;
OgreBites::SdkCameraMan* mCameraMan;     // basic camera controller
bool mRBtdown;
};
源文件[cpp] view plaincopy
#include "StdAfx.h"
#include "MyFrameListener.h"
CMyFrameListener::CMyFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr, Light *l): mMouse(0),
mKeyboard(0), mInputManager(0), mWindow(win), mCamera(cam), light(l)
{
mRBtdown = false;
mCamNode=cam->getParentSceneNode();
mSceneMgr = sceneMgr;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
OIS::ParamList pl;
mCameraMan = new OgreBites::SdkCameraMan(mCamera);
windowHnd = (size_t )AfxGetMainWnd()->GetSafeHwnd(); // 這里這個(gè)窗口句柄就是傳入的MFC主窗口
windowHndStr << windowHnd;
// OIS的窗口必須要頂層窗口,所以只有傳MFC的主窗口給他,傳view就不行
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
// 設(shè)置鼠標(biāo)顯示和非游戲獨(dú)占,這樣鼠標(biāo)可以顯示在屏幕上并可以移動(dòng)到窗口外
pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
// 鍵盤非游戲獨(dú)占
pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
mInputManager = OIS::InputManager::createInputSystem(pl);
mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
}
CMyFrameListener::~CMyFrameListener(void)
{
mInputManager->destroyInputObject(mMouse);
mInputManager->destroyInputObject(mKeyboard);
OIS::InputManager::destroyInputSystem(mInputManager);
mInputManager = 0;
}
bool CMyFrameListener::frameRenderingQueued(const Ogre::FrameEvent& e){
mMouse->capture();
mKeyboard->capture();
mCameraMan->frameRenderingQueued(e);
return true;
}
bool CMyFrameListener::mouseMoved(const OIS::MouseEvent &e)
{
if (mRBtdown)
{
mCameraMan->injectMouseMove(e);
}
return true;
}
bool CMyFrameListener::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
//  mCameraMan->injectMouseDown(e, id);
if (id == OIS::MB_Right)
{
mRBtdown = true;
}
return true;
}
bool CMyFrameListener::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
//  mCameraMan->injectMouseUp(e, id);
if (id == OIS::MB_Right)
{
mRBtdown = false;
}
return true;
}
//鍵盤響應(yīng)
bool CMyFrameListener::keyPressed(const OIS::KeyEvent &e)
{
mCameraMan->injectKeyDown(e);
return true;
}
bool CMyFrameListener::keyReleased(const OIS::KeyEvent &e)
{
mCameraMan->injectKeyUp(e);
return true;
}
此類實(shí)現(xiàn)了對(duì)于鼠標(biāo)和鍵盤事件的監(jiān)聽與響應(yīng)。按住鼠標(biāo)右鍵拖動(dòng)可旋轉(zhuǎn)攝像機(jī)角度,WASD和方向鍵可移動(dòng)攝像機(jī)位置。里面的代碼都很簡(jiǎn)單,我就不再贅述了。下面修改CMyOgreApp類其能夠響應(yīng)鼠標(biāo)和鍵盤的事件。
1、首先在MyOgreApp.h中添加監(jiān)聽類的引用
[cpp] view plaincopy
#include "MyFrameListener.h"
2、聲明一個(gè)CMyFrameListener類的變量[cpp] view plaincopy
class CMyFrameListener* mListener;
3、聲明一個(gè)函數(shù) [cpp] view plaincopy
void createFrameListener(void);
4、在MyOgreApp.cpp文件中定義createFrameListener()[cpp] view plaincopy
void CMyOgreApp::createFrameListener(void)
{
mListener= new CMyFrameListener(mWindow, mCamera, mSceneMgr, light);
mRoot->addFrameListener(mListener);
}
5、在go() 函數(shù)中調(diào)用createFrameListener()[cpp] view plaincopy
bool CMyOgreApp::go(CRect rt, HWND hWnd)
{
createRoot();
setupResources();
setupRenderSystem();
createRenderWindow(hWnd, rt.Width(), rt.Height());
chooseSceneManager();
createCamera();
createViewport();
initializeResourceGroups();
createScene();
createFrameListener();//創(chuàng)建偵聽
return true;
}
生成并運(yùn)行,使用鼠標(biāo)和鍵盤就可以控制攝像機(jī)運(yùn)動(dòng)了。至此,整個(gè)工作就完成了,希望這幾篇文章能幫到還在受這個(gè)問題困擾的朋友。
PS:整個(gè)項(xiàng)目都在我上傳的資源中,配置好環(huán)境變量,再按照里面的說明簡(jiǎn)單配置下就能編譯運(yùn)行
Demo地址:http://download.csdn.net/detail/guoyk1990/7360731
原文:http://blog.csdn.net/guoyk1990/article/details/26060353
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Ogre中的攝像機(jī)
編程關(guān)鍵字個(gè)人百寶箱
C++操作符重載(“關(guān)系操作符”)
讀取NTFS的USN(快速檢索文件)
內(nèi)存池技術(shù)
判斷點(diǎn)是否在三角形內(nèi)的算法-收集備用
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服