source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreDemos/src/PRMDemo/include/PRMDemo.h @ 3255

Revision 3255, 7.6 KB checked in by szirmay, 15 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL 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
28Light* blueLight;
29
30// Listener class for frame updates
31class PRMDemoFrameListener : public ExampleFrameListener
32{
33protected:
34       
35        unsigned long framecount;
36        SceneNode* mainLightNode;
37        Light* light;
38       
39public:
40    PRMDemoFrameListener(RenderWindow* window, Camera* maincam, SceneNode* lightNode, Light* l)
41        :ExampleFrameListener(window, maincam)
42                                 
43    {
44                mainLightNode = lightNode;
45                light = l;
46                framecount = 0;
47                mMoveSpeed /= 50.0;
48    }
49
50    bool frameStarted(const FrameEvent& evt)
51    {   
52        /*      light->setDirection(mCamera->getDirection());
53                light->setPosition(mCamera->getPosition());
54                mainLightNode->setPosition(mCamera->getPosition());*/
55                bool result = ExampleFrameListener::frameStarted(evt);
56       framecount++;
57
58           static float t = 0;
59           float dt = evt.timeSinceLastFrame / 4.0;
60           t += dt;
61/*
62           Vector3 pos(30 * sin(t), 1, 30 * cos(t));
63           light->getParentSceneNode()->setPosition(pos);
64           Vector3 dir = -pos;
65           dir.normalise();
66           light->setDirection(dir);*/
67         
68         
69        return result;     
70    }
71
72       
73
74};
75
76/** Application class */
77class PRMDemoApplication : public ExampleApplication
78{
79
80
81
82
83protected:
84        SceneNode* kupolaNode;
85        SceneNode* mainLightNode;
86        Light* mainLight;
87        void setupResources(void)
88    {
89        // Load resource paths from config file
90        ConfigFile cf;
91        cf.load("resources_pmdemo.cfg");
92
93        // Go through all sections & settings in the file
94        ConfigFile::SectionIterator seci = cf.getSectionIterator();
95
96        String secName, typeName, archName;
97        while (seci.hasMoreElements())
98        {
99            secName = seci.peekNextKey();
100            ConfigFile::SettingsMultiMap *settings = seci.getNext();
101            ConfigFile::SettingsMultiMap::iterator i;
102            for (i = settings->begin(); i != settings->end(); ++i)
103            {
104                typeName = i->first;
105                archName = i->second;
106                ResourceGroupManager::getSingleton().addResourceLocation(
107                    archName, typeName, secName);
108            }
109        }
110    }
111
112        void loadResources(void)
113        {
114                // Initialise, parse scripts etc
115                ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
116                ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
117                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
118                ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
119                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMap");
120                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_PathMapDemo");
121        }
122
123       
124
125        void createScene(void) ///PATHMAP Hangar
126        {               
127                OgreIlluminationManager::getSingleton().joinSharedRuns(false);
128                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
129                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
130                OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_SPOTLIGHT, "GTP/Basic/Distance_Normalized");
131                OgreIlluminationManager::getSingleton().setShadowMapMaterialName(Light::LT_POINT, "GTP/Basic/Distance_Normalized");
132                OgreIlluminationManager::getSingleton().setFocusingSM(false);
133           OgreIlluminationManager::getSingleton().setShadowMapSize(512);
134           OgreIlluminationManager::getSingleton().setBlurShadowMap(false);
135           OgreIlluminationManager::getSingleton().setUseLISPSM(false);
136                               
137                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
138               
139                mCamera->setPosition(32,0.68,11);
140                //mCamera->setPosition(50,35,-2);
141                //mCamera->lookAt(0,0,0);
142               
143                mCamera->setFOVy(Radian(Degree(80)));
144                mCamera->setNearClipDistance(0.01);
145                mCamera->setFarClipDistance(1000);
146                // Set ambient light
147        mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
148                mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox", 500);
149               
150                SceneNode* rootNode = mSceneMgr->getRootSceneNode();
151
152               
153                SceneSerializer s(mSceneMgr);
154                DataStreamPtr inputStream;                             
155                inputStream = ResourceGroupManager::getSingleton().openResource("processed.level");     //towers2.level
156                s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
157                s.parseEntryPoints("SpacePrmEntryPoints.text");
158                       
159                //createPlane("p","GTP/Basic/ShadowReceiver/Depth",Vector3(0,-0.3,0),Vector2(150,150));
160
161                mainLight = mSceneMgr->createLight("MainLight");
162                mainLight->setType(Light::LT_SPOTLIGHT);
163                mainLight->setCastShadows(true);
164        mainLight->setDiffuseColour(ColourValue(1.0,0.5,0.3,1));
165                mainLight->setSpecularColour(ColourValue::White);
166                mainLightNode = rootNode->createChildSceneNode();
167               
168                mainLightNode->setPosition(30,1,0.0);           
169                //mainLight->setPosition(30,1,0);
170                mainLight->setPowerScale(200);
171                mainLight->setDirection(-1, 0, 0);
172                mainLight->setSpotlightOuterAngle(Radian(Degree(90)));
173                mainLight->setSpotlightFalloff(1);
174                mainLight->setAttenuation(200, 0, 0, 1);
175                mainLightNode->attachObject(mainLight);         
176
177                blueLight = mSceneMgr->createLight("BlueLight");
178                blueLight->setType(Light::LT_SPOTLIGHT);
179                blueLight->setCastShadows(true);
180        blueLight->setDiffuseColour(ColourValue(0.3,0.5,1.0,1));
181                blueLight->setSpecularColour(ColourValue::White);
182                SceneNode* blueLightNode = rootNode->createChildSceneNode();
183               
184                blueLightNode->setPosition(-30,1,0.0);         
185                //blueLight->setPosition(-30,1,0);
186                blueLight->setPowerScale(200);
187                blueLight->setDirection(1, 0, 0);
188                blueLight->setSpotlightOuterAngle(Radian(Degree(160)));
189                blueLight->setSpotlightFalloff(1);
190                blueLight->setAttenuation(2000, 0, 0, 1);
191                blueLightNode->attachObject(blueLight);         
192
193               
194                OgreIlluminationManager::getSingleton().initTechniques();
195   }
196       
197        void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1))
198        {
199                Plane _plane;
200        _plane.normal = Vector3::UNIT_Y;
201        _plane.d = 0;
202
203
204        MeshManager::getSingleton().createPlane(_name + ".plane",
205            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
206            _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
207       
208                Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
209        _entity->setMaterialName(_material);
210
211                SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
212                _node->attachObject(_entity);
213                _node->setPosition(_pos);
214
215        }
216
217        void createFrameListener(void)
218    {
219                // This is where we instantiate our own frame listener
220                mFrameListener= new PRMDemoFrameListener(mWindow,
221                                                                                        mCamera, mainLightNode, mainLight       );
222       mFrameListener->setPriority(1); 
223                mRoot->addFrameListener(mFrameListener);
224                OgreIlluminationManager::getSingleton().setPriority(2);
225                mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
226    }
227
228};
229
Note: See TracBrowser for help on using the repository browser.