[731] | 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 | { |
---|
[751] | 15 | showDebugOverlay(false); |
---|
[821] | 16 | epsilonX = 0.0; |
---|
| 17 | epsilonY = 0.0; |
---|
[861] | 18 | factor = 0.125; |
---|
[731] | 19 | } |
---|
| 20 | |
---|
| 21 | virtual ~BillboardViewMode() |
---|
| 22 | { |
---|
| 23 | } |
---|
| 24 | |
---|
[751] | 25 | bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader) |
---|
| 26 | { |
---|
[821] | 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);
|
---|
[751] | 31 | |
---|
| 32 | return OgreFrameListenerMode::frameStarted(evt, inputReader); |
---|
| 33 | } |
---|
| 34 | |
---|
[821] | 35 | virtual bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt)
|
---|
| 36 | {
|
---|
[861] | 37 | if (mInputDevice->isKeyDown(Ogre::KC_RIGHT))
|
---|
[821] | 38 | {
|
---|
[861] | 39 | epsilonX = epsilonX + (factor * evt.timeSinceLastFrame);
|
---|
[821] | 40 | }
|
---|
| 41 |
|
---|
[861] | 42 | if (mInputDevice->isKeyDown(Ogre::KC_LEFT))
|
---|
[821] | 43 | {
|
---|
[861] | 44 | epsilonX = epsilonX - (factor * evt.timeSinceLastFrame);
|
---|
[821] | 45 | }
|
---|
| 46 |
|
---|
[861] | 47 | if (mInputDevice->isKeyDown(Ogre::KC_UP))
|
---|
[821] | 48 | {
|
---|
[861] | 49 | epsilonY = epsilonY + (factor * evt.timeSinceLastFrame);
|
---|
[821] | 50 | }
|
---|
| 51 |
|
---|
[861] | 52 | if (mInputDevice->isKeyDown(Ogre::KC_DOWN))
|
---|
[821] | 53 | {
|
---|
[861] | 54 | epsilonY = epsilonY - (factor * evt.timeSinceLastFrame);
|
---|
[821] | 55 | }
|
---|
| 56 |
|
---|
| 57 | mFragParams = mBillboardCloudEntity->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
|
---|
[861] | 58 |
|
---|
[821] | 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 |
|
---|
[861] | 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 |
|
---|
[821] | 86 | /* Move camera forward by keypress. */
|
---|
[861] | 87 | if (mInputDevice->isKeyDown(Ogre::KC_W) )
|
---|
[821] | 88 | {
|
---|
| 89 | mTranslateVector.z = -mMoveScale;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /* Move camera backward by keypress. */
|
---|
[861] | 93 | if (mInputDevice->isKeyDown(Ogre::KC_S) )
|
---|
[821] | 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 |
|
---|
[861] | 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 | //}
|
---|
[821] | 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()));
|
---|
[861] | 201 | }
|
---|
[821] | 202 |
|
---|
| 203 | // Return true to continue rendering
|
---|
| 204 | return true;
|
---|
| 205 | } |
---|
[751] | 206 | void setBillboardCloudMeshName(Ogre::String billboardCloudMeshName) |
---|
| 207 | { |
---|
| 208 | mBillboardCloudMeshName = billboardCloudMeshName; |
---|
| 209 | } |
---|
| 210 | |
---|
[731] | 211 | virtual void createScene() |
---|
| 212 | { |
---|
[751] | 213 | mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); |
---|
| 214 | |
---|
[731] | 215 | Ogre::SceneNode* sNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
[861] | 216 | mBillboardCloudEntity = mSceneMgr->createEntity(mBillboardCloudMeshName, mBillboardCloudMeshName);
|
---|
| 217 | //mBillboardCloudEntity = mSceneMgr->createEntity("chestnutLeavesBillboardCloudGrouped.mesh", "chestnutLeavesBillboardCloudGrouped.mesh");
|
---|
[786] | 218 | //mBillboardCloudEntity = mSceneMgr->createEntity("mapleLeavesBillboardCloudGrouped.mesh", "mapleLeavesBillboardCloudGrouped.mesh");
|
---|
[821] | 219 | //mBillboardCloudEntity = mSceneMgr->createEntity("prunusLeavesBillboardCloudGrouped.mesh", "prunusLeavesBillboardCloudGrouped.mesh");
|
---|
[751] | 220 | sNode->attachObject(mBillboardCloudEntity); |
---|
[861] | 221 | //sNode->rotate(Ogre::Vector3::UNIT_X, Ogre::Radian(Ogre::Degree(-90.0))); |
---|
[731] | 222 | } |
---|
| 223 | |
---|
[751] | 224 | protected: |
---|
| 225 | Ogre::String mBillboardCloudMeshName; |
---|
| 226 | |
---|
| 227 | Ogre::Entity *mBillboardCloudEntity; |
---|
| 228 | |
---|
[821] | 229 | Ogre::Real epsilonX; |
---|
| 230 | |
---|
| 231 | Ogre::Real epsilonY; |
---|
| 232 | |
---|
| 233 | Ogre::Real factor; |
---|
| 234 | |
---|
| 235 | Ogre::String mEpsilonText; |
---|
| 236 | |
---|
| 237 | Ogre::GpuProgramParametersSharedPtr mFragParams; |
---|
[731] | 238 | }; |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | #endif |
---|