Ogre overlay实现帧动画

 

ogre Dome上有动态纹理的效果演示,这里讲的不是移动或旋转纹理坐标产生的纹理动态效果,而是由几张图片更换显示产生的动画效果,这种效果在2d中指的是帧动画。首先要准备好一组图片,如animotion1.jpg, animotion2.jpg, animotion3.jpg, animotion4.jpg. ogre的材质的Texture-Uint中有anim_texture这个属性(可以参考ogre中文帮助手册),它是专门为作帧动画准备的。接着定义一个简单的overlay, 以下是我的简单定义:

howlet/BigMapOverlay
{
    zorder 0
    container Panel (bigMap)
       {
           horz_align left
           vert_align top
           metrics_mode relative
           left 0
           top 0
           width 1
           height 1

    element Panel (BigMap/Player)
           {
               horz_align left
               vert_align top
               metrics_mode pixels 
               left 0
               top  0
               width 20
               height 20

               material BigMap/Player
 }

material BigMap/Player的定义:

material BigMap/Player
{
    technique
    {
       pass
       {
         alpha_rejection greater 128 
         scene_blend alpha_blend

           texture_unit        //人物方向图标
           {
               tex_address_mode clamp
           }
       }
    }
}

然后我们通过TextureUnitState* pTexUint = OverlayManager::getSingleton().getOverlayElement(“BigMap/Player”)->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0);就可以得到当前的texture_unit 也就是material BigMap/Player中的纹理。

接下来定义图片数组名:const Ogre::String animotion[4]  = {"animotion1.jpg", "animotion2.jpg", "animotion3.jpg", "animotion4.jpg"}; 注意这4张代表的是不同的图片名字。

最后通过TextureUnitState::setAnimatedTextureName(const String* const names, unsigned int numFrames, Real duration = 0)可以直接设置动画。在我们这里是pTexUint->setAnimatedTextureName(animotion, 4, 4*0.1);就这样,简单得实现了动画效果。

setAnimatedTextureName这个函数可以参考官方说明。

转载或修改请说明出处: http://blog.csdn.net/howlet2/archive/2009/11/19/4835061.aspx 
作者:  howlet
E-Mial: howlet3@126.com

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/howlet2/archive/2009/11/19/4835061.aspx

原文地址:https://www.cnblogs.com/minggoddess/p/1910152.html