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

Revision 2163, 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("OcclusionCullingSceneManager");
152        }
153
154        void loadResources(void)
155        {
156               
157                // Initialise, parse scripts etc
158                ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
159                ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
160                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
161                ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
162                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap");
163                ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic");
164        }
165
166        void createPostproc()
167        {               
168                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
169                                                                                                                "GTP/PostProc/Glow");
170                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
171                                                                                                                "GTP/PostProc/Glow", true);
172
173                CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
174                                                                                                                "GTP/PostProc/ToneMap");
175                CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
176                                                                                                                "GTP/PostProc/ToneMap", true);         
177        }
178   
179        Light* light;
180        void createScene(void)
181    {
182                std::string terrain_cfg("terrainCulling.cfg");
183                mSceneMgr->setWorldGeometry(terrain_cfg);
184                //createPostproc();
185                OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
186                OgreIlluminationManager::getSingleton().setUseLISPSM(false);
187
188                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
189                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
190               
191                OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);         
192
193                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
194
195                mCamera->setPosition(0,100,240);
196                mCamera->setFOVy(Radian(Degree(80)));
197                //mCamera->setFarClipDistance(1000);
198                // Set ambient light
199        mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
200
201                // Skybox
202        mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
203
204                SceneNode* rootNode = mSceneMgr->getRootSceneNode();
205
206        Entity* sphere = mSceneMgr->createEntity("sphere", "head.mesh");
207                sphere->setMaterialName("GTP/Caustic/Glass");
208                sphereNode = rootNode->createChildSceneNode();
209                //sphereNode->setScale(0.1, 0.1, 0.1);//sphere
210                sphereNode->setPosition(0, 50, 0);
211                sphereNode->attachObject(sphere);
212                sphereNode->_updateBounds();
213
214                Entity* room = mSceneMgr->createEntity("room", "atlascube.mesh");
215                room->setMaterialName("TestPlane");
216                SceneNode *roomNode = rootNode->createChildSceneNode();
217                //roomNode->setScale(0.1, 0.1, 0.1);
218                roomNode->setPosition(0, 50, 0);
219                roomNode->attachObject(room);
220               
221
222                Light* mainLight = mSceneMgr->createLight("MainLight");
223                light = mainLight;
224                mainLight->setType(Light::LT_POINT);
225        mainLight->setDiffuseColour(ColourValue::White);
226                mainLight->setSpecularColour(ColourValue::White);
227                mainLightNode = rootNode->createChildSceneNode();
228                mainLightNode->setPosition(100,100,0);
229                //mainLight->setPosition(mainLightNode->getWorldPosition());
230                mainLightNode->attachObject(mainLight);
231                BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
232                bbs->setDefaultDimensions(10,10);
233                bbs->createBillboard(Vector3::ZERO, ColourValue::White);
234                bbs->setMaterialName("Flare");
235                mainLightNode->attachObject(bbs);
236
237                Root::getSingleton().renderOneFrame();
238                //mSceneMgr->_updateSceneGraph(mCamera);
239               
240
241                //createPlane("ground", "TestPlane", Vector3(0,0,0), Vector2(500,500));
242       
243                OgreIlluminationManager::getSingleton().initTechniques();
244               
245               
246   }
247   void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
248               
249           Plane _plane;
250        _plane.normal = Vector3::UNIT_Y;
251        _plane.d = 0;
252
253
254        MeshManager::getSingleton().createPlane(_name + ".plane",
255            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
256            _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
257       
258                Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
259        _entity->setMaterialName(_material);
260
261                SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
262                _node->attachObject(_entity);
263                _node->setPosition(_pos);
264        }
265
266
267
268        void createFrameListener(void)
269    {
270                // This is where we instantiate our own frame listener
271                mFrameListener= new RaytraceDemoListener(mWindow,
272                                                                                        mCamera,
273                                                                                        mainLightNode,
274                                                                                        sphereNode,
275                                                                                        light
276                                                                                        );
277                mFrameListener->setPriority(1);
278                OgreIlluminationManager::getSingleton().setPriority(2);
279        mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
280                mRoot->addFrameListener(mFrameListener);
281       
282    }
283
284};
285
Note: See TracBrowser for help on using the repository browser.