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 "SpriteParticleRenderer.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | // Listener class for frame updates
|
---|
30 | class ParticleDemoFrameListener : public ExampleFrameListener
|
---|
31 | {
|
---|
32 | protected:
|
---|
33 |
|
---|
34 | unsigned long framecount;
|
---|
35 |
|
---|
36 | public:
|
---|
37 | ParticleDemoFrameListener(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 ParticleDemoApplication : public ExampleApplication
|
---|
57 | {
|
---|
58 |
|
---|
59 | public:
|
---|
60 |
|
---|
61 | protected:
|
---|
62 | SceneNode* kupolaNode;
|
---|
63 | SceneNode* mainLightNode;
|
---|
64 |
|
---|
65 | void loadResources(void)
|
---|
66 | {
|
---|
67 | // Initialise, parse scripts etc
|
---|
68 | ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap");
|
---|
69 | ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic");
|
---|
70 | ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
|
---|
71 | ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc");
|
---|
72 | }
|
---|
73 |
|
---|
74 | void chooseSceneManager()
|
---|
75 | {
|
---|
76 | //mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
|
---|
77 | mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
|
---|
78 | }
|
---|
79 |
|
---|
80 | void createPostproc()
|
---|
81 | {
|
---|
82 | /*CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
83 | "GTP/PostProc/Glow");
|
---|
84 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
85 | "GTP/PostProc/Glow", true);*/
|
---|
86 |
|
---|
87 | CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0),
|
---|
88 | "GTP/PostProc/ToneMap");
|
---|
89 | CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0),
|
---|
90 | "GTP/PostProc/ToneMap", true);
|
---|
91 | }
|
---|
92 |
|
---|
93 | void createScene(void)
|
---|
94 | {
|
---|
95 | createPostproc();
|
---|
96 |
|
---|
97 | OgreIlluminationManager::getSingleton().setMainCamera(mCamera);
|
---|
98 | OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0));
|
---|
99 |
|
---|
100 | Root::getSingleton()._setCurrentSceneManager(mSceneMgr);
|
---|
101 | mCamera->setPosition(0,100,240);
|
---|
102 | mCamera->setFOVy(Radian(Degree(80)));
|
---|
103 | //mCamera->setFarClipDistance(1000);
|
---|
104 | // Set ambient light
|
---|
105 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
106 |
|
---|
107 | // Skybox
|
---|
108 | mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
|
---|
109 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
110 |
|
---|
111 | //init objects
|
---|
112 | Entity* kupola = mSceneMgr->createEntity("kupola", "kupola.mesh");
|
---|
113 | kupola->getSubEntity(0)->setMaterialName("kupolafal_low");
|
---|
114 | kupola->getSubEntity(1)->setMaterialName("kupolatalaj_low");
|
---|
115 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
116 |
|
---|
117 | //init nodes
|
---|
118 | kupolaNode = rootNode->createChildSceneNode( "kupola" );
|
---|
119 | kupolaNode->rotate(Vector3(0,1,0),Radian(Degree(90)));
|
---|
120 | kupolaNode->attachObject( kupola );
|
---|
121 | kupolaNode->scale(25,21,25);
|
---|
122 | kupolaNode->_updateBounds();
|
---|
123 | MeshPtr kmesh = kupola->getMesh();
|
---|
124 | kmesh->buildTangentVectors(0,1);
|
---|
125 |
|
---|
126 | SceneNode* headNode = rootNode->createChildSceneNode("head");
|
---|
127 | headNode->attachObject(head);
|
---|
128 | headNode->setScale(2,2,2);
|
---|
129 | AxisAlignedBox bbox = head->getBoundingBox();
|
---|
130 | headNode->setPosition(0, 100,0);
|
---|
131 | headNode->_updateBounds();
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 | //Init lights
|
---|
136 | /* Light* mainLight = mSceneMgr->createLight("MainLight");
|
---|
137 | mainLight->setType(Light::LT_POINT);
|
---|
138 | mainLight->setDiffuseColour(ColourValue(0.9,0.9,0.9,1));
|
---|
139 | mainLight->setSpecularColour(ColourValue(0.9, 0.9,0.9,1));
|
---|
140 | mainLight->setAttenuation(400, 1.0, 1, 1);
|
---|
141 | mainLightNode = rootNode->createChildSceneNode();
|
---|
142 | mainLightNode->setPosition(0,150,0);
|
---|
143 | mainLight->setPosition(mainLightNode->getWorldPosition());
|
---|
144 | mainLightNode->attachObject(mainLight); */
|
---|
145 |
|
---|
146 |
|
---|
147 | }
|
---|
148 |
|
---|
149 | void createFrameListener(void)
|
---|
150 | {
|
---|
151 | // This is where we instantiate our own frame listener
|
---|
152 | mFrameListener= new ParticleDemoFrameListener(mWindow,
|
---|
153 | mCamera );
|
---|
154 | mFrameListener->setPriority(1);
|
---|
155 | mRoot->addFrameListener(mFrameListener);
|
---|
156 | OgreIlluminationManager::getSingleton().setPriority(2);
|
---|
157 | mRoot->addFrameListener(&OgreIlluminationManager::getSingleton());
|
---|
158 | }
|
---|
159 |
|
---|
160 | };
|
---|
161 |
|
---|