[4] | 1 | #include "ExampleApplication.h" |
---|
| 2 | |
---|
| 3 | SceneNode *lightNode; |
---|
| 4 | |
---|
| 5 | class TutorialFrameListener : public ExampleFrameListener |
---|
| 6 | { |
---|
| 7 | public: |
---|
| 8 | TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr) |
---|
| 9 | : ExampleFrameListener(win, cam, false, false) |
---|
| 10 | { |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | bool frameStarted(const FrameEvent &evt) |
---|
| 14 | { |
---|
| 15 | lightNode->translate( Vector3(0, -10 * evt.timeSinceLastFrame, 0) ); |
---|
| 16 | |
---|
| 17 | return ExampleFrameListener::frameStarted(evt); |
---|
| 18 | } |
---|
| 19 | private: |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | class TutorialApplication : public ExampleApplication |
---|
| 24 | { |
---|
| 25 | protected: |
---|
| 26 | public: |
---|
| 27 | TutorialApplication() |
---|
| 28 | { |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | ~TutorialApplication() |
---|
| 32 | { |
---|
| 33 | } |
---|
| 34 | protected: |
---|
| 35 | void createCamera(void) |
---|
| 36 | { |
---|
| 37 | // create camera |
---|
| 38 | mCamera = mSceneMgr->createCamera("PlayerCam"); |
---|
| 39 | mCamera->setNearClipDistance(5); |
---|
| 40 | mCamera->setPosition(Vector3(0,10,500)); |
---|
| 41 | mCamera->lookAt(Vector3(0,0,0)); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void createScene(void) |
---|
| 45 | { |
---|
| 46 | // add tutorial code here |
---|
| 47 | mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) ); |
---|
| 48 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
| 49 | SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode", Vector3( 0, 0, 0 ) ); |
---|
| 50 | node->attachObject( head ); |
---|
| 51 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); |
---|
| 52 | |
---|
| 53 | Light *light = mSceneMgr->createLight("Light1"); |
---|
| 54 | light->setType(Light::LT_POINT); |
---|
| 55 | light->setPosition(Vector3(0, -100, 0)); |
---|
| 56 | light->setDiffuseColour(1.0, 0.0, 0.0); |
---|
| 57 | light->setSpecularColour(1.0, 0.0, 0.0); |
---|
| 58 | |
---|
| 59 | BillboardSet *bbs = mSceneMgr->createBillboardSet("bb", 1); |
---|
| 60 | bbs->createBillboard(Vector3::ZERO, ColourValue(1.0, 0.0, 0.0)); |
---|
| 61 | bbs->setMaterialName("Examples/Flare"); |
---|
| 62 | lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "LightNode", Vector3(0, 100, 0) ); |
---|
| 63 | lightNode->attachObject(bbs); |
---|
| 64 | lightNode->attachObject(light); |
---|
| 65 | light->setPosition(0.0, 0.0, 0.0); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void createFrameListener(void) |
---|
| 69 | { |
---|
| 70 | // create frame listener |
---|
| 71 | mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr); |
---|
| 72 | mRoot->addFrameListener(mFrameListener); |
---|
| 73 | } |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
| 77 | #define WIN32_LEAN_AND_MEAN |
---|
| 78 | #include "windows.h" |
---|
| 79 | |
---|
| 80 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) |
---|
| 81 | #else |
---|
| 82 | int main(int argc, char **argv) |
---|
| 83 | #endif |
---|
| 84 | { |
---|
| 85 | // Create application object |
---|
| 86 | TutorialApplication app; |
---|
| 87 | |
---|
| 88 | try { |
---|
| 89 | app.go(); |
---|
| 90 | } catch( Exception& e ) { |
---|
| 91 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
| 92 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
| 93 | #else |
---|
| 94 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
| 95 | e.getFullDescription().c_str()); |
---|
| 96 | #endif |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return 0; |
---|
| 100 | } |
---|