1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | You may use this sample code for anything you like, it is not covered by the
|
---|
11 | LGPL 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 |
|
---|
28 |
|
---|
29 | // Listener class for frame updates
|
---|
30 | class PRMDemoFrameListener : public ExampleFrameListener
|
---|
31 | {
|
---|
32 | protected:
|
---|
33 |
|
---|
34 | unsigned long framecount;
|
---|
35 |
|
---|
36 | public:
|
---|
37 | PRMDemoFrameListener(RenderWindow* window, Camera* maincam)
|
---|
38 | :ExampleFrameListener(window, maincam)
|
---|
39 |
|
---|
40 | {
|
---|
41 | framecount = 0;
|
---|
42 | }
|
---|
43 |
|
---|
44 | bool frameStarted(const FrameEvent& evt)
|
---|
45 | {
|
---|
46 | bool result = ExampleFrameListener::frameStarted(evt);
|
---|
47 | framecount++;
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | };
|
---|
54 |
|
---|
55 | /** Application class */
|
---|
56 | class PRMDemoApplication : public ExampleApplication
|
---|
57 | {
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | protected:
|
---|
63 | SceneNode* kupolaNode;
|
---|
64 | SceneNode* mainLightNode;
|
---|
65 |
|
---|
66 | void loadResources(void)
|
---|
67 | {
|
---|
68 | // Initialise, parse scripts etc
|
---|
69 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
70 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
71 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
72 | }
|
---|
73 |
|
---|
74 | void createPostproc()
|
---|
75 | {
|
---|
76 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
77 | "GTP/PostProc/Glow");
|
---|
78 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
79 | "GTP/PostProc/Glow", true);
|
---|
80 |
|
---|
81 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
82 | "GTP/PostProc/ToneMap");
|
---|
83 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
84 | "GTP/PostProc/ToneMap", true);
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | void createScene(void)
|
---|
89 | {
|
---|
90 | //createPostproc();
|
---|
91 |
|
---|
92 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
93 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
94 | OgreIlluminationManager::getSingleton().setShadowMapSize(512);
|
---|
95 |
|
---|
96 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
97 | mCamera->setPosition(0,20,40);
|
---|
98 | //mCamera->setPosition(0,100,0);
|
---|
99 | //mCamera->lookAt(0,-1,0);
|
---|
100 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
101 | //mCamera->setFarClipDistance(1000);
|
---|
102 | // Set ambient light
|
---|
103 | mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
|
---|
104 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
105 |
|
---|
106 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
107 |
|
---|
108 | SceneSerializer s(mSceneMgr);
|
---|
109 | DataStreamPtr inputStream;
|
---|
110 | inputStream = ResourceGroupManager::getSingleton().openResource("level.txt");
|
---|
111 | s.parseScript(inputStream, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
112 |
|
---|
113 | /* Entity* lepcso = mSceneMgr->createEntity("lepcso","stairs.mesh");
|
---|
114 | SceneNode* lNode = rootNode->createChildSceneNode("l");
|
---|
115 | lNode->attachObject(lepcso);*/
|
---|
116 |
|
---|
117 | createPlane("p","lambert1",Vector3(0,-20,0),Vector2(100,100));
|
---|
118 |
|
---|
119 | Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
120 | mainLight->setType(Light::LT_DIRECTIONAL);
|
---|
121 | mainLight->setDiffuseColour(ColourValue::White);
|
---|
122 | mainLight->setSpecularColour(ColourValue::White);
|
---|
123 | mainLightNode = rootNode->createChildSceneNode();
|
---|
124 |
|
---|
125 | mainLightNode->setPosition(0,0,0);
|
---|
126 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
127 | mainLight->setDirection(-1,-1, 0);
|
---|
128 | mainLightNode->attachObject(mainLight);
|
---|
129 |
|
---|
130 | OgreIlluminationManager::getSingleton().initTechniques();
|
---|
131 | }
|
---|
132 |
|
---|
133 | void createPlane(Ogre::String _name, Ogre::String _material, Ogre::Vector3 _pos, Ogre::Vector2 _size, Ogre::Vector2 _subdivisions = Ogre::Vector2(1,1)) {
|
---|
134 | Plane _plane;
|
---|
135 | _plane.normal = Vector3::UNIT_Y;
|
---|
136 | _plane.d = 0;
|
---|
137 |
|
---|
138 |
|
---|
139 | MeshManager::getSingleton().createPlane(_name + ".plane",
|
---|
140 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
141 | _plane,_size.x,_size.y,1,1,true,1,_subdivisions.x,_subdivisions.y,Vector3::UNIT_Z);
|
---|
142 |
|
---|
143 | Entity *_entity = mSceneMgr->createEntity(_name + ".entity", _name + ".plane");
|
---|
144 | _entity->setMaterialName(_material);
|
---|
145 |
|
---|
146 | SceneNode* _node = mSceneMgr->getRootSceneNode()->createChildSceneNode(_name + ".node");
|
---|
147 | _node->attachObject(_entity);
|
---|
148 | _node->setPosition(_pos);
|
---|
149 |
|
---|
150 | }
|
---|
151 |
|
---|
152 | void createFrameListener(void)
|
---|
153 | {
|
---|
154 | // This is where we instantiate our own frame listener
|
---|
155 | mFrameListener= new PRMDemoFrameListener(mWindow,
|
---|
156 | mCamera );
|
---|
157 | mFrameListener->setPriority(1);
|
---|
158 | mRoot->addFrameListener(mFrameListener);
|
---|
159 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
160 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
161 | }
|
---|
162 |
|
---|
163 | };
|
---|
164 |
|
---|