ogre numberic value animation demo(using MFC)

来源:互联网 发布:小米note刷windows 编辑:程序博客网 时间:2024/04/29 23:19
  1. First, create a new Ogre MFC application named NumericValueAnimation, by following the Creating an MFC Ogre application recipe from Chapter 1.
  2. Create a light in CNumericValueAnimation::EngineSetup named AnimatedLight.
    Ogre::NumericKeyFrame* kf;Ogre::Light *Light = SceneManager->createLight("AnimatedLight");
  3. Next, create an AnimableValuePtr for the named value diffuseColour, and set the initial value.
    Ogre::AnimableValuePtr animableValue = Light-> createAnimableValue("diffuseColour");animableValue->setValue(lightInitialColor);animableValue->setCurrentStateAsBaseValue ();
  4. Next, create an animation named AnimateValue with a duration of 5 seconds.
    Ogre::Animation *Animation = SceneManager-> createAnimation("AnimateValue", 5);
  5. Create a NumericAnimationTrack, and associate it with AnimableValue that we created.
    Ogre::NumericAnimationTrack *track = Animation-> createNumericTrack(0, animableValue);
  6. Next, create key frames for each time index, and set the values for each key frame to a varying color of red.
    float colourValue = 0.0;for(int i = 1; i <= 1000; i++){kf = track->createNumericKeyFrame(i * 0.025);colourValue = colourValue + 0.01;kf->setValue( Ogre::AnyNumeric(Ogre::ColourValue (colourValue, 0.0, 0.0, 1.0)) );}
  7. Start a timer, and add a timer event handler named OnTimer. In the timer function, get the value from the next NumericKeyFrame, and set the background color of the viewport to the same color value as the light.
    Ogre::Animation *Animation = SceneManager-> getAnimation("AnimateValue");Ogre::NumericAnimationTrack *track = Animation-> getNumericTrack(0);Ogre::NumericKeyFrame *frame = track-> getNumericKeyFrame(m_TimeIndex++);Ogre::AnyNumeric value = frame->getValue();Ogre::ColourValue color = Ogre::any_cast <Ogre::ColourValue>(value);Viewport->setBackgroundColour(color);Root->renderOneFrame();

How it works...

The attribute we change in this recipe is the light diffuse color. When we create the key frames, we store a new color in each key frame. The key frame setValue() function only accepts a value of type AnyNumeric, so we must cast our color value to this type first. Then, when the timer function is run, we get the value for the current key frame, and set the background color with that value. The starting background color starts out black and ends bright red.

How it works...

The final frame has a bright red background.

How it works...
原创粉丝点击