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 | \file
|
---|
17 | Lighting.h
|
---|
18 | \brief
|
---|
19 | Shows lighting support in OGRE. Also demonstrates the use of billboards
|
---|
20 | and controllers for automatic time-relative behaviour.
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | #include "ExampleApplication.h"
|
---|
25 | #include "OgreIlluminationManager.h"
|
---|
26 | #include "SpriteParticleRenderer.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | int scene = 2;
|
---|
30 |
|
---|
31 | // Listener class for frame updates
|
---|
32 | class ParticleDemoFrameListener : public ExampleFrameListener
|
---|
33 | {
|
---|
34 | protected:
|
---|
35 |
|
---|
36 | SceneNode* lightNode;
|
---|
37 |
|
---|
38 | public:
|
---|
39 | ParticleDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode)
|
---|
40 | :ExampleFrameListener(window, maincam)
|
---|
41 |
|
---|
42 | {
|
---|
43 | this->lightNode = lightNode;
|
---|
44 | }
|
---|
45 |
|
---|
46 | bool frameStarted(const FrameEvent& evt)
|
---|
47 | {
|
---|
48 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
49 |
|
---|
50 | if(scene == 1)
|
---|
51 | {
|
---|
52 | Timer* timer = Root::getSingleton().getTimer();
|
---|
53 |
|
---|
54 | float t = (float) timer->getMilliseconds() / 2000.0;
|
---|
55 | float r = 150;
|
---|
56 | lightNode->setPosition( r * sin(t), r * sin(5 * t) + 200 , r * cos(t));
|
---|
57 | }
|
---|
58 | return result;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | };
|
---|
64 |
|
---|
65 | /** Application class */
|
---|
66 | class ParticleDemoApplication : public ExampleApplication
|
---|
67 | {
|
---|
68 |
|
---|
69 | public:
|
---|
70 |
|
---|
71 | protected:
|
---|
72 | SceneNode* kupolaNode;
|
---|
73 | SceneNode* mainLightNode;
|
---|
74 |
|
---|
75 | void createPostproc()
|
---|
76 | {
|
---|
77 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
78 | "GameTools/Glow");
|
---|
79 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
80 | "GameTools/Glow", true);
|
---|
81 | }
|
---|
82 |
|
---|
83 | virtual void chooseSceneManager(void)
|
---|
84 | {
|
---|
85 | if(scene == 1)
|
---|
86 | ExampleApplication::chooseSceneManager();
|
---|
87 | else if(scene == 2)
|
---|
88 | mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
|
---|
89 | }
|
---|
90 |
|
---|
91 | void createScene(void)
|
---|
92 | {
|
---|
93 | //createPostproc();
|
---|
94 |
|
---|
95 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
96 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
97 |
|
---|
98 |
|
---|
99 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
100 |
|
---|
101 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
102 | mCamera->setFarClipDistance(5000);
|
---|
103 | // Set ambient light
|
---|
104 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
105 |
|
---|
106 | // Skybox
|
---|
107 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 10);
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | // OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PHASE_TEXTURE);
|
---|
114 | // OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PHASE_TEXTURE, 1);
|
---|
115 | // OgreIlluminationManager::getSingleton().savePhaseTextureToFile("phase.dds");
|
---|
116 |
|
---|
117 |
|
---|
118 | if(scene == 1)
|
---|
119 | createScene1();
|
---|
120 | else if(scene == 2)
|
---|
121 | createScene2();
|
---|
122 |
|
---|
123 |
|
---|
124 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | void createScene1()
|
---|
129 | {
|
---|
130 | mCamera->setPosition(0,150,100);
|
---|
131 | mCamera->setDirection(0,0,-1);
|
---|
132 |
|
---|
133 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
134 |
|
---|
135 | Entity* head = mSceneMgr->createEntity("head", "athene.mesh");
|
---|
136 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
137 | head->setMaterialName("GameTools/Standard");
|
---|
138 | headNode->attachObject(head);
|
---|
139 | //headNode->setScale(1.5,1.5,1.5);
|
---|
140 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
141 | headNode->setPosition(0,80,20);
|
---|
142 | headNode->_updateBounds();
|
---|
143 |
|
---|
144 |
|
---|
145 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GameTools/Big");
|
---|
146 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
147 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
148 | pSysNode->attachObject(pSys1);
|
---|
149 | pSysNode->setPosition(0,0,0);
|
---|
150 |
|
---|
151 | //Init lights
|
---|
152 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
153 | mainLight->setType(Light::LT_POINT);
|
---|
154 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
155 | mainLight->setSpecularColour(ColourValue::White);
|
---|
156 | mainLightNode = rootNode->createChildSceneNode();
|
---|
157 | mainLightNode->setPosition(0,500,0);
|
---|
158 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
159 | mainLightNode->attachObject(mainLight);
|
---|
160 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
161 | bbs->createBillboard(Vector3::ZERO, ColourValue::White);
|
---|
162 | bbs->setMaterialName("Flare");
|
---|
163 | mainLightNode->attachObject(bbs);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void createScene2()
|
---|
167 | {
|
---|
168 | mCamera->setPosition(0,150,100);
|
---|
169 | mCamera->setDirection(0,0,-1);
|
---|
170 |
|
---|
171 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
172 | std::string terrain_cfg("terrain.cfg");
|
---|
173 | mSceneMgr -> setWorldGeometry( terrain_cfg );
|
---|
174 |
|
---|
175 | ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GameTools/FogBig");
|
---|
176 | pSys1->setKeepParticlesInLocalSpace(false);
|
---|
177 | SceneNode *pSysNode = rootNode->createChildSceneNode("psys1");
|
---|
178 | pSysNode->attachObject(pSys1);
|
---|
179 | pSysNode->setPosition(600,-50,600);
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 | void createFrameListener(void)
|
---|
184 | {
|
---|
185 | // This is where we instantiate our own frame listener
|
---|
186 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
187 | mCamera , mainLightNode);
|
---|
188 | mFrameListener->setPriority(1);
|
---|
189 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
190 | mRoot->addFrameListener(mFrameListener);
|
---|
191 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | };
|
---|
198 |
|
---|