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 | }
|
---|
43 |
|
---|
44 | bool frameStarted(const FrameEvent& evt)
|
---|
45 | {
|
---|
46 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
47 | framecount++;
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | };
|
---|
54 |
|
---|
55 | /** Application class */
|
---|
56 | class PRMDemoApplication : public ExampleApplication
|
---|
57 | {
|
---|
58 |
|
---|
59 | public:
|
---|
60 | virtual void go(void)
|
---|
61 | {
|
---|
62 | if (!setup())
|
---|
63 | return;
|
---|
64 |
|
---|
65 | renderScene();
|
---|
66 |
|
---|
67 | // clean up
|
---|
68 | destroyScene();
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected:
|
---|
72 | SceneNode* kupolaNode;
|
---|
73 | SceneNode* mainLightNode;
|
---|
74 |
|
---|
75 | void renderScene(){
|
---|
76 |
|
---|
77 | mWindow->resetStatistics();
|
---|
78 | while(true){
|
---|
79 |
|
---|
80 |
|
---|
81 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
82 | // Pump events on Win32
|
---|
83 | MSG msg;
|
---|
84 | while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
|
---|
85 | {
|
---|
86 | TranslateMessage( &msg );
|
---|
87 | DispatchMessage( &msg );
|
---|
88 | }
|
---|
89 |
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | if(!mRoot->_fireFrameStarted()){
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | unsigned long framenum = mRoot->getCurrentFrameNumber();
|
---|
96 |
|
---|
97 | OgreIlluminationManager::getSingleton().update(framenum, mWindow);
|
---|
98 |
|
---|
99 | //mRoot->renderOneFrame();
|
---|
100 | mRoot->_updateAllRenderTargets();
|
---|
101 |
|
---|
102 | mRoot->_fireFrameEnded();
|
---|
103 |
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | void createPostproc()
|
---|
108 | {
|
---|
109 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
110 | "GameTools/Glow");
|
---|
111 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
112 | "GameTools/Glow", true);
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | void createScene(void)
|
---|
117 | {
|
---|
118 | //createPostproc();
|
---|
119 |
|
---|
120 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
121 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
122 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
123 |
|
---|
124 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
125 | mCamera->setPosition(0,20,40);
|
---|
126 | //mCamera->setPosition(0,100,0);
|
---|
127 | //mCamera->lookAt(0,-1,0);
|
---|
128 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
129 | //mCamera->setFarClipDistance(1000);
|
---|
130 | // Set ambient light
|
---|
131 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
132 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
133 |
|
---|
134 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
135 |
|
---|
136 | SceneSerializer s(mSceneMgr);
|
---|
137 | DataStreamPtr inputStream;
|
---|
138 | inputStream = ResourceGroupManager::getSingleton().openResource("level.txt");
|
---|
139 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
140 |
|
---|
141 | /* Entity* lepcso = mSceneMgr->createEntity("lepcso","stairs.mesh");
|
---|
142 | SceneNode* lNode = rootNode->createChildSceneNode("l");
|
---|
143 | lNode->attachObject(lepcso);*/
|
---|
144 |
|
---|
145 | createPlane("p","lambert1",Vector3(0,-20,0),Vector2(100,100));
|
---|
146 |
|
---|
147 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
148 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
149 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
150 | mainLight->setSpecularColour(ColourValue::White);
|
---|
151 | mainLightNode = rootNode->createChildSceneNode();
|
---|
152 |
|
---|
153 | mainLightNode->setPosition(0,0,0);
|
---|
154 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
155 | mainLight->setDirection(-1,-1, 0);
|
---|
156 | mainLightNode->attachObject(mainLight);
|
---|
157 |
|
---|
158 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
159 | }
|
---|
160 |
|
---|
161 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
162 | Plane _plane;
|
---|
163 | _plane.normal = Vector3::UNIT_Y;
|
---|
164 | _plane.d = 0;
|
---|
165 |
|
---|
166 |
|
---|
167 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
168 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
169 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
170 |
|
---|
171 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
172 | _entity->setMaterialName(_material);
|
---|
173 |
|
---|
174 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
175 | _node->attachObject(_entity);
|
---|
176 | _node->setPosition(_pos);
|
---|
177 |
|
---|
178 | }
|
---|
179 |
|
---|
180 | void createFrameListener(void)
|
---|
181 | {
|
---|
182 | // This is where we instantiate our own frame listener
|
---|
183 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
184 | mCamera );
|
---|
185 | mRoot->addFrameListener(mFrameListener);
|
---|
186 |
|
---|
187 | }
|
---|
188 |
|
---|
189 | };
|
---|
190 |
|
---|