[288] | 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-2006 Torus Knot Software Ltd |
---|
| 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 | #include <OgreTextAreaOverlayElement.h> |
---|
| 24 | |
---|
| 25 | #include "ExampleApplication.h" |
---|
| 26 | |
---|
| 27 | Overlay* helloOverlay ; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /** This class turns lights & billboards linked to them on & off */ |
---|
| 31 | class LightFlasher : public ControllerValue<Real> |
---|
| 32 | { |
---|
| 33 | protected: |
---|
| 34 | Light* mLight; |
---|
| 35 | Billboard* mBillboard; |
---|
| 36 | ColourValue mMaxColour; |
---|
| 37 | Real intensity; |
---|
| 38 | public: |
---|
| 39 | LightFlasher(Light* light, Billboard* billboard, ColourValue maxColour) |
---|
| 40 | { |
---|
| 41 | mLight = light; |
---|
| 42 | mBillboard = billboard; |
---|
| 43 | mMaxColour = maxColour; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | virtual Real getValue (void) const |
---|
| 47 | { |
---|
| 48 | return intensity; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | virtual void setValue (Real value) |
---|
| 52 | { |
---|
| 53 | intensity = value; |
---|
| 54 | |
---|
| 55 | ColourValue newColour; |
---|
| 56 | |
---|
| 57 | // Attenuate the brightness of the light |
---|
| 58 | newColour.r = mMaxColour.r * intensity; |
---|
| 59 | newColour.g = mMaxColour.g * intensity; |
---|
| 60 | newColour.b = mMaxColour.b * intensity; |
---|
| 61 | |
---|
| 62 | mLight->setDiffuseColour(newColour); |
---|
| 63 | mBillboard->setColour(newColour); |
---|
| 64 | } |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | /** Controller function mapping waveform to light intensity */ |
---|
| 69 | class LightFlasherControllerFunction : public WaveformControllerFunction |
---|
| 70 | { |
---|
| 71 | public: |
---|
| 72 | LightFlasherControllerFunction(WaveformType wavetype, Real frequency, Real phase) : WaveformControllerFunction(wavetype, 0, frequency, phase, 1, true) |
---|
| 73 | { |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | // Some global node data |
---|
| 80 | SceneNode* mRedYellowLightsNode; |
---|
| 81 | SceneNode* mGreenBlueLightsNode; |
---|
| 82 | std::vector<AnimationState*> mAnimStateList; |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | // Listener class for frame updates |
---|
| 86 | class LightingListener : public ExampleFrameListener |
---|
| 87 | { |
---|
| 88 | protected: |
---|
| 89 | public: |
---|
| 90 | LightingListener(RenderWindow* win, Camera* cam) |
---|
| 91 | : ExampleFrameListener(win, cam) |
---|
| 92 | { |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | bool frameStarted(const FrameEvent& evt) |
---|
| 96 | { |
---|
| 97 | if( ExampleFrameListener::frameStarted(evt) == false ) |
---|
| 98 | return false; |
---|
| 99 | |
---|
| 100 | std::vector<AnimationState*>::iterator animi; |
---|
| 101 | for (animi = mAnimStateList.begin(); animi != mAnimStateList.end(); ++animi) |
---|
| 102 | { |
---|
| 103 | (*animi)->addTime(evt.timeSinceLastFrame); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return true; |
---|
| 107 | } |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | /** Application class */ |
---|
| 111 | class LightingApplication : public ExampleApplication |
---|
| 112 | { |
---|
| 113 | protected: |
---|
| 114 | |
---|
| 115 | // The set of all the billboards used for the lights |
---|
| 116 | // 2 sets because we'll rotate them differently |
---|
| 117 | BillboardSet* mRedYellowLights; |
---|
| 118 | BillboardSet* mGreenBlueLights; |
---|
| 119 | |
---|
| 120 | // Billboards |
---|
| 121 | Billboard* mRedLightBoard; |
---|
| 122 | Billboard* mBlueLightBoard; |
---|
| 123 | Billboard* mYellowLightBoard; |
---|
| 124 | Billboard* mGreenLightBoard; |
---|
| 125 | |
---|
| 126 | // Lights |
---|
| 127 | Light* mRedLight; |
---|
| 128 | Light* mBlueLight; |
---|
| 129 | Light* mYellowLight; |
---|
| 130 | Light* mGreenLight; |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | // Light flashers |
---|
| 134 | ControllerValueRealPtr mRedLightFlasher; |
---|
| 135 | ControllerValueRealPtr mBlueLightFlasher; |
---|
| 136 | ControllerValueRealPtr mYellowLightFlasher; |
---|
| 137 | ControllerValueRealPtr mGreenLightFlasher; |
---|
| 138 | |
---|
| 139 | // Light controller functions |
---|
| 140 | ControllerFunctionRealPtr mRedLightControllerFunc; |
---|
| 141 | ControllerFunctionRealPtr mBlueLightControllerFunc; |
---|
| 142 | ControllerFunctionRealPtr mYellowLightControllerFunc; |
---|
| 143 | ControllerFunctionRealPtr mGreenLightControllerFunc; |
---|
| 144 | |
---|
| 145 | // Light controllers |
---|
| 146 | Controller<Real>* mRedLightController; |
---|
| 147 | Controller<Real>* mBlueLightController; |
---|
| 148 | Controller<Real>* mYellowLightController; |
---|
| 149 | Controller<Real>* mGreenLightController; |
---|
| 150 | |
---|
| 151 | void update(void) |
---|
| 152 | { |
---|
| 153 | // set Time |
---|
| 154 | int TimeMin = 99; |
---|
| 155 | int TimeSec = 55; |
---|
| 156 | OverlayElement* TimeText = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text"); |
---|
| 157 | TimeText->setCaption(StringConverter::toString(TimeMin) + ":" + StringConverter::toString(TimeSec)); |
---|
| 158 | |
---|
| 159 | // set TargetWindow |
---|
| 160 | String TargetWindowName = "HURRA"; |
---|
| 161 | int TargetWindowDistance = 12; |
---|
| 162 | String TargetWindowStatus = "Dead"; |
---|
| 163 | int TargetWindowHitRating = 30; |
---|
| 164 | OverlayElement* TargetWindowNameText = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name"); |
---|
| 165 | TargetWindowNameText->setCaption( TargetWindowName); |
---|
| 166 | OverlayElement* TargetWindowDistanceText = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText"); |
---|
| 167 | TargetWindowDistanceText->setCaption(StringConverter::toString(TargetWindowDistance) + "km" ); |
---|
| 168 | OverlayElement* TargetWindowStatusText = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText"); |
---|
| 169 | TargetWindowStatusText->setCaption( TargetWindowStatus ); |
---|
| 170 | OverlayElement* TargetWindowHitRatingText = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText"); |
---|
| 171 | TargetWindowHitRatingText->setCaption(StringConverter::toString(TargetWindowHitRating) + "%" ); |
---|
| 172 | |
---|
| 173 | // set Energy |
---|
| 174 | int EnergyValue = 60.0; |
---|
| 175 | OverlayElement* EnergyLength = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground"); |
---|
| 176 | EnergyLength->setWidth((int)((double)60/(double)100*200)); |
---|
| 177 | |
---|
| 178 | // set Shild |
---|
| 179 | bool ShildLeftTopValue = true; |
---|
| 180 | bool ShildRightTopValue = false; |
---|
| 181 | bool ShildLeftBottomValue = false; |
---|
| 182 | bool ShildRightBottomValue = true; |
---|
| 183 | OverlayElement* ShildLeftTop = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/ShildLeftTop"); |
---|
| 184 | if (ShildLeftTopValue) ShildLeftTop->show(); |
---|
| 185 | else ShildLeftTop->hide(); |
---|
| 186 | OverlayElement* ShildRightTop = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/ShildRightTop"); |
---|
| 187 | if (ShildRightTopValue) ShildRightTop->show(); |
---|
| 188 | else ShildRightTop->hide(); |
---|
| 189 | OverlayElement* ShildLeftBottom = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/ShildLeftBottom"); |
---|
| 190 | if (ShildLeftBottomValue) ShildLeftBottom->show(); |
---|
| 191 | else ShildLeftBottom->hide(); |
---|
| 192 | OverlayElement* ShildRightBottom = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/ShildRightBottom"); |
---|
| 193 | if (ShildRightBottomValue) ShildRightBottom->show(); |
---|
| 194 | else ShildRightBottom->hide(); |
---|
| 195 | |
---|
| 196 | // set Rockets |
---|
| 197 | int Rocket1 = 11; |
---|
| 198 | int Rocket2 = 22; |
---|
| 199 | int Rocket3 = 33; |
---|
| 200 | int Rocket4 = 44; |
---|
| 201 | OverlayElement* RocketNum1 = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1"); |
---|
| 202 | RocketNum1->setCaption(StringConverter::toString(Rocket1)); |
---|
| 203 | OverlayElement* RocketNum2 = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2"); |
---|
| 204 | RocketNum2->setCaption(StringConverter::toString(Rocket2)); |
---|
| 205 | OverlayElement* RocketNum3 = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3"); |
---|
| 206 | RocketNum3->setCaption(StringConverter::toString(Rocket3)); |
---|
| 207 | OverlayElement* RocketNum4 = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4"); |
---|
| 208 | RocketNum4->setCaption(StringConverter::toString(Rocket4)); |
---|
| 209 | |
---|
| 210 | // set EnergyDistribution |
---|
| 211 | double EnergyDistrPixelX = 100; |
---|
| 212 | double EnergyDistrPixelY = 86; |
---|
| 213 | double EnergyDistrShild = 32; |
---|
| 214 | double EnergyDistrEngine = 50; |
---|
| 215 | double EnergyDistrLaser = 18; |
---|
| 216 | double EnergyDistrShildInv = 100 - EnergyDistrShild; |
---|
| 217 | double EnergyDistrEngineInv = 100 - EnergyDistrEngine; |
---|
| 218 | double EnergyDistrLaserInv = 100 - EnergyDistrLaser; |
---|
| 219 | double EnergyDistrY = (double)EnergyDistrEngineInv/((double)EnergyDistrEngineInv+(double)EnergyDistrLaserInv) * EnergyDistrPixelY; |
---|
| 220 | double EnergyDistrX = EnergyDistrY/1.7321; |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | OverlayElement* EnergyDistrPoint = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint"); |
---|
| 225 | // EnergyDistrPoint->setLeft(); |
---|
| 226 | // EnergyDistrPoint->setTop(); |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | void createScene(void) |
---|
| 242 | { |
---|
| 243 | // Set a very low level of ambient lighting |
---|
| 244 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1)); |
---|
| 245 | |
---|
| 246 | // Use the "Space" skybox |
---|
| 247 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); |
---|
| 248 | |
---|
| 249 | // Load ogre head |
---|
| 250 | // Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
| 251 | |
---|
| 252 | // Attach the head to the scene |
---|
| 253 | // mSceneMgr->getRootSceneNode()->attachObject(head); |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | // show overlay |
---|
| 257 | helloOverlay = OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); |
---|
| 258 | update(); |
---|
| 259 | helloOverlay->show(); |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | /* |
---|
| 267 | // Create nodes for the lights to be rotated with |
---|
| 268 | mRedYellowLightsNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
| 269 | mGreenBlueLightsNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | // First create the BillboardSets. This will define the materials for the billboards |
---|
| 273 | // in its set to use |
---|
| 274 | mRedYellowLights = mSceneMgr->createBillboardSet("RedYellowLights"); |
---|
| 275 | mRedYellowLights->setMaterialName("Examples/Flare"); |
---|
| 276 | mRedYellowLightsNode->attachObject(mRedYellowLights); |
---|
| 277 | |
---|
| 278 | mGreenBlueLights = mSceneMgr->createBillboardSet("GreenBlueLights"); |
---|
| 279 | mGreenBlueLights->setMaterialName("Examples/Flare"); |
---|
| 280 | mGreenBlueLightsNode->attachObject(mGreenBlueLights); |
---|
| 281 | |
---|
| 282 | // Red light billboard, in "off" state |
---|
| 283 | Vector3 redLightPosition(78, -8, -70); |
---|
| 284 | mRedLightBoard = mRedYellowLights->createBillboard(redLightPosition); |
---|
| 285 | mRedLightBoard->setColour(ColourValue::Black); |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | // Blue light billboard, in "off" state |
---|
| 289 | Vector3 blueLightPosition(-90, -8, -70); |
---|
| 290 | mBlueLightBoard = mGreenBlueLights->createBillboard(blueLightPosition); |
---|
| 291 | mBlueLightBoard->setColour(ColourValue::Black); |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | // Yellow light billboard, in "off" state |
---|
| 295 | Vector3 yellowLightPosition(-4.5, 30, -80); |
---|
| 296 | mYellowLightBoard = mRedYellowLights->createBillboard(yellowLightPosition); |
---|
| 297 | mYellowLightBoard->setColour(ColourValue::Black); |
---|
| 298 | |
---|
| 299 | // Green light billboard, in "off" state |
---|
| 300 | Vector3 greenLightPosition(50, 70, 80); |
---|
| 301 | mGreenLightBoard = mGreenBlueLights->createBillboard(greenLightPosition); |
---|
| 302 | mGreenLightBoard->setColour(ColourValue::Black); |
---|
| 303 | |
---|
| 304 | // Red light, in "off" state |
---|
| 305 | mRedLight = mSceneMgr->createLight("RedFlyingLight"); |
---|
| 306 | mRedLight->setType(Light::LT_POINT); |
---|
| 307 | mRedLight->setPosition(redLightPosition); |
---|
| 308 | mRedLight->setDiffuseColour(ColourValue::Black); |
---|
| 309 | mRedYellowLightsNode->attachObject(mRedLight); |
---|
| 310 | |
---|
| 311 | // Blue light, in "off" state |
---|
| 312 | mBlueLight = mSceneMgr->createLight("BlueFlyingLight"); |
---|
| 313 | mBlueLight->setType(Light::LT_POINT); |
---|
| 314 | mBlueLight->setPosition(blueLightPosition); |
---|
| 315 | mBlueLight->setDiffuseColour(ColourValue::Black); |
---|
| 316 | mGreenBlueLightsNode->attachObject(mBlueLight); |
---|
| 317 | |
---|
| 318 | // Yellow light in "off" state |
---|
| 319 | mYellowLight = mSceneMgr->createLight("YellowFlyingLight"); |
---|
| 320 | mYellowLight->setType(Light::LT_POINT); |
---|
| 321 | mYellowLight->setPosition(yellowLightPosition); |
---|
| 322 | mYellowLight->setDiffuseColour(ColourValue::Black); |
---|
| 323 | mRedYellowLightsNode->attachObject(mYellowLight); |
---|
| 324 | |
---|
| 325 | // Yellow light in "off" state |
---|
| 326 | mGreenLight = mSceneMgr->createLight("GreenFlyingLight"); |
---|
| 327 | mGreenLight->setType(Light::LT_POINT); |
---|
| 328 | mGreenLight->setPosition(greenLightPosition); |
---|
| 329 | mGreenLight->setDiffuseColour(ColourValue::Black); |
---|
| 330 | mGreenBlueLightsNode->attachObject(mGreenLight); |
---|
| 331 | |
---|
| 332 | // Light flashers |
---|
| 333 | mRedLightFlasher = ControllerValueRealPtr( |
---|
| 334 | new LightFlasher(mRedLight, mRedLightBoard, ColourValue::Red)); |
---|
| 335 | mBlueLightFlasher = ControllerValueRealPtr( |
---|
| 336 | new LightFlasher(mBlueLight, mBlueLightBoard, ColourValue::Blue)); |
---|
| 337 | mYellowLightFlasher = ControllerValueRealPtr( |
---|
| 338 | new LightFlasher(mYellowLight, mYellowLightBoard, ColourValue(1.0, 1.0, 0.0))); |
---|
| 339 | mGreenLightFlasher = ControllerValueRealPtr( |
---|
| 340 | new LightFlasher(mGreenLight, mGreenLightBoard, ColourValue::Green)); |
---|
| 341 | |
---|
| 342 | // Light controller functions |
---|
| 343 | mRedLightControllerFunc = ControllerFunctionRealPtr( |
---|
| 344 | new LightFlasherControllerFunction(Ogre::WFT_SINE, 0.5, 0.0)); |
---|
| 345 | mBlueLightControllerFunc = ControllerFunctionRealPtr( |
---|
| 346 | new LightFlasherControllerFunction(Ogre::WFT_SINE, 0.75, 0.5)); |
---|
| 347 | mYellowLightControllerFunc = ControllerFunctionRealPtr( |
---|
| 348 | new LightFlasherControllerFunction(Ogre::WFT_TRIANGLE, 0.25, 0.0)); |
---|
| 349 | mGreenLightControllerFunc = ControllerFunctionRealPtr( |
---|
| 350 | new LightFlasherControllerFunction(Ogre::WFT_SINE, 0.25, 0.5)); |
---|
| 351 | |
---|
| 352 | // Light controllers |
---|
| 353 | ControllerManager* mControllerManager = &ControllerManager::getSingleton(); |
---|
| 354 | mRedLightController = mControllerManager->createController(mControllerManager->getFrameTimeSource(), mRedLightFlasher, mRedLightControllerFunc); |
---|
| 355 | mBlueLightController = mControllerManager->createController(mControllerManager->getFrameTimeSource(), mBlueLightFlasher, mBlueLightControllerFunc); |
---|
| 356 | mYellowLightController = mControllerManager->createController(mControllerManager->getFrameTimeSource(), mYellowLightFlasher, mYellowLightControllerFunc); |
---|
| 357 | mGreenLightController = mControllerManager->createController(mControllerManager->getFrameTimeSource(), mGreenLightFlasher, mGreenLightControllerFunc); |
---|
| 358 | |
---|
| 359 | */ |
---|
| 360 | |
---|
| 361 | // setupTrailLights(); |
---|
| 362 | |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | void setupTrailLights(void) |
---|
| 366 | { |
---|
| 367 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
| 368 | Vector3 dir(-1, -1, 0.5); |
---|
| 369 | dir.normalise(); |
---|
| 370 | Light* l = mSceneMgr->createLight("light1"); |
---|
| 371 | l->setType(Light::LT_DIRECTIONAL); |
---|
| 372 | l->setDirection(dir); |
---|
| 373 | |
---|
| 374 | NameValuePairList pairList; |
---|
| 375 | pairList["numberOfChains"] = "2"; |
---|
| 376 | pairList["maxElements"] = "80"; |
---|
| 377 | RibbonTrail* trail = static_cast<RibbonTrail*>( |
---|
| 378 | mSceneMgr->createMovableObject("1", "RibbonTrail", &pairList)); |
---|
| 379 | trail->setMaterialName("Examples/LightRibbonTrail"); |
---|
| 380 | trail->setTrailLength(400); |
---|
| 381 | |
---|
| 382 | |
---|
| 383 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(trail); |
---|
| 384 | |
---|
| 385 | // Create 3 nodes for trail to follow |
---|
| 386 | SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
| 387 | animNode->setPosition(50,30,0); |
---|
| 388 | Animation* anim = mSceneMgr->createAnimation("an1", 14); |
---|
| 389 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
| 390 | NodeAnimationTrack* track = anim->createNodeTrack(1, animNode); |
---|
| 391 | TransformKeyFrame* kf = track->createNodeKeyFrame(0); |
---|
| 392 | kf->setTranslate(Vector3(50,30,0)); |
---|
| 393 | kf = track->createNodeKeyFrame(2); |
---|
| 394 | kf->setTranslate(Vector3(100, -30, 0)); |
---|
| 395 | kf = track->createNodeKeyFrame(4); |
---|
| 396 | kf->setTranslate(Vector3(120, -100, 150)); |
---|
| 397 | kf = track->createNodeKeyFrame(6); |
---|
| 398 | kf->setTranslate(Vector3(30, -100, 50)); |
---|
| 399 | kf = track->createNodeKeyFrame(8); |
---|
| 400 | kf->setTranslate(Vector3(-50, 30, -50)); |
---|
| 401 | kf = track->createNodeKeyFrame(10); |
---|
| 402 | kf->setTranslate(Vector3(-150, -20, -100)); |
---|
| 403 | kf = track->createNodeKeyFrame(12); |
---|
| 404 | kf->setTranslate(Vector3(-50, -30, 0)); |
---|
| 405 | kf = track->createNodeKeyFrame(14); |
---|
| 406 | kf->setTranslate(Vector3(50,30,0)); |
---|
| 407 | |
---|
| 408 | AnimationState* animState = mSceneMgr->createAnimationState("an1"); |
---|
| 409 | animState->setEnabled(true); |
---|
| 410 | mAnimStateList.push_back(animState); |
---|
| 411 | |
---|
| 412 | trail->setInitialColour(0, 1.0, 0.8, 0); |
---|
| 413 | trail->setColourChange(0, 0.5, 0.5, 0.5, 0.5); |
---|
| 414 | trail->setInitialWidth(0, 5); |
---|
| 415 | trail->addNode(animNode); |
---|
| 416 | |
---|
| 417 | // Add light |
---|
| 418 | Light* l2 = mSceneMgr->createLight("l2"); |
---|
| 419 | l2->setDiffuseColour(trail->getInitialColour(0)); |
---|
| 420 | animNode->attachObject(l2); |
---|
| 421 | |
---|
| 422 | // Add billboard |
---|
| 423 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1); |
---|
| 424 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0)); |
---|
| 425 | bbs->setMaterialName("Examples/Flare"); |
---|
| 426 | animNode->attachObject(bbs); |
---|
| 427 | |
---|
| 428 | animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
| 429 | animNode->setPosition(-50,100,0); |
---|
| 430 | anim = mSceneMgr->createAnimation("an2", 10); |
---|
| 431 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
| 432 | track = anim->createNodeTrack(1, animNode); |
---|
| 433 | kf = track->createNodeKeyFrame(0); |
---|
| 434 | kf->setTranslate(Vector3(-50,100,0)); |
---|
| 435 | kf = track->createNodeKeyFrame(2); |
---|
| 436 | kf->setTranslate(Vector3(-100, 150, -30)); |
---|
| 437 | kf = track->createNodeKeyFrame(4); |
---|
| 438 | kf->setTranslate(Vector3(-200, 0, 40)); |
---|
| 439 | kf = track->createNodeKeyFrame(6); |
---|
| 440 | kf->setTranslate(Vector3(0, -150, 70)); |
---|
| 441 | kf = track->createNodeKeyFrame(8); |
---|
| 442 | kf->setTranslate(Vector3(50, 0, 30)); |
---|
| 443 | kf = track->createNodeKeyFrame(10); |
---|
| 444 | kf->setTranslate(Vector3(-50,100,0)); |
---|
| 445 | |
---|
| 446 | animState = mSceneMgr->createAnimationState("an2"); |
---|
| 447 | animState->setEnabled(true); |
---|
| 448 | mAnimStateList.push_back(animState); |
---|
| 449 | |
---|
| 450 | trail->setInitialColour(1, 0.0, 1.0, 0.4); |
---|
| 451 | trail->setColourChange(1, 0.5, 0.5, 0.5, 0.5); |
---|
| 452 | trail->setInitialWidth(1, 5); |
---|
| 453 | trail->addNode(animNode); |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | // Add light |
---|
| 457 | l2 = mSceneMgr->createLight("l3"); |
---|
| 458 | l2->setDiffuseColour(trail->getInitialColour(1)); |
---|
| 459 | animNode->attachObject(l2); |
---|
| 460 | |
---|
| 461 | // Add billboard |
---|
| 462 | bbs = mSceneMgr->createBillboardSet("bb2", 1); |
---|
| 463 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1)); |
---|
| 464 | bbs->setMaterialName("Examples/Flare"); |
---|
| 465 | animNode->attachObject(bbs); |
---|
| 466 | |
---|
| 467 | |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | void createFrameListener(void) |
---|
| 471 | { |
---|
| 472 | // This is where we instantiate our own frame listener |
---|
| 473 | mFrameListener= new LightingListener(mWindow, mCamera); |
---|
| 474 | mFrameListener->showDebugOverlay(false); |
---|
| 475 | mRoot->addFrameListener(mFrameListener); |
---|
| 476 | |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | }; |
---|