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

Revision 3255, 8.9 KB checked in by szirmay, 15 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
33class RaytraceDemoApplication;
34
35// Listener class for frame updates
36class RaytraceDemoListener : public ExampleFrameListener
37{
38protected:
39       
40        Light* light;
41        SceneNode* lightNode;
42        SceneNode* sphereNode;
43        unsigned long framecount;
44        RaytraceDemoApplication* app;
45       
46public:
47    RaytraceDemoListener(RenderWindow* window, Camera* maincam,SceneNode* lightNode, SceneNode* sphereNode, Light* l, RaytraceDemoApplication* app)
48        :ExampleFrameListener(window, maincam)
49                                 
50    {
51                framecount = 0;
52                this->sphereNode = sphereNode;
53                this->lightNode = lightNode;
54                light = l;
55                this->app = app;
56    }
57        void setAttr(SceneNode* lightNode, SceneNode* sphereNode, Light* l)
58        {
59                this->sphereNode = sphereNode;
60                this->lightNode = lightNode;
61                light = l;             
62        }
63        bool processUnbufferedKeyInput(const FrameEvent& evt)
64    {
65                if (mInputDevice->isKeyDown(KC_SUBTRACT))
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_ADD))
75        {
76                       
77                        Vector3 lPos = lightNode->getPosition();
78                        Vector3 lDir = sphereNode->getPosition() - lPos;
79                        lDir.normalise();
80                        lPos += lDir;
81                        lightNode->setPosition(lPos);
82                        light->setDirection(lDir);
83                }
84                if (mInputDevice->isKeyDown(KC_MULTIPLY))
85        {
86                        Vector3 lPos = lightNode->getPosition();
87                        Vector3 lDir = sphereNode->getPosition() - lPos;
88                        lDir.normalise();
89                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
90                        Vector3 up = lDir.crossProduct(right);
91                        lPos += up,
92                        lightNode->setPosition(lPos);
93                        light->setDirection(lDir);
94                }
95                if (mInputDevice->isKeyDown(KC_DIVIDE))
96        {
97                        Vector3 lPos = lightNode->getPosition();
98                        Vector3 lDir = sphereNode->getPosition() - lPos;
99                        lDir.normalise();
100                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
101                        Vector3 up = lDir.crossProduct(right);
102                        lPos -= up,                     
103                        lightNode->setPosition(lPos);
104                        light->setDirection(lDir);
105                               
106                }
107                if (mInputDevice->isKeyDown(KC_HOME))
108        {
109                        Vector3 lPos = lightNode->getPosition();
110                        Vector3 lDir = sphereNode->getPosition() - lPos;
111                        lDir.normalise();
112                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
113                        Vector3 up = lDir.crossProduct(right);
114                        lPos += right,
115                        lightNode->setPosition(lPos);
116                        light->setDirection(lDir);
117                }
118                if (mInputDevice->isKeyDown(KC_END))
119        {
120                        Vector3 lPos = lightNode->getPosition();
121                        Vector3 lDir = sphereNode->getPosition() - lPos;
122                        lDir.normalise();
123                        Vector3 right = lDir.crossProduct(Vector3(0,1,0));
124                        Vector3 up = lDir.crossProduct(right);
125                        lPos -= right,                 
126                        lightNode->setPosition(lPos);
127                        light->setDirection(lDir);
128                               
129                }
130                return ExampleFrameListener::processUnbufferedKeyInput(evt);
131        }
132   
133        bool frameStarted(const FrameEvent& evt);
134       
135
136};
137
138/** Application class */
139class RaytraceDemoApplication : public ExampleApplication
140{
141
142public:
143       
144        void setupScene()
145        {
146                // Skybox
147        mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
148
149                SceneNode* rootNode = mSceneMgr->getRootSceneNode();
150
151        Entity* sphere = mSceneMgr->createEntity("sphere", "head.mesh");
152               
153        //      Material* mat = (Material*) MaterialManager::getSingleton().getByName("GTP/Caustic/Glass").getPointer();
154        //      Material* newMat = mat->clone(mat->getName() + "_new").getPointer();
155
156                sphere->setMaterialName("GTP/Caustic/Glass");
157                sphereNode = rootNode->createChildSceneNode();
158                //sphereNode->setScale(0.1, 0.1, 0.1);//sphere
159                sphereNode->setPosition(0, 50, 0);
160                sphereNode->attachObject(sphere);
161                sphereNode->_updateBounds();
162
163                Entity* room = mSceneMgr->createEntity("room", "atlascube.mesh");
164        //      mat = (Material*) MaterialManager::getSingleton().getByName("TestPlane").getPointer();
165        //      newMat = mat->clone(mat->getName() + "_new").getPointer();
166
167                room->setMaterialName("TestPlane");
168                SceneNode *roomNode = rootNode->createChildSceneNode();
169                //roomNode->setScale(0.1, 0.1, 0.1);
170                roomNode->setPosition(0, 50, 0);
171                roomNode->attachObject(room);
172               
173
174                Light* mainLight = mSceneMgr->createLight("MainLight");
175                light = mainLight;
176                mainLight->setType(Light::LT_POINT);
177        mainLight->setDiffuseColour(ColourValue::White);
178                mainLight->setSpecularColour(ColourValue::White);
179                mainLightNode = rootNode->createChildSceneNode();
180                mainLightNode->setPosition(100,100,0);
181                //mainLight->setPosition(mainLightNode->getWorldPosition());
182                mainLightNode->attachObject(mainLight);
183                BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
184                bbs->setDefaultDimensions(10,10);
185                bbs->createBillboard(Vector3::ZERO, ColourValue::White);
186                bbs->setMaterialName("Flare");
187                mainLightNode->attachObject(bbs);
188
189                //createPlane("ground", "TestPlane", Vector3(0,0,0), Vector2(500,500));
190                OgreIlluminationManager::getSingleton().initTechniques();
191
192                OgreIlluminationManager::getSingleton().setPriority(2);
193        mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());             
194        }
195        setFrameListenerAttr()
196        {
197                ((RaytraceDemoListener*) mFrameListener)->setAttr(mainLightNode, sphereNode, light);
198        }
199       
200
201protected:
202        SceneNode* mainLightNode;
203        SceneNode* sphereNode;
204
205        void loadResources(void)
206        {
207                // Initialise, parse scripts etc
208                ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
209                ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
210                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
211                ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
212                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
213                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
214        }
215
216        void createPostproc()
217        {               
218                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
219                                                                                                                "GTP/PostProc/Glow");
220                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
221                                                                                                                "GTP/PostProc/Glow", true);
222
223                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
224                                                                                                                "GTP/PostProc/ToneMap");
225                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
226                                                                                                                "GTP/PostProc/ToneMap", true);         
227        }
228   
229        Light* light;
230        void createScene(void)
231    {
232               
233                //createPostproc();
234                OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
235                OgreIlluminationManager::getSingleton().setUseLISPSM(false);
236
237                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
238                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
239               
240                OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);         
241
242                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
243
244                mCamera->setPosition(0,100,240);
245                mCamera->setFOVy(Radian(Degree(80)));
246                //mCamera->setFarClipDistance(1000);
247                // Set ambient light
248        mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
249
250                setupScene();
251         }
252
253       
254   void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
255               
256           Plane _plane;
257        _plane.normal = Vector3::UNIT_Y;
258        _plane.d = 0;
259
260
261        MeshManager::getSingleton().createPlane(_name + ".plane",
262            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
263            _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
264       
265                Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
266        _entity->setMaterialName(_material);
267
268                SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
269                _node->attachObject(_entity);
270                _node->setPosition(_pos);
271        }
272
273
274
275        void createFrameListener(void)
276    {
277                // This is where we instantiate our own frame listener
278                mFrameListener= new RaytraceDemoListener(mWindow,
279                                                                                        mCamera,
280                                                                                        mainLightNode,
281                                                                                        sphereNode,
282                                                                                        light,
283                                                                                        this
284                                                                                        );
285                mFrameListener->setPriority(1);
286                mRoot->addFrameListener(mFrameListener);
287       
288    }
289
290};
291
292
293
294
295
296
Note: See TracBrowser for help on using the repository browser.