1 | #ifndef _LBBCBILLBOARDVIEWMODE_H |
---|
2 | #define _LBBCBILLBOARDVIEWMODE_H |
---|
3 | |
---|
4 | |
---|
5 | #include "OBAOgreFrameListenerMode.h" |
---|
6 | |
---|
7 | namespace LBBC { |
---|
8 | |
---|
9 | class BillboardViewMode : public OBA::OgreFrameListenerMode |
---|
10 | { |
---|
11 | public: |
---|
12 | BillboardViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false): |
---|
13 | OBA::OgreFrameListenerMode(win, ogreFrameListenerModeHandle, useBufferedInputKeys, useBufferedInputMouse) |
---|
14 | { |
---|
15 | showDebugOverlay(false); |
---|
16 | epsilonX = 0.0; |
---|
17 | epsilonY = 0.0; |
---|
18 | factor = 0.125; |
---|
19 | } |
---|
20 | |
---|
21 | virtual ~BillboardViewMode() |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader) |
---|
26 | { |
---|
27 | Ogre::LogManager::getSingleton().logMessage("Before reloading the textureUnitState:" + mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getTextureUnitState(1)->getName()); |
---|
28 | Ogre::TextureManager::getSingleton().load(mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getTextureUnitState(1)->getName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
29 | //mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getTextureUnitState(1)->_load(); |
---|
30 | Ogre::LogManager::getSingleton().logMessage("After reloading the textureUnitState:" + mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getTextureUnitState(1)->getName()); |
---|
31 | //mWindow->setDebugText(mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getTextureUnitState(1)->getName()); |
---|
32 | |
---|
33 | showDebugOverlay(true); |
---|
34 | mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0));
|
---|
35 | //mEpsilonText = Ogre::String("Epsilon:") + Ogre::StringConverter::toString(epsilonX) + Ogre::String(",") + Ogre::StringConverter::toString(epsilonY);
|
---|
36 | //mWindow->setDebugText(mEpsilonText);
|
---|
37 | |
---|
38 | return OgreFrameListenerMode::frameStarted(evt, inputReader); |
---|
39 | } |
---|
40 | |
---|
41 | virtual bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt)
|
---|
42 | {
|
---|
43 | if (mInputDevice->isKeyDown(Ogre::KC_RIGHT))
|
---|
44 | {
|
---|
45 | epsilonX = epsilonX + (factor * evt.timeSinceLastFrame);
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (mInputDevice->isKeyDown(Ogre::KC_LEFT))
|
---|
49 | {
|
---|
50 | epsilonX = epsilonX - (factor * evt.timeSinceLastFrame);
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (mInputDevice->isKeyDown(Ogre::KC_UP))
|
---|
54 | {
|
---|
55 | epsilonY = epsilonY + (factor * evt.timeSinceLastFrame);
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (mInputDevice->isKeyDown(Ogre::KC_DOWN))
|
---|
59 | {
|
---|
60 | epsilonY = epsilonY - (factor * evt.timeSinceLastFrame);
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->hasFragmentProgram())
|
---|
64 | {
|
---|
65 | mFragParams = mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
|
---|
66 | if (mFragParams->getNumConstantDefinitions() > 0)
|
---|
67 | {
|
---|
68 | mFragParams->setNamedConstant("epsilonX", epsilonX);
|
---|
69 | mFragParams->setNamedConstant("epsilonY", epsilonY);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | if (mInputDevice->isKeyDown(Ogre::KC_A))
|
---|
74 | {
|
---|
75 | // Move camera left
|
---|
76 | mTranslateVector.x = -mMoveScale;
|
---|
77 | }
|
---|
78 |
|
---|
79 | if (mInputDevice->isKeyDown(Ogre::KC_D))
|
---|
80 | {
|
---|
81 | // Move camera RIGHT
|
---|
82 | mTranslateVector.x = mMoveScale;
|
---|
83 | }
|
---|
84 |
|
---|
85 | ///* Move camera forward by keypress. */
|
---|
86 | //if (mInputDevice->isKeyDown(Ogre::KC_UP) || mInputDevice->isKeyDown(Ogre::KC_W) )
|
---|
87 | //{
|
---|
88 | // mTranslateVector.z = -mMoveScale;
|
---|
89 | //}
|
---|
90 |
|
---|
91 | ///* Move camera backward by keypress. */
|
---|
92 | //if (mInputDevice->isKeyDown(Ogre::KC_DOWN) || mInputDevice->isKeyDown(Ogre::KC_S) )
|
---|
93 | //{
|
---|
94 | // mTranslateVector.z = mMoveScale;
|
---|
95 | //}
|
---|
96 |
|
---|
97 | /* Move camera forward by keypress. */
|
---|
98 | if (mInputDevice->isKeyDown(Ogre::KC_W) )
|
---|
99 | {
|
---|
100 | mTranslateVector.z = -mMoveScale;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* Move camera backward by keypress. */
|
---|
104 | if (mInputDevice->isKeyDown(Ogre::KC_S) )
|
---|
105 | {
|
---|
106 | mTranslateVector.z = mMoveScale;
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (mInputDevice->isKeyDown(Ogre::KC_PGUP))
|
---|
110 | {
|
---|
111 | // Move camera up
|
---|
112 | mTranslateVector.y = mMoveScale;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (mInputDevice->isKeyDown(Ogre::KC_PGDOWN))
|
---|
116 | {
|
---|
117 | // Move camera down
|
---|
118 | mTranslateVector.y = -mMoveScale;
|
---|
119 | }
|
---|
120 |
|
---|
121 | //if (mInputDevice->isKeyDown(Ogre::KC_RIGHT))
|
---|
122 | //{
|
---|
123 | // mCamera->yaw(-mRotScale);
|
---|
124 | //}
|
---|
125 | //
|
---|
126 | //if (mInputDevice->isKeyDown(Ogre::KC_LEFT))
|
---|
127 | //{
|
---|
128 | // mCamera->yaw(mRotScale);
|
---|
129 | //}
|
---|
130 |
|
---|
131 | // see if switching is on, and you want to toggle
|
---|
132 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(Ogre::KC_M) && mTimeUntilNextToggle <= 0)
|
---|
133 | {
|
---|
134 | switchMouseMode();
|
---|
135 | mTimeUntilNextToggle = 1;
|
---|
136 | }
|
---|
137 |
|
---|
138 | if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(Ogre::KC_K) && mTimeUntilNextToggle <= 0)
|
---|
139 | {
|
---|
140 | // must be going from immediate keyboard to buffered keyboard
|
---|
141 | switchKeyMode();
|
---|
142 | mTimeUntilNextToggle = 1;
|
---|
143 | }
|
---|
144 | if (mInputDevice->isKeyDown(Ogre::KC_F) && mTimeUntilNextToggle <= 0)
|
---|
145 | {
|
---|
146 | mStatsOn = !mStatsOn;
|
---|
147 | showDebugOverlay(mStatsOn);
|
---|
148 |
|
---|
149 | mTimeUntilNextToggle = 1;
|
---|
150 | }
|
---|
151 | if (mInputDevice->isKeyDown(Ogre::KC_T) && mTimeUntilNextToggle <= 0)
|
---|
152 | {
|
---|
153 | switch(mFiltering)
|
---|
154 | {
|
---|
155 | case Ogre::TFO_BILINEAR:
|
---|
156 | mFiltering = Ogre::TFO_TRILINEAR;
|
---|
157 | mAniso = 1;
|
---|
158 | break;
|
---|
159 | case Ogre::TFO_TRILINEAR:
|
---|
160 | mFiltering = Ogre::TFO_ANISOTROPIC;
|
---|
161 | mAniso = 8;
|
---|
162 | break;
|
---|
163 | case Ogre::TFO_ANISOTROPIC:
|
---|
164 | mFiltering = Ogre::TFO_BILINEAR;
|
---|
165 | mAniso = 1;
|
---|
166 | break;
|
---|
167 | default:
|
---|
168 | break;
|
---|
169 | }
|
---|
170 | Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
|
---|
171 | Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
|
---|
172 |
|
---|
173 |
|
---|
174 | showDebugOverlay(mStatsOn);
|
---|
175 |
|
---|
176 | mTimeUntilNextToggle = 1;
|
---|
177 | }
|
---|
178 |
|
---|
179 | if (mInputDevice->isKeyDown(Ogre::KC_SYSRQ) && mTimeUntilNextToggle <= 0)
|
---|
180 | {
|
---|
181 | char tmp[20];
|
---|
182 | sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
|
---|
183 | mWindow->writeContentsToFile(tmp);
|
---|
184 | mTimeUntilNextToggle = 0.5;
|
---|
185 | mWindow->setDebugText(Ogre::String("Wrote ") + tmp);
|
---|
186 | }
|
---|
187 |
|
---|
188 | if (mInputDevice->isKeyDown(Ogre::KC_R) && mTimeUntilNextToggle <=0)
|
---|
189 | {
|
---|
190 | mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
|
---|
191 | switch(mSceneDetailIndex) {
|
---|
192 | case 0 : mCamera->setPolygonMode(Ogre::PM_SOLID) ; break ;
|
---|
193 | case 1 : mCamera->setPolygonMode(Ogre::PM_WIREFRAME) ; break ;
|
---|
194 | case 2 : mCamera->setPolygonMode(Ogre::PM_POINTS) ; break ;
|
---|
195 | }
|
---|
196 | mTimeUntilNextToggle = 0.5;
|
---|
197 | }
|
---|
198 |
|
---|
199 | static bool displayCameraDetails = false;
|
---|
200 | if (mInputDevice->isKeyDown(Ogre::KC_P) && mTimeUntilNextToggle <= 0)
|
---|
201 | {
|
---|
202 | displayCameraDetails = !displayCameraDetails;
|
---|
203 | mTimeUntilNextToggle = 0.5;
|
---|
204 | if (!displayCameraDetails)
|
---|
205 | mWindow->setDebugText("");
|
---|
206 | }
|
---|
207 | if (displayCameraDetails)
|
---|
208 | {
|
---|
209 | // Print camera details
|
---|
210 | mWindow->setDebugText("P: " + Ogre::StringConverter::toString(mCamera->getDerivedPosition()) + " " +
|
---|
211 | "O: " + Ogre::StringConverter::toString(mCamera->getDerivedOrientation()));
|
---|
212 | }
|
---|
213 |
|
---|
214 | // Return true to continue rendering
|
---|
215 | return true;
|
---|
216 | } |
---|
217 | void setBillboardCloudMeshName(Ogre::String billboardCloudMeshName) |
---|
218 | { |
---|
219 | mBillboardCloudMeshName = billboardCloudMeshName; |
---|
220 | } |
---|
221 | |
---|
222 | virtual void createScene() |
---|
223 | { |
---|
224 | mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); |
---|
225 | |
---|
226 | Ogre::SceneNode* sNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
227 | mBillboardCloudEntity = mSceneMgr->createEntity(mBillboardCloudMeshName, mBillboardCloudMeshName);
|
---|
228 | sNode->attachObject(mBillboardCloudEntity); |
---|
229 | } |
---|
230 | |
---|
231 | protected: |
---|
232 | Ogre::String mBillboardCloudMeshName; |
---|
233 | |
---|
234 | Ogre::Entity *mBillboardCloudEntity; |
---|
235 | |
---|
236 | Ogre::Real epsilonX; |
---|
237 | |
---|
238 | Ogre::Real epsilonY; |
---|
239 | |
---|
240 | Ogre::Real factor; |
---|
241 | |
---|
242 | Ogre::String mEpsilonText; |
---|
243 | |
---|
244 | Ogre::GpuProgramParametersSharedPtr mFragParams; |
---|
245 | }; |
---|
246 | |
---|
247 | } |
---|
248 | #endif |
---|