Ogiror 中 Hydrax 插件的使用

来源:互联网 发布:2016手机赚钱软件大全 编辑:程序博客网 时间:2024/04/27 18:48

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://ogre3d.blogbus.com/logs/78454138.html

    最近因为工作原因研究了下Hydrax插件,这个插件非常不错,效果非常的好,可惜的就是效率不高,鸡肋!不过在游戏中这种大场景的水毕竟不是每个场景都存在,所以只要效率过得去就还算是可以的。将工作写成日志 记录我的工作。

 

Hydrax 插件的引导

pElement XMLNode ->first_node ("water" );        // 先通过XML 读取HYDRAX 插件是否存在

    if (pElement )

        processHydrax (pElement );

 

mHydraxHandle new Hydrax ::Hydrax (scenemgr , camera , mviewport );

mHydraxModule new Hydrax ::Module ::ProjectedGrid (// Hydrax parent pointer

        mHydraxHandle ,

        // Noise module

        new Hydrax ::Noise ::Perlin (/*Generic one*/ ),

        // Base plane

        Ogre ::Plane (Ogre ::Vector3 (0,1,0), Ogre ::Vector3 (0,0,0)),

        // Normal mode

        Hydrax ::MaterialManager ::NM_RTT ,// NM_VERTEX, NM_RTT  // 顶点模式

        // Projected grid options

        Hydrax ::Module ::ProjectedGrid ::Options (60)); 

 

//lee  读取水配置文件

mHydraxHandle ->loadCfg (XMLfilename );

// Create water

mHydraxHandle ->create ();

 

 

void DotSceneLoader::UpdataHydrax(float timePassed)  
{
 if (mHydraxHandle)
 {
  Ogre::Vector3 col = mHydraxHandle->getWaterColor();
  Ogre::Vector3 original = col;

  float height = mHydraxHandle->getSunPosition().y / 10.0f;

  if(height < -99.0f)
  {
   col = original * 0.1f;
   height = 9999.0f;
  }
  else if(height < 1.0f)
  {
   col = original * (0.1f + (0.009f * (height + 99.0f)));
   height = 100.0f / (height + 99.001f);
  }
  else if(height < 2.0f)
  {
   col += original;
   col /= 2.0f;
   float percent = (height - 1.0f);
   col = (col * percent) + (original * (1.0f - percent));
  }
  else
  {
   col += original;
   col /= 2.0f;
  }
  mHydraxHandle->setWaterColor(col);// 设置水颜色  
  mHydraxHandle->setSunArea(height);//根据水波 实现太阳在水面上的效果

  mHydraxHandle->update(timePassed);//实时更新 
 }
}

原创粉丝点击