source: GTP/trunk/App/Demos/Illum/Ogre/src/CausticTest/include/CausticTest.h @ 2179

Revision 2179, 8.6 KB checked in by szirmay, 17 years ago (diff)
Line 
1
2
3
4/*
5-----------------------------------------------------------------------------
6This source file is part of OGRE
7    (Object-oriented Graphics Rendering Engine)
8For the latest info, see http://www.ogre3d.org/
9
10Copyright (c) 2000-2005 The OGRE Team
11Also see acknowledgements in Readme.html
12
13You may use this sample code for anything you like, it is not covered by the
14LGPL like the rest of the engine.
15-----------------------------------------------------------------------------
16*/
17
18/**
19    \file
20        Lighting.h
21    \brief
22        Shows lighting support in OGRE. Also demonstrates the use of billboards
23        and controllers for automatic time-relative behaviour.
24*/
25
26
27#include "ExampleApplication.h"
28#include "OgreIlluminationManager.h"
29
30float causize = 10;
31float cauintens = 40;
32
33// Listener class for frame updates
34class RaytraceDemoListener : public ExampleFrameListener
35{
36protected:
37       
38        Light* light;
39        SceneNode* lightNode;
40        SceneNode* sphereNode;
41        unsigned long framecount;
42       
43public:
44    RaytraceDemoListener(RenderWindow* window, Camera* maincam,SceneNode* lightNode, SceneNode* sphereNode, Light* l)
45        :ExampleFrameListener(window, maincam)
46                                 
47    {
48                framecount = 0;
49                this->sphereNode = sphereNode;
50                this->lightNode = lightNode;
51                light = l;
52    }
53        bool processUnbufferedKeyInput(const FrameEvent& evt)
54    {
55                if (mInputDevice->isKeyDown(KC_SUBTRACT))
56        {
57                        Vector3 lPos = lightNode->getPosition();
58                        Vector3 lDir = sphereNode->getPosition() - lPos;
59                        lDir.normalise();
60                        lPos -= lDir;
61                        lightNode->setPosition(lPos);
62                        light->setDirection(lDir);
63                }
64                if (mInputDevice->isKeyDown(KC_ADD))
65        {
66                       
67                        Vector3 lPos = lightNode->getPosition();
68                        Vector3 lDir = sphereNode->getPosition() - lPos;
69                        lDir.normalise();
70                        lPos += lDir;
71                        lightNode->setPosition(lPos);
72                        light->setDirection(lDir);
73                }
74                if (mInputDevice->isKeyDown(KC_MULTIPLY))
75        {
76                        Vector3 lPos = lightNode->getPosition();
77                        Vector3 lDir = sphereNode->getPosition() - lPos;
78                        lDir.normalise();
79                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
80                        Vector3 up = lDir.crossProduct(right);
81                        lPos += up,
82                        lightNode->setPosition(lPos);
83                        light->setDirection(lDir);
84                }
85                if (mInputDevice->isKeyDown(KC_DIVIDE))
86        {
87                        Vector3 lPos = lightNode->getPosition();
88                        Vector3 lDir = sphereNode->getPosition() - lPos;
89                        lDir.normalise();
90                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
91                        Vector3 up = lDir.crossProduct(right);
92                        lPos -= up,                     
93                        lightNode->setPosition(lPos);
94                        light->setDirection(lDir);
95                               
96                }
97                if (mInputDevice->isKeyDown(KC_HOME))
98        {
99                        Vector3 lPos = lightNode->getPosition();
100                        Vector3 lDir = sphereNode->getPosition() - lPos;
101                        lDir.normalise();
102                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
103                        Vector3 up = lDir.crossProduct(right);
104                        lPos += right,
105                        lightNode->setPosition(lPos);
106                        light->setDirection(lDir);
107                }
108                if (mInputDevice->isKeyDown(KC_END))
109        {
110                        Vector3 lPos = lightNode->getPosition();
111                        Vector3 lDir = sphereNode->getPosition() - lPos;
112                        lDir.normalise();
113                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
114                        Vector3 up = lDir.crossProduct(right);
115                        lPos -= right,                 
116                        lightNode->setPosition(lPos);
117                        light->setDirection(lDir);
118                               
119                }
120                return ExampleFrameListener::processUnbufferedKeyInput(evt);
121        }
122    bool frameStarted(const FrameEvent& evt)
123    {
124                static bool first = true;
125       
126
127        //      lightNode->setPosition( 100.0 * Vector3(cos(-(float)framecount/500.0),2.0,sin(-(float)framecount/500.0)));
128               
129               
130                bool result = ExampleFrameListener::frameStarted(evt);
131       framecount++;
132      return result;     
133    }
134
135       
136
137};
138
139/** Application class */
140class RaytraceDemoApplication : public ExampleApplication
141{
142
143public:
144
145protected:
146        SceneNode* mainLightNode;
147        SceneNode* sphereNode;
148       
149        void chooseSceneManager()
150        {
151                //mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
152                mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
153        }
154
155        void loadResources(void)
156        {
157               
158                // Initialise, parse scripts etc
159                ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
160                ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
161                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
162                ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
163                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
164                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
165        }
166
167        void createPostproc()
168        {               
169                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
170                                                                                                                "GTP/PostProc/Glow");
171                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
172                                                                                                                "GTP/PostProc/Glow", true);
173
174                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
175                                                                                                                "GTP/PostProc/ToneMap");
176                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
177                                                                                                                "GTP/PostProc/ToneMap", true);         
178        }
179   
180        Light* light;
181        void createScene(void)
182    {
183                std::string occlusion_cfg("OcclusionCulling.cfg");
184                mSceneMgr->setWorldGeometry(occlusion_cfg);
185                //createPostproc();
186                OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
187                OgreIlluminationManager::getSingleton().setUseLISPSM(false);
188
189                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
190                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
191               
192                OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);         
193
194                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
195
196                mCamera->setPosition(0,100,240);
197                mCamera->setFOVy(Radian(Degree(80)));
198                //mCamera->setFarClipDistance(1000);
199                // Set ambient light
200        mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
201
202                // Skybox
203        mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
204
205                SceneNode* rootNode = mSceneMgr->getRootSceneNode();
206
207        Entity* sphere = mSceneMgr->createEntity("sphere", "head.mesh");
208                sphere->setMaterialName("GTP/Caustic/Glass");
209                sphereNode = rootNode->createChildSceneNode();
210                //sphereNode->setScale(0.1, 0.1, 0.1);//sphere
211                sphereNode->setPosition(0, 50, 0);
212                sphereNode->attachObject(sphere);
213                sphereNode->_updateBounds();
214
215                Entity* room = mSceneMgr->createEntity("room", "atlascube.mesh");
216                room->setMaterialName("TestPlane");
217                SceneNode *roomNode = rootNode->createChildSceneNode();
218                //roomNode->setScale(0.1, 0.1, 0.1);
219                roomNode->setPosition(0, 50, 0);
220                roomNode->attachObject(room);
221               
222
223                Light* mainLight = mSceneMgr->createLight("MainLight");
224                light = mainLight;
225                mainLight->setType(Light::LT_POINT);
226        mainLight->setDiffuseColour(ColourValue::White);
227                mainLight->setSpecularColour(ColourValue::White);
228                mainLightNode = rootNode->createChildSceneNode();
229                mainLightNode->setPosition(100,100,0);
230                //mainLight->setPosition(mainLightNode->getWorldPosition());
231                mainLightNode->attachObject(mainLight);
232                BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
233                bbs->setDefaultDimensions(10,10);
234                bbs->createBillboard(Vector3::ZERO, ColourValue::White);
235                bbs->setMaterialName("Flare");
236                mainLightNode->attachObject(bbs);
237
238                //createPlane("ground", "TestPlane", Vector3(0,0,0), Vector2(500,500));
239                OgreIlluminationManager::getSingleton().initTechniques();
240         }
241   void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
242               
243           Plane _plane;
244        _plane.normal = Vector3::UNIT_Y;
245        _plane.d = 0;
246
247
248        MeshManager::getSingleton().createPlane(_name + ".plane",
249            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
250            _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
251       
252                Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
253        _entity->setMaterialName(_material);
254
255                SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
256                _node->attachObject(_entity);
257                _node->setPosition(_pos);
258        }
259
260
261
262        void createFrameListener(void)
263    {
264                // This is where we instantiate our own frame listener
265                mFrameListener= new RaytraceDemoListener(mWindow,
266                                                                                        mCamera,
267                                                                                        mainLightNode,
268                                                                                        sphereNode,
269                                                                                        light
270                                                                                        );
271                mFrameListener->setPriority(1);
272                OgreIlluminationManager::getSingleton().setPriority(2);
273        mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
274                mRoot->addFrameListener(mFrameListener);
275       
276    }
277
278};
279
Note: See TracBrowser for help on using the repository browser.