#include "ExampleApplication.h" class TutorialFrameListener : public ExampleFrameListener { public: TutorialFrameListener( RenderWindow* win, Camera* cam, SceneManager *sceneMgr ) : ExampleFrameListener(win, cam, false, false) : mSceneMgr(sceneMgr) // it shoud now work { } bool frameStarted(const FrameEvent &evt) { using namespace OIS; mMouse->capture(); mKeyboard->capture(); if( mKeyboard->isKeyDown( KC_ESCAPE ) ) return false; bool currMouse = mMouse->getMouseState().buttonDown( MB_Left ); if ( currMouse && ! mMouseDown ) { Light *light = mSceneMgr->getLight( "Light1" ); light->setVisible( ! light->isVisible() ); mMouseDown = currMouse; } // if return true; } protected: bool mMouseDown; // Whether or not the left mouse button was down last frame Real mToggle; // The time left until next toggle 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 }; class TutorialApplication : public ExampleApplication { public: TutorialApplication() { } ~TutorialApplication() { } void createCamera(void) { // create camera, but leave at default position mCamera = mSceneMgr->createCamera("PlayerCam"); mCamera->setNearClipDistance(5); } protected: void createScene(void) { mSceneMgr->setAmbientLight( ColourValue( 0.25, 0.25, 0.25 ) ); Entity *ent = mSceneMgr->createEntity( "Ninja", "ninja.mesh" ); SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "NinjaNode" ); node->attachObject( ent ); 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 node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "CamNode1", Vector3( -400, 200, 400 ) ); // Make it look towards the ninja node->yaw( Degree(-45) ); // Create the pitch node node = node->createChildSceneNode( "PitchNode1" ); node->attachObject( mCamera ); // create the second camera node/pitch node node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "CamNode2", Vector3( 0, 200, 400 ) ); node = node->createChildSceneNode( "PitchNode2" ); } void createFrameListener(void) { // Create the FrameListener mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr); mRoot->addFrameListener(mFrameListener); // Show the frame stats overlay mFrameListener->showDebugOverlay(true); } }; #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 { // Create application object TutorialApplication app; try { app.go(); } catch( Exception& e ) { #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else fprintf(stderr, "An exception has occured: %s\n", e.getFullDescription().c_str()); #endif } return 0; }