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