Előadást letölteni
Az előadás letöltése folymat van. Kérjük, várjon
KiadtaEtelka Halászné Megváltozta több, mint 10 éve
1
OIS
2
Kezdeti teendők Letöltés: OgreLabControllersBase.zip Kicsomagol, betölt:.sln Additional include és library path beállítása Working directory beállítása Fordít futtat
4
OIS #include "stdafx.h" #include "Ogre.h" #define OIS_DYNAMIC_LIB #include using namespace Ogre; Root* ogreRoot; SceneManager* sceneManager; Camera* camera; RenderWindow* renderWindow; OIS::InputManager* OISInputManager;
5
class ControlDeviceHandler : public FrameListener { protected: OIS::Keyboard* mKeyboard; float mTimeUntilNextToggle; public: ControlDeviceHandler() { LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHnd = 0; renderWindow->getCustomAttribute("WINDOW", &windowHnd); std::ostringstream windowHndStr; windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); OISInputManager = OIS::InputManager::createInputSystem( pl ); mKeyboard = static_cast (OISInputManager->createInputObject( OIS::OISKeyboard, false )); } };
6
void setupListeners() { ogreRoot->addFrameListener(new ControlDeviceHandler()); } Másolás: OgeSdk/bin/release/OIS.lib -> bin Másolás: OgeSdk/bin/debug/OIS_d.lib -> bin OIS_d.lib
7
Próba
8
class ControlDeviceHandler : public FrameListener { … public: … bool frameStarted(const FrameEvent& evt) { mKeyboard->capture(); if( mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; if( mKeyboard->isKeyDown(OIS::KC_UP)) LogManager::getSingleton().logMessage("up arrow pressed"); if( mKeyboard->isKeyDown(OIS::KC_DOWN)) LogManager::getSingleton().logMessage("down arrow pressed"); if( mKeyboard->isKeyDown(OIS::KC_SPACE)) LogManager::getSingleton().logMessage("space pressed"); return true; } };
9
Próba
10
bool frameStarted(const FrameEvent& evt) { mKeyboard->capture(); if (mTimeUntilNextToggle >= 0) mTimeUntilNextToggle -= evt.timeSinceLastFrame; … if( mKeyboard->isKeyDown(OIS::KC_SPACE) && mTimeUntilNextToggle < 0) { LogManager::getSingleton().logMessage("space pressed"); mTimeUntilNextToggle = 0.2f; } Próba
11
bool frameStarted(const FrameEvent& evt) { float cameraMoveSpeed = 50.0f * evt.timeSinceLastFrame; Vector3 campos = camera->getPosition(); Vector3 camdir = camera->getDirection(); Vector3 cammove(0,0,0); … if( mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) cammove += camdir; if( mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) cammove -= camdir; camera->setPosition(campos + cammove * cameraMoveSpeed);
12
Próba Önálló feladat: Slide (A, D gombok) Föl-le mozgás (Q, E gombok) (cammove legyen egységvektor!)
13
Megoldás: Vector3 camright = camera->getRight(); Vector3 camup = camera->getUp(); … if( mKeyboard->isKeyDown(OIS::KC_A)) cammove -= camright; if( mKeyboard->isKeyDown(OIS::KC_D)) cammove += camright; if( mKeyboard->isKeyDown(OIS::KC_Q)) cammove += camup; if( mKeyboard->isKeyDown(OIS::KC_E)) cammove -= camup; cammove.normalise(); camera->setPosition(campos + cammove * cameraMoveSpeed);
14
Fordulás bool frameStarted(const FrameEvent& evt) { float cameraMoveSpeed = 50.0f * evt.timeSinceLastFrame; float cameraRotateSpeed = 50.0f * evt.timeSinceLastFrame; … if( mKeyboard->isKeyDown(OIS::KC_LEFT)) camera->rotate(Vector3::UNIT_Y, Radian(cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_RIGHT)) camera->rotate(Vector3::UNIT_Y, Radian(-cameraRotateSpeed * 0.02f)); Önálló feladat: fel-le nézés (PageUp-PageDown)
15
if( mKeyboard->isKeyDown(OIS::KC_LEFT)) camera->rotate(Vector3::UNIT_Y,Radian(cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_RIGHT)) camera->rotate(Vector3::UNIT_Y, Radian(-cameraRotateSpeed * 0.02f)); camright = camera->getRight(); if( mKeyboard->isKeyDown(OIS::KC_PGUP)) camera->rotate(camright, Radian(cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_PGDOWN)) camera->rotate(camright, Radian(-cameraRotateSpeed * 0.02f)); /* if( mKeyboard->isKeyDown(OIS::KC_LEFT)) camera->yaw(Radian(cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_RIGHT)) camera->yaw(Radian(-cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_PGUP)) camera->pitch(Radian(cameraRotateSpeed * 0.02f)); if( mKeyboard->isKeyDown(OIS::KC_PGDOWN)) camera->pitch(Radian(-cameraRotateSpeed * 0.02f));*/
16
Próba
17
protected: OIS::Keyboard* mKeyboard; OIS::Mouse* mMouse; … ControlDeviceHandler() { … mKeyboard = static_cast (OISInputManager->createInputObject( OIS::OISKeyboard, false )); mMouse = static_cast (OISInputManager->createInputObject( OIS::OISMouse, false )); }
18
bool frameStarted(const FrameEvent& evt) { float mousesensitivity = 1.0f; … mMouse->capture(); const OIS::MouseState &ms = mMouse->getMouseState(); LogManager::getSingleton().logMessage( StringConverter::toString(ms.X.rel) + " " + StringConverter::toString(ms.Y.rel)); return true; } Próba
19
Kamera forgatás mMouse->capture(); const OIS::MouseState &ms = mMouse->getMouseState(); camera->yaw(Radian(-cameraRotateSpeed * mousesensitivity * ms.X.rel * 0.01f)); camera->pitch(Radian(-cameraRotateSpeed * mousesensitivity * ms.Y.rel * 0.01f));
20
Próba
21
Egér gomb if(ms.buttonDown(OIS::MB_Left)) LogManager::getSingleton().logMessage("left button down"); Önálló feladat: Slide az egérrel fordulás helyett ha a jobb gomb le van nyomva
22
Megoldás if(ms.buttonDown(OIS::MB_Right)) { cammove += camright * ms.X.rel * 0.01f; cammove += camup * ms.Y.rel * 0.01f; } else { camera->yaw(Radian(-cameraRotateSpeed * mousesensitivity * ms.X.rel * 0.01f)); camera->pitch(Radian(-cameraRotateSpeed * mousesensitivity * ms.Y.rel * 0.01f)); }
23
Vége
Hasonló előadás
© 2024 SlidePlayer.hu Inc.
All rights reserved.