| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | You may use this sample code for anything you like, it is not covered by the |
|---|
| 11 | LGPL like the rest of the engine. |
|---|
| 12 | ----------------------------------------------------------------------------- |
|---|
| 13 | */ |
|---|
| 14 | /* |
|---|
| 15 | ----------------------------------------------------------------------------- |
|---|
| 16 | Filename: ParticleApplication.cpp |
|---|
| 17 | Description: Specialisation of OGRE's framework application to show the |
|---|
| 18 | environment mapping feature. |
|---|
| 19 | ----------------------------------------------------------------------------- |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include "ExampleApplication.h" |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | // Event handler to add ability to alter curvature |
|---|
| 27 | class ParticleFrameListener : public ExampleFrameListener |
|---|
| 28 | { |
|---|
| 29 | protected: |
|---|
| 30 | SceneNode* mFountainNode; |
|---|
| 31 | public: |
|---|
| 32 | ParticleFrameListener(RenderWindow* win, Camera* cam, SceneNode* fountainNode) |
|---|
| 33 | : ExampleFrameListener(win, cam) |
|---|
| 34 | { |
|---|
| 35 | mFountainNode = fountainNode; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | bool frameStarted(const FrameEvent& evt) |
|---|
| 39 | { |
|---|
| 40 | if( ExampleFrameListener::frameStarted(evt) == false ) |
|---|
| 41 | return false; |
|---|
| 42 | // Rotate fountains |
|---|
| 43 | mFountainNode->yaw(Degree(evt.timeSinceLastFrame * 30)); |
|---|
| 44 | |
|---|
| 45 | // Call default |
|---|
| 46 | return true; |
|---|
| 47 | |
|---|
| 48 | } |
|---|
| 49 | }; |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | class ParticleApplication : public ExampleApplication |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | ParticleApplication() {} |
|---|
| 57 | |
|---|
| 58 | protected: |
|---|
| 59 | SceneNode* mFountainNode; |
|---|
| 60 | |
|---|
| 61 | // Just override the mandatory create scene method |
|---|
| 62 | void createScene(void) |
|---|
| 63 | { |
|---|
| 64 | // Set ambient light |
|---|
| 65 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
|---|
| 70 | |
|---|
| 71 | // Add entity to the root scene node |
|---|
| 72 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | // Green nimbus around Ogre |
|---|
| 76 | //mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject( |
|---|
| 77 | // mSceneMgr->createParticleSystem("Nimbus", "Examples/GreenyNimbus")); |
|---|
| 78 | |
|---|
| 79 | // Create some nice fireworks |
|---|
| 80 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject( |
|---|
| 81 | mSceneMgr->createParticleSystem("Fireworks", "Examples/Fireworks")); |
|---|
| 82 | |
|---|
| 83 | // Create shared node for 2 fountains |
|---|
| 84 | mFountainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
|---|
| 85 | |
|---|
| 86 | // fountain 1 |
|---|
| 87 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("fountain1", |
|---|
| 88 | "Examples/PurpleFountain"); |
|---|
| 89 | // Point the fountain at an angle |
|---|
| 90 | SceneNode* fNode = mFountainNode->createChildSceneNode(); |
|---|
| 91 | fNode->translate(200,-100,0); |
|---|
| 92 | fNode->rotate(Vector3::UNIT_Z, Degree(20)); |
|---|
| 93 | fNode->attachObject(pSys2); |
|---|
| 94 | |
|---|
| 95 | // fountain 2 |
|---|
| 96 | ParticleSystem* pSys3 = mSceneMgr->createParticleSystem("fountain2", |
|---|
| 97 | "Examples/PurpleFountain"); |
|---|
| 98 | // Point the fountain at an angle |
|---|
| 99 | fNode = mFountainNode->createChildSceneNode(); |
|---|
| 100 | fNode->translate(-200,-100,0); |
|---|
| 101 | fNode->rotate(Vector3::UNIT_Z, Degree(-20)); |
|---|
| 102 | fNode->attachObject(pSys3); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | // Create a rainstorm |
|---|
| 108 | ParticleSystem* pSys4 = mSceneMgr->createParticleSystem("rain", |
|---|
| 109 | "Examples/Rain"); |
|---|
| 110 | SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
|---|
| 111 | rNode->translate(0,1000,0); |
|---|
| 112 | rNode->attachObject(pSys4); |
|---|
| 113 | // Fast-forward the rain so it looks more natural |
|---|
| 114 | pSys4->fastForward(5); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | // Aureola around Ogre perpendicular to the ground |
|---|
| 118 | ParticleSystem* pSys5 = mSceneMgr->createParticleSystem("Aureola", |
|---|
| 119 | "Examples/Aureola"); |
|---|
| 120 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pSys5); |
|---|
| 121 | |
|---|
| 122 | // Set nonvisible timeout |
|---|
| 123 | ParticleSystem::setDefaultNonVisibleUpdateTimeout(5); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | // Create new frame listener |
|---|
| 127 | void createFrameListener(void) |
|---|
| 128 | { |
|---|
| 129 | mFrameListener= new ParticleFrameListener(mWindow, mCamera, mFountainNode); |
|---|
| 130 | mRoot->addFrameListener(mFrameListener); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | }; |
|---|
| 135 | |
|---|