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