粒子系统

来源:互联网 发布:zcash 挖矿 linux 编辑:程序博客网 时间:2024/05/29 16:15

粒子系统

载入粒子系统模板

代码如下

[cpp] view plain copy
  1. ParticleSystem* ps; //声明一个粒子系统  
  2. //两个参数分别是新建粒子系统的名称(自己取)和载入的粒子系统模板名称  
  3. ps = mSceneMgr->createParticleSystem("Fireworks""Examples/Fireworks");  
  4. 绑定到节点上  
  5. mSceneMgr->getRootSceneNode()->attachObject(ps);  

粒子系统模板格式如下,是一些参数的设定,

[plain] view plain copy
  1. particle_system Examples/Swarm  
  2. {  
  3.     quota   3000  
  4.     material    Examples/Flare2  
  5.     particle_width  12  
  6.     particle_height 24  
  7.     cull_each   true  
  8.     renderer    billboard  
  9.     sorted  true  
  10.     local_space false  
  11.     billboard_type  oriented_self  
  12.   
  13.     emitter Box  
  14.     {  
  15.         angle   180  
  16.         colour  1 1 1 1  
  17.         colour_range_start  1 1 1 1  
  18.         colour_range_end    1 1 1 1  
  19.         direction   0 1 0  
  20.         emission_rate   30  
  21.         position    0 0 0  
  22.         velocity    50  
  23.         velocity_min    50  
  24.         velocity_max    1  
  25.         time_to_live    20  
  26.         time_to_live_min    20  
  27.         time_to_live_max    20  
  28.         duration    0  
  29.         duration_min    0  
  30.         duration_max    0  
  31.         repeat_delay    0  
  32.         repeat_delay_min    0  
  33.         repeat_delay_max    0  
  34.         width   80  
  35.         height  80  
  36.         depth   80  
  37.     }  
  38.   
  39.     affector ColourFader  
  40.     {  
  41.         red -0.05  
  42.         green   0  
  43.         blue    0  
  44.         alpha   0  
  45.     }  
  46.   
  47.     affector DeflectorPlane  
  48.     {  
  49.         plane_point 0 -50 0  
  50.         plane_normal    0 1 0  
  51.         bounce  1  
  52.     }  
  53.   
  54.     affector DeflectorPlane  
  55.     {  
  56.         plane_point 0 50 0  
  57.         plane_normal    0 -1 0  
  58.         bounce  1  
  59.     }  
  60.   
  61.     affector DeflectorPlane  
  62.     {  
  63.         plane_point 50 0 0  
  64.         plane_normal    -1 0 0  
  65.         bounce  1  
  66.     }  
  67.   
  68.     affector DeflectorPlane  
  69.     {  
  70.         plane_point -50 0 0  
  71.         plane_normal    1 0 0  
  72.         bounce  1  
  73.     }  
  74.   
  75.     affector DeflectorPlane  
  76.     {  
  77.         plane_point 0 0 50  
  78.         plane_normal    0 0 -1  
  79.         bounce  1  
  80.     }  
  81.   
  82.     affector DeflectorPlane  
  83.     {  
  84.         plane_point 0 0 -50  
  85.         plane_normal    0 0 1  
  86.         bounce  1  
  87.     }  
  88.   
  89.     affector DirectionRandomiser  
  90.     {  
  91.         randomness  60  
  92.     }  
  93. }  
Ogre内有Fireworks, Rain, Fountain,Aureola,Nimbus,Snow, JetEngine等粒子系统模板,非常漂亮


节点轨迹跟踪

如果是需要显示物体的运动轨迹,可以使用RibbonTrail类来实现,首先是创建一个RibbonTrail实例,然后把节点添加给RibbonTrail,要注意的是参数numberOfChains限定了可以添加的node数量。
[cpp] view plain copy
  1. Ogre::NameValuePairList params;  
  2. params["numberOfChains"] = "1";  
  3. params["maxElements"] = "80";  
  4. Ogre::RibbonTrail* m_pRocketTrail = static_cast<RibbonTrail*>(m_pSceneMgr->createMovableObject("RibbonTrail", &params));  
  5. m_pRocketTrail->setMaterialName("Examples/LightRibbonTrail");  
  6. m_pRocketTrail->setTrailLength(20);  
  7. m_pRocketTrail->setVisible(false);  
  8. m_pSceneMgr->getRootSceneNode()->attachObject(m_pRocketTrail);  
  9. m_pRocketTrail->setInitialColour(0, 1, 0.8, 0);  
  10. m_pRocketTrail->setColourChange(0, 0.75, 1.25, 1.25, 1.25);  
  11. m_pRocketTrail->setWidthChange(0, 1);  
  12. m_pRocketTrail->setInitialWidth(0, 0.5);  

[cpp] view plain copy
  1. m_pRocketTrail->setVisible(true);  
  2. m_pRocketTrail->addNode(m_pRocket->getParentNode());  
原创粉丝点击