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