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 "SceneSerializer.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | // Listener class for frame updates
|
---|
30 | class PRMDemoFrameListener : public ExampleFrameListener
|
---|
31 | {
|
---|
32 | protected:
|
---|
33 |
|
---|
34 | unsigned long framecount;
|
---|
35 |
|
---|
36 | public:
|
---|
37 | PRMDemoFrameListener(RenderWindow* window, Camera* maincam)
|
---|
38 | :ExampleFrameListener(window, maincam)
|
---|
39 |
|
---|
40 | {
|
---|
41 | framecount = 0;
|
---|
42 | mMoveSpeed /= 50.0;
|
---|
43 | }
|
---|
44 |
|
---|
45 | bool frameStarted(const FrameEvent& evt)
|
---|
46 | {
|
---|
47 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
48 | framecount++;
|
---|
49 | return result;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | };
|
---|
55 |
|
---|
56 | /** Application class */
|
---|
57 | class PRMDemoApplication : public ExampleApplication
|
---|
58 | {
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | protected:
|
---|
64 | SceneNode* kupolaNode;
|
---|
65 | SceneNode* mainLightNode;
|
---|
66 |
|
---|
67 | void loadResources(void)
|
---|
68 | {
|
---|
69 | // Initialise, parse scripts etc
|
---|
70 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
71 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
72 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
73 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
74 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Demo");
|
---|
75 | }
|
---|
76 |
|
---|
77 | void createPostproc()
|
---|
78 | {
|
---|
79 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
80 | "GTP/PostProc/Glow");
|
---|
81 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
82 | "GTP/PostProc/Glow", true);
|
---|
83 |
|
---|
84 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
85 | "GTP/PostProc/ToneMap");
|
---|
86 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
87 | "GTP/PostProc/ToneMap", true);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void chooseSceneManager()
|
---|
91 | {
|
---|
92 | mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
93 | //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
94 | }
|
---|
95 |
|
---|
96 | void createScene(void)
|
---|
97 | {
|
---|
98 | //std::string occlusion_cfg("OcclusionCulling.cfg");
|
---|
99 | //mSceneMgr->setWorldGeometry(occlusion_cfg);
|
---|
100 |
|
---|
101 | //createPostproc();
|
---|
102 |
|
---|
103 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
104 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
105 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
106 | OgreIlluminationManager::getSingleton().setShadowMapMaterialName("GTP/Basic/DepthCCW");
|
---|
107 | OgreIlluminationManager::getSingleton().setFocusingSM(true);
|
---|
108 | OgreIlluminationManager::getSingleton().setShadowMapSize(700);
|
---|
109 | OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
|
---|
110 | OgreIlluminationManager::getSingleton().setUseLISPSM(true);
|
---|
111 |
|
---|
112 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
113 | mCamera->setPosition(0,0,0);
|
---|
114 | //mCamera->setPosition(0,100,0);
|
---|
115 | //mCamera->lookAt(0,-1,0);
|
---|
116 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
117 | mCamera->setNearClipDistance(0.01);
|
---|
118 | mCamera->setFarClipDistance(1000);
|
---|
119 | // Set ambient light
|
---|
120 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
121 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
|
---|
122 |
|
---|
123 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
124 |
|
---|
125 |
|
---|
126 | SceneSerializer s(mSceneMgr);
|
---|
127 | DataStreamPtr inputStream;
|
---|
128 | inputStream = ResourceGroupManager::getSingleton().openResource("towers2.level"); //towers2.level
|
---|
129 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
130 |
|
---|
131 | createPlane("p","GTP/Basic/ShadowReciever/Depth",Vector3(0,-0.3,0),Vector2(150,150));
|
---|
132 |
|
---|
133 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
134 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
135 | mainLight->setCastShadows(true);
|
---|
136 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
137 | mainLight->setSpecularColour(ColourValue::White);
|
---|
138 | mainLightNode = rootNode->createChildSceneNode();
|
---|
139 |
|
---|
140 | mainLightNode->setPosition(1000,1000,1000);
|
---|
141 | mainLight->setPosition(1000,1000,1000);
|
---|
142 | mainLight->setPowerScale(5);
|
---|
143 | mainLight->setDirection(-1,-1, -1);
|
---|
144 | mainLightNode->attachObject(mainLight);
|
---|
145 |
|
---|
146 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
147 | }
|
---|
148 |
|
---|
149 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
150 | Plane _plane;
|
---|
151 | _plane.normal = Vector3::UNIT_Y;
|
---|
152 | _plane.d = 0;
|
---|
153 |
|
---|
154 |
|
---|
155 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
156 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
157 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
158 |
|
---|
159 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
160 | _entity->setMaterialName(_material);
|
---|
161 |
|
---|
162 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
163 | _node->attachObject(_entity);
|
---|
164 | _node->setPosition(_pos);
|
---|
165 |
|
---|
166 | }
|
---|
167 |
|
---|
168 | void createFrameListener(void)
|
---|
169 | {
|
---|
170 | // This is where we instantiate our own frame listener
|
---|
171 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
172 | mCamera );
|
---|
173 | mFrameListener->setPriority(1);
|
---|
174 | mRoot->addFrameListener(mFrameListener);
|
---|
175 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
176 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
177 | }
|
---|
178 |
|
---|
179 | };
|
---|
180 |
|
---|