Sixth Demo of OGRE---Buffer Input

#include "ExampleApplication.h" class TutorialFrameListener : public ExampleFrameListener, public OIS::MouseListener, public OIS::KeyListener { public: TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr) : ExampleFrameListener(win, cam, true, true) { // Populate the camera and scene manager containers mCamNode = cam->getParentSceneNode(); mSceneMgr = sceneMgr; //set speed of rotate and move mRotate = 0.13; mMove = 250; // continue to rander mContinue = true; mMouse->setEventCallback(this); mKeyboard->setEventCallback(this); mDirection = Vector3::ZERO; } bool frameStarted(const FrameEvent &evt) { if(mMouse) { mMouse->capture(); } if(mKeyboard) { mKeyboard->capture(); } mCamNode->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL); return mContinue; } // MouseListener bool mouseMoved(const OIS::MouseEvent &e) { return true; } bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { Light *light = mSceneMgr->getLight("Light1"); switch (id) { case OIS::MB_Left: light->setVisible(! light->isVisible()); return true; break; } if (e.state.buttonDown(OIS::MB_Right)) { mCamNode->yaw(Degree(-mRotate * e.state.X.rel), Node::TS_WORLD); mCamNode->pitch(Degree(-mRotate * e.state.Y.rel), Node::TS_LOCAL); return true; } return true; } bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } // KeyListener bool keyPressed(const OIS::KeyEvent &e) { switch(e.key) { case OIS::KC_ESCAPE: { mContinue = false; } break; case OIS::KC_1: { mCamera->getParentSceneNode()->detachObject(mCamera); mCamNode = mSceneMgr->getSceneNode("CamNode1"); mCamNode->attachObject(mCamera); } break; case OIS::KC_2: { mCamera->getParentSceneNode()->detachObject(mCamera); mCamNode = mSceneMgr->getSceneNode("CamNode2"); mCamNode->attachObject(mCamera); } break; case OIS::KC_UP: case OIS::KC_W: { mDirection.z -= mMove; } break; case OIS::KC_DOWN: case OIS::KC_S: { mDirection.z += mMove; } break; case OIS::KC_LEFT: case OIS::KC_A: { mDirection.x -= mMove; } break; case OIS::KC_RIGHT: case OIS::KC_D: { mDirection.x += mMove; } break; case OIS::KC_PGDOWN: case OIS::KC_E: { mDirection.y -= mMove; } break; case OIS::KC_PGUP: case OIS::KC_Q: { mDirection.y += mMove; } break; } return true; } bool keyReleased(const OIS::KeyEvent &e) { switch (e.key) { case OIS::KC_UP: case OIS::KC_W: mDirection.z += mMove; break; case OIS::KC_DOWN: case OIS::KC_S: mDirection.z -= mMove; break; case OIS::KC_LEFT: case OIS::KC_A: mDirection.x += mMove; break; case OIS::KC_RIGHT: case OIS::KC_D: mDirection.x -= mMove; break; case OIS::KC_PGDOWN: case OIS::KC_E: mDirection.y += mMove; break; case OIS::KC_PGUP: case OIS::KC_Q: mDirection.y -= mMove; break; } // switch return true; } protected: Real mRotate; // The rotate constant Real mMove; // The movement constant SceneManager *mSceneMgr; // The current SceneManager SceneNode *mCamNode; // The SceneNode the camera is currently attached to bool mContinue; // Whether to continue rendering or not Vector3 mDirection; // Value to move in the correct direction }; class FameApplication : public ExampleApplication { public: FameApplication(); ~FameApplication(); //Just override the mandatory create scene method void createScene(void); void createFrameListener(void); void createCamera(void); void destroyScene(void); }; FameApplication::FameApplication() { } FameApplication::~FameApplication() { } void FameApplication::createScene() { //set ambient light mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25)); //create a entiry Entity* pEntity = mSceneMgr->createEntity("Ninja", "ninja.mesh"); //create a sence node SceneNode* pSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode"); pSceneNode->attachObject(pEntity); Light *light = mSceneMgr->createLight("Light1"); light->setType(Light::LT_POINT); light->setPosition(Vector3(250, 150, 250)); light->setDiffuseColour(ColourValue::White); light->setSpecularColour(ColourValue::White); // Create the scene node pSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-400, 200, 400)); // Make it look towards the ninja pSceneNode->yaw(Degree(-45)); // Create the pitch node pSceneNode = pSceneNode->createChildSceneNode("PitchNode1"); pSceneNode->attachObject(mCamera); // create the second camera/pitch node pSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode2", Vector3(0, 200, 400)); pSceneNode = pSceneNode->createChildSceneNode("PitchNode2"); } void FameApplication::createFrameListener(void) { // Create the FrameListener mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr); mRoot->addFrameListener(mFrameListener); // Show the frame stats overlay mFrameListener->showDebugOverlay(true); } void FameApplication::createCamera(void) { // create camera, but leave at default position mCamera = mSceneMgr->createCamera("PlayerCam"); mCamera->setNearClipDistance(5); } void FameApplication::destroyScene() { } INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) { // Create application object FameApplication app; try { app.go(); } catch( Ogre::Exception& e ) { MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); } return 0; } 

 

你可能感兴趣的:(exception,vector,application,input,CAM,winapi)