• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿

            剛給引擎設(shè)備新加了一個函數(shù)GetLuaStateOwner();
            用于獲取引擎中的lua上下文
            看起來似乎沒多大必要但是我有自己的考慮!

            另外:我修改了粒子腳本
            如下:

              1 
              2 -- 這是蓋莫引擎中使用lua腳本的測試粒子
              3 
              4 -- 定義粒子池粒子個數(shù)
              5 max_particles = 5000
              6 
              7 -- 定義粒子初始位置
              8 particle_position = 
              9 
             10    xpos = 0;
             11    ypos = 0;
             12    zpos = 4;
             13 }
             14 
             15 -- 定義粒子大小
             16 particle_size = 0.7
             17 
             18 -- 定義粒子壽命
             19 particle_life = 9
             20 
             21 -- 定義粒子批大小
             22 batch_particles = 100
             23  
             24 friction = 0.75
             25  
             26 fountain_radius = 1.8
             27 particle_r = (fountain_radius + particle_size/2)*(fountain_radius + particle_size/2)
             28  
             29 -- 定義粒子速度
             30 particle_vel = 8.0
             31  
             32 function GetVelByTime(t)
             33     return particle_vel*(0.6 + 0.1*(math.sin(0.5*t)+math.sin(0.31*t)));
             34 end
             35 function InitZVel()
             36     return 0.5 + (0.3/4096.0* (math.random(1,4095));
             37 end
             38 local function GetRandRotXY()
             39     return (2.0*3.14159265/4096.0* math.random(1,4095)
             40 end    
             41 function InitXVel(t)
             42    xy_angle = GetRandRotXY();
             43    vt = GetVelByTime(t);
             44    return 0.4 * math.cos(xy_angle)*vt;
             45 end
             46 function InitYVel(t)
             47    xy_angle = GetRandRotXY();
             48    vt = GetVelByTime(t);
             49    return 0.4 * math.sin(xy_angle)*vt;
             50 end
             51 
             52 -- 粒子位置
             53 xpos = particle_position[xpos];
             54 ypos = particle_position[ypos];
             55 zpos = particle_position[zpos];
             56  
             57 function InitPosition()
             58    xpos = 2*(particle_position.xpos + 1-math.random());
             59    ypos = 3*(particle_position.ypos + 1-math.random());
             60    zpos = particle_position.zpos  + math.random() - 1
             61 end 
             62  
             63 function InitColorRed(t)
             64     return 0.7 + 0.3 * math.sin(0.34*+ 0.1);
             65 end
             66 function InitColorGreen(t)
             67     return 0.6 + 0.4 * math.sin(0.63*+ 1.1);
             68 end
             69 function InitColorBlue(t)
             70     return 0.6 + 0.4 * math.sin(0.91*+ 2.1);
             71 end
             72  
             73 red = 0;
             74 green = 0;
             75 blue = 0;
             76 xvel = 0;
             77 yvel = 0;
             78 zvel = 0;
             79  
             80 function InitParticle(t)
             81    InitPosition(); 
             82    red = InitColorRed(t);
             83    green = InitColorGreen(t);
             84    blue = InitColorBlue(t);
             85    zvel = InitZVel();
             86    xvel = InitXVel(t);
             87    yvel = InitYVel(t);
             88 end
             89  
             90 new_life = 1;
             91 new_xpos = 0;
             92 new_ypos = 0;
             93 new_zpos = 0;
             94 new_xvel = 1;
             95 new_yvel = 1;
             96 new_zvel = 1;
             97 new_red  = 0.2;
             98 new_green = 0.3;
             99 new_blue  = 0.2;
            100 
            101 
            102 -- 更新更新粒子顏色
            103 function UpdateColor(red,green,blue)
            104    if red > 0.2 or red < 0.2 then
            105       red = red - (red - 0.2)*1/99.0;
            106       if red > 1 or red < 0 then
            107          red = 0.5;
            108          new_red = red;
            109       end
            110    end  
            111    new_red = red;   
            112    new_green = green;
            113    new_blue = blue;            
            114 end
            115   
            116 -- 更新粒子狀態(tài)
            117 function UpdateParticles(life,xpos,ypos,zpos,xvel,yvel,zvel,dt)
            118    -- 修正粒子生命 
            119    new_life = life - dt * (1.0 / particle_life);
            120    -- 修正粒子速度 
            121    new_zvel = zvel;
            122    new_xpos = xpos + xvel*dt/8*(math.random()-0.5);
            123    new_ypos = ypos + yvel*dt/8*(math.random()-0.5);
            124    new_zpos = zpos + new_zvel*dt;        
            125 end
            126 
            127 
            128 
            在粒子初始化中,我讓粒子的初始位置保持在一個盒子當(dāng)中,這樣其效果就相當(dāng)于irr中的粒子盒狀發(fā)射器了。
            在粒子更新中變動粒子顏色,修改粒子生命和粒子位置,或者粒子速度
            其c++代碼如下:
              1 
              2 #include <GEngine/Main.hpp>
              3 #include <luaplus/luaplus.h>
              4 
              5 #define WIN_WIDTH  640
              6 #define WIN_HEIGHT 480
              7  
              8 ////////////////////////////////////////////////////////////
              9 /// 給出一個初始化粒子的方法 
             10 ////////////////////////////////////////////////////////////
             11 void G_CALL InitParticle(core::Particle* p,float t);
             12 
             13 ////////////////////////////////////////////////////////////
             14 /// 更新粒子函數(shù) 
             15 ////////////////////////////////////////////////////////////
             16 void G_CALL UpdateParticle(core::Particle* p,float time);
             17 
             18 ////////////////////////////////////////////////////////////
             19 /// 場景旋轉(zhuǎn)和偏移 
             20 //////////////////////////////////////////////////////////// 
             21 float TransForm(double t);
             22  
             23 ////////////////////////////////////////////////////////////
             24 /// 渲染場景 
             25 //////////////////////////////////////////////////////////// 
             26 void RenderScene(); 
             27 
             28 core::Device* device = NULL; 
             29 
             30 LuaPlus::LuaStateOwner *state = NULL; 
             31   
             32 ////////////////////////////////////////////////////////////
             33 /// 初始化luaplus  
             34 ////////////////////////////////////////////////////////////     
             35 void InitLua(const char* lua)
             36 {    
             37     state = device->GetLuaStateOwner();
             38     // 載入Lua腳本
             39     (*state)->DoFile(lua);  
             40 }  
             41  
             42 ////////////////////////////////////////////////////////////
             43 /// 從腳本載入粒子描述數(shù)據(jù) 
             44 //////////////////////////////////////////////////////////// 
             45 void LoadData(core::ParticleSystemDesc &desc); 
             46  
             47 int main(int argc, char **argv)
             48 {
             49     int        i;
             50     double     t0, t;
             51     
             52     core::VideoMode mode;
             53     mode.width = WIN_WIDTH;
             54     mode.height = WIN_HEIGHT; 
             55     
             56     device = core::InitDevice("蓋莫引擎粒子系統(tǒng)",false,mode); 
             57     InitLua("..\\script\\particle.lua");
             58     
             59     //! 獲取資源管理器 
             60     core::ResourceManager* resourcemanager = device->GetResourceManager();
             61     core::RefPtr<core::Image> particleimage = resourcemanager->GetImage("particle","..\\image//particle//flare.bmp"); 
             62     core::RefPtr<core::Texture> particletexture = resourcemanager->GetTexture("particle",particleimage); 
             63     particletexture->Bind(); 
             64      
             65     core::ParticleSystemDesc desc;
             66     desc.texture_id = particletexture->GetTextureId();    
             67     desc.init_fn = &InitParticle;
             68     desc.update_fn = &UpdateParticle;
             69     LoadData(desc);
             70     core::ParticleSystem* ps = device->GetParticleSystem(desc); 
             71  
             72     t0 = device->GetTime();
             73     BEGIN_LOOP(device)
             74         t = device->GetTime() - t0;
             75         RenderScene();
             76         float dt = TransForm(t);
             77         ps->Render(); 
             78     END_LOOP(device)
             79     
             80     device->Close();
             81     device->Drop();
             82  
             83     return 0;
             84 }
             85  
             86 ////////////////////////////////////////////////////////////
             87 /// 場景旋轉(zhuǎn)和偏移 
             88 //////////////////////////////////////////////////////////// 
             89 float TransForm(double t)
             90 {
             91     double xpos, ypos, zpos, angle_x, angle_y, angle_z;
             92     static double t_old = 0.0;
             93     float  dt = (float)(t-t_old);
             94     t_old = t;
             95  
             96     angle_x = 90.0 - 10.0;
             97     angle_y = 10.0 * sin( 0.3 * t );
             98     angle_z = 10.0 * t;
             99     glRotated( -angle_x, 1.00.00.0 );
            100     glRotated( -angle_y, 0.01.00.0 );
            101     glRotated( -angle_z, 0.00.01.0 );
            102  
            103     xpos =  15.0 * sin( (M_PI/180.0* angle_z ) +
            104              2.0 * sin( (M_PI/180.0* 3.1 * t );
            105     ypos = -15.0 * cos( (M_PI/180.0* angle_z ) +
            106              2.0 * cos( (M_PI/180.0* 2.9 * t );
            107     zpos = 4.0 + 2.0 * cos( (M_PI/180.0* 4.9 * t );
            108     glTranslated( -xpos, -ypos, -zpos );
            109     return dt; 
            110 }
            111 
            112 void RenderScene()
            113 {
            114     glViewport( 00, WIN_WIDTH,WIN_HEIGHT);
            115     glClearColor( 0.1f0.1f0.1f1.0f );
            116     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
            117     glMatrixMode( GL_PROJECTION );
            118     glLoadIdentity();
            119     gluPerspective(65.0640.0/480.01.060.0 );
            120     glMatrixMode( GL_MODELVIEW );
            121     glLoadIdentity();
            122 }
            123 
            124 ////////////////////////////////////////////////////////////
            125 /// 給出一個初始化粒子的方法(t為粒子系統(tǒng)啟動時間(單位:秒)) 
            126 ////////////////////////////////////////////////////////////
            127 void G_CALL InitParticle(core::Particle* p,float t)
            128 {
            129     //! 初始化粒子位置位置
            130     LuaPlus::LuaFunction<void> initpos(*state,"InitParticle");
            131     initpos(t);
            132     
            133     float xpos =(*state)->GetGlobal("xpos").GetFloat(); //GetByName("xpos").
            134     float ypos =(*state)->GetGlobal("ypos").GetFloat();
            135     float zpos =(*state)->GetGlobal("zpos").GetFloat();
            136     p->position = Vector3f(xpos,ypos,zpos); 
            137     
            138     //! 初始化粒子顏色 
            139     p->color.red = (*state)->GetGlobal("red").GetFloat(); 
            140     p->color.green = (*state)->GetGlobal("green").GetFloat();
            141     p->color.blue = (*state)->GetGlobal("blue").GetFloat();
            142     
            143     //! 初始化粒子初始速度 
            144     float xvel =(*state)->GetGlobal("xvel").GetFloat();
            145     float yvel =(*state)->GetGlobal("yvel").GetFloat();
            146     float zvel =(*state)->GetGlobal("zvel").GetFloat();    
            147     p->velocity = Vector3f(xvel,yvel,zvel);
            148 }
            149 
            150 ////////////////////////////////////////////////////////////
            151 /// 更新粒子函數(shù) 
            152 ////////////////////////////////////////////////////////////
            153 void G_CALL UpdateParticle(core::Particle* p,float time)
            154 {
            155     LuaPlus::LuaFunction<void> update_fn(*state,"UpdateParticles");  
            156     float life = p->life;
            157     float xpos = p->position.x;
            158     float ypos = p->position.y;
            159     float zpos = p->position.z;
            160     float xvel = p->velocity.x;
            161     float yvel = p->velocity.y;
            162     float zvel = p->velocity.z;
            163     update_fn(life,xpos,ypos,zpos,xvel,yvel,zvel,time); 
            164     
            165     //! 獲取更新后的粒子顏色
            166     LuaPlus::LuaFunction<void> update_color(*state,"UpdateColor");
            167     update_color(p->color.red,p->color.green,p->color.blue);
            168     
            169     p->color.red = (*state)->GetGlobal("new_red").GetFloat();  
            170     p->color.green = (*state)->GetGlobal("new_green").GetFloat();
            171     p->color.blue = (*state)->GetGlobal("new_blue").GetFloat();       
            172     
            173     //! 獲取粒子的更新后數(shù)據(jù) 
            174     p->life = (*state)->GetGlobal("new_life").GetFloat();  
            175     p->position.x = (*state)->GetGlobal("new_xpos").GetFloat(); 
            176     p->position.y = (*state)->GetGlobal("new_ypos").GetFloat(); 
            177     p->position.z = (*state)->GetGlobal("new_zpos").GetFloat(); 
            178     p->velocity.x = (*state)->GetGlobal("new_xvel").GetFloat();  
            179     p->velocity.y = (*state)->GetGlobal("new_yvel").GetFloat();  
            180     p->velocity.z = (*state)->GetGlobal("new_zvel").GetFloat();  
            181 
            182 
            183 ////////////////////////////////////////////////////////////
            184 /// 從腳本載入粒子描述數(shù)據(jù) 
            185 //////////////////////////////////////////////////////////// 
            186 void LoadData(core::ParticleSystemDesc &desc)
            187 {
            188     desc.batch_particles = (*state)->GetGlobal("batch_particles").GetInteger();
            189     desc.particle_size = (*state)->GetGlobal("particle_size").GetFloat(); 
            190     desc.life_span = (*state)->GetGlobal("particle_life").GetFloat(); 
            191     int max_particles = (*state)->GetGlobal("max_particles").GetInteger(); 
            192     desc.particle_number = max_particles;     
            193 }
            194 
            195 
            196 
            當(dāng)然代碼中沒有檢測錯誤和異常.
            其輸出圖形如下所示:

            另外一幅截圖

            看得使用蓋莫游戲引擎設(shè)計粒子效果足夠簡單吧
            最后上蓋莫引擎的logo(當(dāng)然這是題外圖O(∩_∩)O~)
            posted on 2010-02-25 13:39 ccsdu2009 閱讀(362) 評論(0)  編輯 收藏 引用 所屬分類: Game引擎
             
            伊人色综合久久天天人手人婷 | 久久99热这里只频精品6| 久久久精品日本一区二区三区| 亚洲国产成人精品女人久久久| 一本综合久久国产二区| 精品久久久久久无码中文字幕一区| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 亚洲第一永久AV网站久久精品男人的天堂AV | 欧美精品久久久久久久自慰| 国产成人精品久久免费动漫| 久久综合久久鬼色| 国内精品久久久久| 久久精品国产99久久久古代| 国产成人香蕉久久久久| 午夜精品久久久久久99热| 精品无码久久久久久国产| 欧美黑人又粗又大久久久| 热RE99久久精品国产66热| 久久福利青草精品资源站| 久久久久亚洲AV无码观看| 国产精品熟女福利久久AV| www.久久热.com| 久久人爽人人爽人人片AV| 97久久婷婷五月综合色d啪蜜芽| 欧美一区二区精品久久| 国产精品一区二区久久国产| 久久狠狠爱亚洲综合影院| 久久激情五月丁香伊人| 91精品国产91热久久久久福利| 77777亚洲午夜久久多喷| 亚洲伊人久久成综合人影院| 久久精品免费大片国产大片| 97超级碰碰碰碰久久久久| 国产精品久久久久…| 1000部精品久久久久久久久| 久久亚洲春色中文字幕久久久| 无码国产69精品久久久久网站| 精品一二三区久久aaa片| 久久久一本精品99久久精品88| 7777久久久国产精品消防器材| 99久久国产精品免费一区二区 |