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-2005 The OGRE Team
|
---|
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 |
|
---|
41 | // Rotate fountains
|
---|
42 | mFountainNode->yaw(Degree(evt.timeSinceLastFrame * 30));
|
---|
43 |
|
---|
44 | // Call default
|
---|
45 | return ExampleFrameListener::frameStarted(evt);
|
---|
46 |
|
---|
47 | }
|
---|
48 | };
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 | class ParticleApplication : public ExampleApplication
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | ParticleApplication() {}
|
---|
56 |
|
---|
57 | protected:
|
---|
58 | SceneNode* mFountainNode;
|
---|
59 |
|
---|
60 | // Just override the mandatory create scene method
|
---|
61 | void createScene(void)
|
---|
62 | {
|
---|
63 | // Set ambient light
|
---|
64 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
69 |
|
---|
70 | // Add entity to the root scene node
|
---|
71 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
72 |
|
---|
73 |
|
---|
74 | // Green nimbus around Ogre
|
---|
75 | ParticleSystem* pSys1 = ParticleSystemManager::getSingleton().createSystem("Nimbus",
|
---|
76 | "Examples/GreenyNimbus");
|
---|
77 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pSys1);
|
---|
78 |
|
---|
79 |
|
---|
80 | // Create shared node for 2 fountains
|
---|
81 | mFountainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
82 |
|
---|
83 | // fountain 1
|
---|
84 | ParticleSystem* pSys2 = ParticleSystemManager::getSingleton().createSystem("fountain1",
|
---|
85 | "Examples/PurpleFountain");
|
---|
86 | // Point the fountain at an angle
|
---|
87 | SceneNode* fNode = mFountainNode->createChildSceneNode();
|
---|
88 | fNode->translate(200,-100,0);
|
---|
89 | fNode->rotate(Vector3::UNIT_Z, Degree(20));
|
---|
90 | fNode->attachObject(pSys2);
|
---|
91 |
|
---|
92 | // fountain 2
|
---|
93 | ParticleSystem* pSys3 = ParticleSystemManager::getSingleton().createSystem("fountain2",
|
---|
94 | "Examples/PurpleFountain");
|
---|
95 | // Point the fountain at an angle
|
---|
96 | fNode = mFountainNode->createChildSceneNode();
|
---|
97 | fNode->translate(-200,-100,0);
|
---|
98 | fNode->rotate(Vector3::UNIT_Z, Degree(-20));
|
---|
99 | fNode->attachObject(pSys3);
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 | // Create a rainstorm
|
---|
105 | ParticleSystem* pSys4 = ParticleSystemManager::getSingleton().createSystem("rain",
|
---|
106 | "Examples/Rain");
|
---|
107 | SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
108 | rNode->translate(0,1000,0);
|
---|
109 | rNode->attachObject(pSys4);
|
---|
110 | // Fast-forward the rain so it looks more natural
|
---|
111 | pSys4->fastForward(5);
|
---|
112 |
|
---|
113 |
|
---|
114 | }
|
---|
115 |
|
---|
116 | // Create new frame listener
|
---|
117 | void createFrameListener(void)
|
---|
118 | {
|
---|
119 | mFrameListener= new ParticleFrameListener(mWindow, mCamera, mFountainNode);
|
---|
120 | mRoot->addFrameListener(mFrameListener);
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | };
|
---|
125 |
|
---|