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 /= 5.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("OcclusionCullingSceneManager");
|
---|
93 | }
|
---|
94 |
|
---|
95 | void createScene(void)
|
---|
96 | {
|
---|
97 | //createPostproc();
|
---|
98 |
|
---|
99 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
100 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
101 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
102 |
|
---|
103 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
104 | mCamera->setPosition(0,20,40);
|
---|
105 | //mCamera->setPosition(0,100,0);
|
---|
106 | //mCamera->lookAt(0,-1,0);
|
---|
107 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
108 | //mCamera->setFarClipDistance(1000);
|
---|
109 | // Set ambient light
|
---|
110 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
111 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
|
---|
112 |
|
---|
113 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
114 |
|
---|
115 | /*
|
---|
116 | SceneSerializer s(mSceneMgr);
|
---|
117 | DataStreamPtr inputStream;
|
---|
118 | inputStream = ResourceGroupManager::getSingleton().openResource("level.txt");
|
---|
119 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
120 | */
|
---|
121 | Entity* tower = mSceneMgr->createEntity("tower","tower.mesh");
|
---|
122 | SceneNode* tNode = rootNode->createChildSceneNode("tower");
|
---|
123 | tNode->setScale(10,10,10);
|
---|
124 | tNode->attachObject(tower);
|
---|
125 |
|
---|
126 | /* Entity* lepcso = mSceneMgr->createEntity("lepcso","stairs.mesh");
|
---|
127 | SceneNode* lNode = rootNode->createChildSceneNode("l");
|
---|
128 | lNode->attachObject(lepcso);*/
|
---|
129 |
|
---|
130 | //createPlane("p","lambert1",Vector3(0,-20,0),Vector2(100,100));
|
---|
131 |
|
---|
132 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
133 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
134 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
135 | mainLight->setSpecularColour(ColourValue::White);
|
---|
136 | mainLightNode = rootNode->createChildSceneNode();
|
---|
137 |
|
---|
138 | mainLightNode->setPosition(10,10,0);
|
---|
139 | mainLight->setPosition(10,10,0);
|
---|
140 | mainLight->setPowerScale(5);
|
---|
141 | mainLight->setDirection(-1,-1, -1);
|
---|
142 | mainLightNode->attachObject(mainLight);
|
---|
143 |
|
---|
144 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
145 | }
|
---|
146 |
|
---|
147 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
148 | Plane _plane;
|
---|
149 | _plane.normal = Vector3::UNIT_Y;
|
---|
150 | _plane.d = 0;
|
---|
151 |
|
---|
152 |
|
---|
153 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
154 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
155 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
156 |
|
---|
157 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
158 | _entity->setMaterialName(_material);
|
---|
159 |
|
---|
160 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
161 | _node->attachObject(_entity);
|
---|
162 | _node->setPosition(_pos);
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | void createFrameListener(void)
|
---|
167 | {
|
---|
168 | // This is where we instantiate our own frame listener
|
---|
169 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
170 | mCamera );
|
---|
171 | mFrameListener->setPriority(1);
|
---|
172 | mRoot->addFrameListener(mFrameListener);
|
---|
173 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
174 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
175 | }
|
---|
176 |
|
---|
177 | };
|
---|
178 |
|
---|