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

Revision 2144, 8.5 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
183                //createPostproc();
184                OgreIlluminationManager::getSingleton().setBlurShadowMap(true);
185                OgreIlluminationManager::getSingleton().setUseLISPSM(false);
186
187                OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
188                OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
189               
190                OgreIlluminationManager::getSingleton().setMaxJoinRadius(420);         
191
192                Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
193
194                mCamera->setPosition(0,100,240);
195                mCamera->setFOVy(Radian(Degree(80)));
196                //mCamera->setFarClipDistance(1000);
197                // Set ambient light
198        mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
199
200                // Skybox
201        mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
202
203                SceneNode* rootNode = mSceneMgr->getRootSceneNode();
204
205        Entity* sphere = mSceneMgr->createEntity("sphere", "head.mesh");
206                sphere->setMaterialName("GTP/Caustic/Glass");
207                sphereNode = rootNode->createChildSceneNode();
208                //sphereNode->setScale(0.1, 0.1, 0.1);//sphere
209                sphereNode->setPosition(0, 50, 0);
210                sphereNode->attachObject(sphere);
211                sphereNode->_updateBounds();
212
213                Entity* room = mSceneMgr->createEntity("room", "atlascube.mesh");
214                room->setMaterialName("TestPlane");
215                SceneNode *roomNode = rootNode->createChildSceneNode();
216                //roomNode->setScale(0.1, 0.1, 0.1);
217                roomNode->setPosition(0, 50, 0);
218                roomNode->attachObject(room);
219               
220
221                Light* mainLight = mSceneMgr->createLight("MainLight");
222                light = mainLight;
223                mainLight->setType(Light::LT_POINT);
224        mainLight->setDiffuseColour(ColourValue::White);
225                mainLight->setSpecularColour(ColourValue::White);
226                mainLightNode = rootNode->createChildSceneNode();
227                mainLightNode->setPosition(100,100,0);
228                //mainLight->setPosition(mainLightNode->getWorldPosition());
229                mainLightNode->attachObject(mainLight);
230                BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
231                bbs->setDefaultDimensions(10,10);
232                bbs->createBillboard(Vector3::ZERO, ColourValue::White);
233                bbs->setMaterialName("Flare");
234                mainLightNode->attachObject(bbs);
235               
236
237                //createPlane("ground", "TestPlane", Vector3(0,0,0), Vector2(500,500));
238       
239                OgreIlluminationManager::getSingleton().initTechniques();
240               
241               
242   }
243   void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
244               
245           Plane _plane;
246        _plane.normal = Vector3::UNIT_Y;
247        _plane.d = 0;
248
249
250        MeshManager::getSingleton().createPlane(_name + ".plane",
251            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
252            _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
253       
254                Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
255        _entity->setMaterialName(_material);
256
257                SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
258                _node->attachObject(_entity);
259                _node->setPosition(_pos);
260        }
261
262
263
264        void createFrameListener(void)
265    {
266                // This is where we instantiate our own frame listener
267                mFrameListener= new RaytraceDemoListener(mWindow,
268                                                                                        mCamera,
269                                                                                        mainLightNode,
270                                                                                        sphereNode,
271                                                                                        light
272                                                                                        );
273                mFrameListener->setPriority(1);
274                OgreIlluminationManager::getSingleton().setPriority(2);
275        mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
276                mRoot->addFrameListener(mFrameListener);
277       
278    }
279
280};
281
Note: See TracBrowser for help on using the repository browser.