dx粒子效果雪花飘

 

 

 

简单修改一下也能变成玻璃效果,天上掉玻璃了

 

主文件

Code:
  1. //  
  2. // 文件: main.cpp  
  3. // 作者:CYM  
  4. //  *雾特效,旋转的立方体,底面!~简单演示  
  5. //  *方向键控制摄像头  
  6. //  *shift使摄像头向上ctrl使摄像头向下  
  7. //  
  8. #include "D3DFrame.h"  
  9. #include "Box.h"  
  10. #include "Ground.h"  
  11. #include "Drawtext.h"  
  12. #include "Sprite.h"  
  13. #include <d3d9.h>  
  14. #include <d3dx9.h>  
  15.   
  16. void SetFogEffects(D3DCAPS9 caps,bool isFogEnable);     //设置雾效果函数声明  
  17.   
  18. //  
  19. // 全局设置  
  20. //  
  21.   
  22. IDirect3DDevice9* Device = 0;   //定义设备对象   
  23. IDirect3DTexture9*  Texture1;   //立方体纹理  
  24. IDirect3DTexture9*  Texture2;   //地面地图纹理  
  25. IDirect3DTexture9*  Texture3;   //简单的粒子文理纹理  
  26. LPD3DXFONT  Font;               //定义字体  
  27.   
  28. CD3DFrame Frame;    //定义框架类  
  29. CGround*    Ground=0;   //定义场地类  
  30. CBox*   Box1 = 0;   //定义Box对象  
  31. CBox*   Box2 = 0;  
  32. CDrawtext*  Text=0; //定义文字绘制对象  
  33. CSprite*    Point;  //定义sprite点对象  
  34.   
  35. D3DMATERIAL9 material;  
  36. D3DXMATRIX  Map;     //地图矩阵  
  37. D3DXMATRIX V;        //视图矩阵  
  38.   
  39. D3DXVECTOR3 Txyz1(-3,2,-3); //矩阵平移坐标  
  40. D3DXVECTOR3 Rxyz1(0,0,0);   //矩阵旋转坐标  
  41.   
  42. const int Width  = 640;     //窗口的宽高  
  43. const int Height = 480;  
  44.   
  45. static RECT FontRect={0,0,Width,Height};        //绘制文字的矩形  
  46.   
  47. static D3DXVECTOR3 position( 0.0f, 3.0f, 3.0f );        //摄像机位置  
  48. static D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);            //摄像机观察目标  
  49. static D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);                //摄像机高度  
  50.   
  51. //static D3DXVECTOR3 SpritePos(10.0f,10.0f,-10.0f);                         //Sprite点的坐标  
  52.   
  53. D3DCAPS9 caps;  //设备功能支持的结构体  
  54.   
  55. bool isFogEnable=true;  //判断雾效果是否开启  
  56. static float timeConversion=0.1f;   //时间转换(速度同步)数值  
  57.   
  58. //  
  59. // 框架函数  
  60. //  
  61. bool Setup()  
  62. {  
  63.     //创造对象  
  64.     Box1 = new CBox(Device);      
  65.     Box2 = new CBox(Device);      
  66.     Ground = new CGround(Device);  
  67.     Text = new CDrawtext(Device,Font);  
  68.     Point = new CSprite(Device);  
  69.   
  70.     Device->GetDeviceCaps(&caps);   //获取设备功能支持信息的结构体  
  71.   
  72.     //设置纹理  
  73.     //D3DMATERIAL9 material;  
  74.     ::ZeroMemory(&material, sizeof(material));  
  75.     material.Ambient=D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  76.     material.Diffuse=D3DXCOLOR(1.0f, 1.0f, 0.1f, 1.0f);  
  77.     material.Emissive=D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  78.     material.Power=0.1f;  
  79.     material.Specular=D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);  
  80.   
  81.     //设置平行光  
  82.     D3DLIGHT9 light;  
  83.     ::ZeroMemory(&light, sizeof(light));  
  84.     light.Type      = D3DLIGHT_DIRECTIONAL;  
  85.     light.Ambient   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  86.     light.Diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  87.     light.Specular  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  88.     light.Direction = D3DXVECTOR3(1.0f, -1.0f, 0.0f);  
  89.     Device->SetLight(0, &light);  
  90.     Device->LightEnable(0, true);  
  91.   
  92.     //设置平行光  
  93.     D3DLIGHT9 light2;  
  94.     ::ZeroMemory(&light2, sizeof(light2));  
  95.     light2.Type      = D3DLIGHT_DIRECTIONAL;  
  96.     light2.Ambient   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  97.     light2.Diffuse   = D3DXCOLOR(0.1f, 0.5f, 0.4f, 1.0f);  
  98.     light2.Specular  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
  99.     light2.Direction = D3DXVECTOR3(0.0f, 1.0f, 0.0f);  
  100.     Device->SetLight(1, &light2);  
  101.     Device->LightEnable(1, true);  
  102.   
  103.     Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);   //正常的渲染等级  
  104.     Device->SetRenderState(D3DRS_SPECULARENABLE, true);     //镜面高光  
  105.       
  106.   
  107.     D3DXMatrixLookAtLH(&V, &position, &target, &up);    //设置摄像机  
  108.     Device->SetTransform(D3DTS_VIEW, &V);               //视图转换  
  109.   
  110.     //  
  111.     // Create texture.  
  112.     //  
  113.     //载入立方体纹理  
  114.     D3DXCreateTextureFromFile(  
  115.         Device,  
  116.         "crate.jpg",  
  117.         &Texture1);  
  118.   
  119.     //载入地面纹理  
  120.     D3DXCreateTextureFromFile(  
  121.         Device,  
  122.         "河流.jpg",  
  123.         &Texture2);  
  124.   
  125.     D3DXCreateTextureFromFile(  
  126.         Device,  
  127.         "雪球.tga",  
  128.         &Texture3);  
  129.   
  130.     //   
  131.     // Set Texture Filter States.  
  132.     //  
  133.   
  134.     Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);  
  135.     Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);  
  136.     Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);  
  137.   
  138.     Device->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);  
  139.     Device->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);  
  140.     Device->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);  
  141.   
  142.     Device->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);  
  143.     Device->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);  
  144.     Device->SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);  
  145.   
  146.     //  
  147.     // Set the projection matrix.  
  148.     //  
  149.   
  150.     D3DXMATRIX proj;  
  151.     D3DXMatrixPerspectiveFovLH(  
  152.             &proj,  
  153.             D3DX_PI * 0.5f, // 90 - degree  
  154.             (float)Width / (float)Height,  
  155.             1.0f,  
  156.             1000.0f);  
  157.     Device->SetTransform(D3DTS_PROJECTION, &proj);  
  158.   
  159.     //设置雾效果  
  160.     SetFogEffects(caps,true);  
  161.   
  162.     Device->SetRenderState(D3DRS_LIGHTING,true);  
  163.     Device->SetRenderState(D3DRS_AMBIENT,D3DXCOLOR(0.3f,0.4f,0.5f,1.0f));  
  164.     Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);  // 不剔除任何面  
  165.   
  166.     return true;  
  167. }  
  168.   
  169. void Cleanup()  
  170. {  
  171.     Frame.Delete<CSprite*>(Point);  
  172.     Frame.Delete<CBox*>(Box2);  
  173.     Frame.Delete<CBox*>(Box1);  
  174.     Frame.Delete<CGround*>(Ground);  
  175.     Frame.Delete<CDrawtext*>(Text);  
  176.     Frame.Release<LPD3DXFONT>(Font);  
  177.     Frame.Release<IDirect3DTexture9*>(Texture3);  
  178.     Frame.Release<IDirect3DTexture9*>(Texture2);  
  179.     Frame.Release<IDirect3DTexture9*>(Texture1);  
  180. }  
  181.   
  182. //设置摄像机函数  
  183. void SetMatrixLookAt(D3DXMATRIX* V, D3DXVECTOR3* position, D3DXVECTOR3* target, D3DXVECTOR3* up)  
  184. {  
  185.     D3DXMatrixLookAtLH(V, position, target, up);    //设置摄像机  
  186.     Device->SetTransform(D3DTS_VIEW, V);                //视图转换  
  187. }  
  188.   
  189. //设置雾特效函数  
  190. void SetFogEffects(D3DCAPS9 caps,bool isFogEnable)  
  191. {  
  192.     // 雾特效的开始和结束距离数值  
  193.     float start = 12, end = 15;  
  194.     // 设置雾的相关属性  
  195.     Device->SetRenderState(D3DRS_FOGENABLE, isFogEnable);  // 启用雾效果  
  196.     // 设置要渲染的雾的期望颜色(这里为灰色)  
  197.     Device->SetRenderState(D3DRS_FOGCOLOR,D3DCOLOR_XRGB(128, 128, 128));  
  198.     // 使用顶点雾  
  199.     Device->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);  
  200.     // 指定雾的开始距离和终点距离  
  201.     Device->SetRenderState(D3DRS_FOGSTART, *(DWORD*)(&start));  
  202.     Device->SetRenderState(D3DRS_FOGEND, *(DWORD*)(&end));  
  203.     // Pixel Fog  像素雾  
  204.     //Device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);  
  205.     // 如果支持,则启用基于距离的雾  
  206.     if(caps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)  
  207.         Device->SetRenderState(D3DRS_RANGEFOGENABLE, true);  
  208. }  
  209.   
  210. //数值计算函数  
  211. bool Calculation(void)  
  212. {  
  213.   
  214.     //*start:立方体1(箱子)的矩阵变化数值计算  
  215.      Rxyz1.x+=0.005f;  
  216.      Rxyz1.y+=0.005f;  
  217.      Rxyz1.z+=0.005f;  
  218.           
  219.     if( Rxyz1.x>=2*D3DX_PI)     //当角度达到360时,赋值为零  
  220.          Rxyz1.x=0.0f;  
  221.     if( Rxyz1.y>=2*D3DX_PI)     //当角度达到360时,赋值为零  
  222.          Rxyz1.y=0.0f;  
  223.     if( Rxyz1.z>=2*D3DX_PI)     //当角度达到360时,赋值为零  
  224.          Rxyz1.z=0.0f;    
  225.     //end:立方体1(箱子)数值计算;  
  226.   
  227.     //*start:文字绘制矩形区域数值变化  
  228.     timeConversion+=0.1f;       //速度同步数值累加  
  229.     if(timeConversion>=2.0f)    //timeConversion累加到2.0f是,执行文字矩形框的数值计算  
  230.     {  
  231.         timeConversion=0.1f;    //重置初始值  
  232.   
  233.         FontRect.left+=1;  
  234.         FontRect.top+=1;  
  235.         FontRect.right-=1;  
  236.         FontRect.bottom-=1;  
  237.   
  238.         if(FontRect.left>=Width/2)      //当矩形left大于100是重置为零  
  239.             FontRect.left=0;  
  240.         if(FontRect.top>=Height/2)      //当矩形top大于100是重置为零  
  241.             FontRect.top=0;  
  242.         if(FontRect.right<=Width/2)     //当矩形right小于400是重置为Width(窗口宽度)  
  243.             FontRect.right=Width;  
  244.         if(FontRect.bottom<=Height/2)   //当矩形bottom小于200是重置为Height(窗口高度)  
  245.             FontRect.bottom=Height;  
  246.     }  
  247.   
  248.     return true;  
  249. }  
  250.   
  251. bool Display(float timeDelta)  
  252. {  
  253.     if( Device ) //如果设备对象不为空  
  254.     {  
  255.         //数值计算;  
  256.         Calculation();  
  257.           
  258.         Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(00,00,00),  1.0f, 0);  
  259.   
  260.         //开始渲染  
  261.         Device->BeginScene();  
  262.   
  263.         Device->SetTransform(D3DTS_VIEW,&V);  
  264.   
  265.         //绘制立方体  
  266.         Box1->SetCalculation(Txyz1,Rxyz1);  //设置数值计算后的值  
  267.         Box1->Draw(&material,Texture1);     //绘制最终立方体  
  268.   
  269.         Box2->SetCalculation(D3DXVECTOR3(3,2,-3),D3DXVECTOR3(0,0,0));  
  270.         Box2->Draw(&material,Texture1);     //绘制最终立方体  
  271.   
  272.         Ground->DrawGround(&Map,&material,Texture2);    //绘制地形(地图)  
  273.   
  274.         //显示文字  
  275.         Text->DrawTextA(NULL,"雾特效,旋转的立方体,河流底面,雪花飘!~简单演示~",  
  276.                         -1,&FontRect,DT_CENTER,D3DCOLOR_XRGB(255,255,255));   
  277.   
  278.         //绘制sprite点  
  279.         Point->Draw(Texture3);  
  280.   
  281.         //结束渲染  
  282.         Device->EndScene();  
  283.           
  284.         Device->Present(0, 0, 0, 0);  
  285.     }  
  286.     return true;  
  287. }  
  288.   
  289. //  
  290. // 消息处理  
  291. //  
  292. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  
  293. {  
  294.     switch( msg )  
  295.     {  
  296.     case WM_DESTROY:  
  297.         ::PostQuitMessage(0);  
  298.         break;  
  299.     case WM_KEYDOWN:  
  300.         switch(wParam)  
  301.         {  
  302.         case VK_ESCAPE:  
  303.             ::DestroyWindow(hwnd);  
  304.             break;  
  305.         case VK_LEFT:  
  306.             target.x+=0.2f;                                 //摄像机观察目标向左移动  
  307.             position.x+=0.2f;                               //摄像机位置向左移动  
  308.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  309.             break;  
  310.         case VK_RIGHT:  
  311.             target.x-=0.2f;                                 //摄像机观察目标向右移动  
  312.             position.x-=0.2f;                               //摄像机位置向右移动  
  313.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  314.             break;  
  315.         case VK_UP:  
  316.             target.z-=0.2f;                                 //摄像机观察目标向前移动  
  317.             position.z-=0.2f;                               //摄像机向前移动  
  318.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  319.             break;  
  320.         case VK_DOWN:  
  321.             target.z+=0.2f;                                 //摄像机观察目标向后移动  
  322.             position.z+=0.2f;                               //摄像机位置向后移动  
  323.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  324.             break;  
  325.         case VK_SHIFT:  
  326.             position.y+=0.2f;                               //摄像机位置向上移动  
  327.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  328.             break;  
  329.         case VK_CONTROL:  
  330.             position.y-=0.2f;                               //摄像机位置向下移动  
  331.             SetMatrixLookAt( &V,&position, &target,&up);    //设置摄像机函数  
  332.             break;  
  333.         case VK_SPACE:  
  334.             isFogEnable=(isFogEnable==1?0:1);   //启动或关闭雾效果  
  335.             SetFogEffects(caps,isFogEnable);  
  336.             break;  
  337.         }  
  338.     }  
  339.     return ::DefWindowProc(hwnd, msg, wParam, lParam);  
  340. }  
  341.   
  342. //  
  343. // 入口函数  
  344. //  
  345. int WINAPI WinMain(HINSTANCE hinstance,  
  346.                    HINSTANCE prevInstance,   
  347.                    PSTR cmdLine,  
  348.                    int showCmd)  
  349. {  
  350.     WNDCLASS wc;  
  351.   
  352.     wc.style         = CS_HREDRAW | CS_VREDRAW;  
  353.     wc.lpfnWndProc   = (WNDPROC)WndProc;   
  354.     wc.cbClsExtra    = 0;  
  355.     wc.cbWndExtra    = 0;  
  356.     wc.hInstance     = hinstance;  
  357.     wc.hIcon         = LoadIcon(0, IDI_APPLICATION);  
  358.     wc.hCursor       = LoadCursor(0, IDC_ARROW);  
  359.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);  
  360.     wc.lpszMenuName  = 0;  
  361.     wc.lpszClassName = "Direct3D9App";  
  362.   
  363.     if( !RegisterClass(&wc) )   
  364.     {  
  365.         ::MessageBox(0, "RegisterClass() - FAILED", 0, 0);  
  366.         return false;  
  367.     }  
  368.   
  369.     //初始化D3D  
  370.     if(!Frame.InitD3D(hinstance,  
  371.         640, 480, true, D3DDEVTYPE_HAL, &Device))  
  372.     {  
  373.         ::MessageBox(0, "InitD3D() - FAILED", 0, 0);  
  374.         return 0;  
  375.     }  
  376.           
  377.     if(!Setup())  
  378.     {  
  379.         ::MessageBox(0, "Setup() - FAILED", 0, 0);  
  380.         return 0;  
  381.     }  
  382.   
  383.     //进入游戏循环  
  384.     Frame.EnterMsgLoop( Display );  
  385.   
  386.     Cleanup();  
  387.   
  388.     Device->Release();  
  389.   
  390.     return 0;  
  391. }  

 

两个粒子系统文件

Code:
  1. //  
  2. // 文件: Sprite.cpp  
  3. // 作者:CYM  
  4. // *简单的粒子类    
  5. //  
  6. #pragma once  
  7. #include <d3d9.h>  
  8. #include <d3dx9.h>  
  9. #include "Vertex.h"  
  10. #define count 1000  
  11.   
  12. struct SPRITE  
  13. {  
  14.     D3DXVECTOR3 pos;    //位置  
  15.     float speed;        //粒子速度  
  16. };  
  17.   
  18. class CSprite  
  19. {  
  20. public:  
  21.     CSprite(IDirect3DDevice9* device);  
  22.     ~CSprite(void);  
  23. public:  
  24.     void Draw(IDirect3DTexture9* texture);  //显示图像函数  
  25. protected:  
  26.     void Update(void);                      //[内]更新数据函数   
  27.     inline unsigned long FtoDW(float v);    //[内]数值转换函数  
  28. public:  
  29.     IDirect3DDevice9*   _device;            //定义D3D设备  
  30.     IDirect3DVertexBuffer9*     _vb;        //定义顶点缓存  
  31.     IDirect3DTexture9*  _texture;           //定义文理  
  32. protected:  
  33.     //sprite属性  
  34.     SPRITE  _sprite[count]; //定义1000个粒子  
  35.     //int _count;                   //粒子数量  
  36.     unsigned long   _col;       //颜色  
  37.     //D3DXMATRIX*   matrix;         //移动矩阵  
  38. };  
Code:
  1. #include "Sprite.h"  
  2.   
  3.   
  4. CSprite::CSprite(IDirect3DDevice9* device)  
  5. {  
  6.     _device=device;     //获取设备对象  
  7.     _col=D3DCOLOR_XRGB(255,00,00);      //初始化颜色  
  8.   
  9.     for(int i=0;i<=count;i++)  
  10.     {  
  11.         //初始化位置坐标和速度  
  12.         _sprite[i].pos=D3DXVECTOR3(0.0f,-1.0f,0.0f);  
  13.         _sprite[i].speed=0.0f;  
  14.     }  
  15.   
  16.     _device->CreateVertexBuffer(  
  17.         count * sizeof(Vertex3),   
  18.         D3DUSAGE_WRITEONLY,  
  19.         FVF_VERTEX3,  
  20.         D3DPOOL_MANAGED,  
  21.         &_vb,  
  22.         0);  
  23. }  
  24.   
  25.   
  26. CSprite::~CSprite(void)  
  27. {  
  28.     if(_vb){_vb->Release(); _vb = 0;}  
  29. }  
  30.   
  31. //数值转换函数  
  32. unsigned long CSprite::FtoDW(float v)  
  33. {  
  34.     return *((unsigned long*)&v);  
  35. }  
  36.   
  37. //显示图像函数  
  38. void CSprite::Draw(IDirect3DTexture9*   texture)  
  39. {  
  40.     _texture=texture;  
  41.     _device->SetTexture(0,_texture);  
  42.     Update();   //更新数据  
  43.   
  44.     // 启用点状sprite  
  45.     _device->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);  
  46.     // 启用点状sprite的比例  
  47.     _device->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);  
  48.     //开启混合因子  
  49.     _device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);  
  50.     //设置目标混合因子  
  51.     _device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);  
  52.   
  53.     // 设置sprite的尺寸  
  54.     _device->SetRenderState(D3DRS_POINTSIZE, FtoDW(0.1f));  
  55.     // 设置点状sprite的最小尺寸  
  56.     _device->SetRenderState(D3DRS_POINTSIZE_MIN,FtoDW(0.0f));    
  57.     // 根据距离更改点状sprite的形状  
  58.     _device->SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.0f));  
  59.     // 根据距离更改点状sprite的形状  
  60.     _device->SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.0f));  
  61.     // 根据距离更改点状sprite的形状  
  62.     _device->SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.0f));  
  63.   
  64.     _device->SetFVF(FVF_VERTEX3);        
  65.     _device->SetStreamSource(0, _vb,0, sizeof(Vertex3));  
  66.     _device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0,count);  
  67.   
  68.     _device->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);  
  69.     _device->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);  
  70.     _device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);  
  71. }  
  72.   
  73. //更新数据函数  
  74. void CSprite::Update()  
  75. {  
  76.     Vertex3* v;             //顶点  
  77.     _vb->Lock(0, 0, (void**)&v, 0);  
  78.     // 填充数据X正半轴,Z负半轴粒子顶点缓存数据  
  79.     for(int i=0;i<count/4;i++)  
  80.     {  
  81.         _sprite[i].pos.y-=0.01f*_sprite[i].speed;  
  82.         if(_sprite[i].pos.y<0.0f)  
  83.         {  
  84.             ::ZeroMemory(&v[i], sizeof(v[i]));              //清空数据  
  85.             ::ZeroMemory(&_sprite[i], sizeof(_sprite[i]));              //清空数据  
  86.             ::ZeroMemory(&_sprite[i].speed, sizeof(_sprite[i].speed));  //清空数据  
  87.             _sprite[i].speed=((rand()%20)*0.1f);  
  88.             _sprite[i].pos.x=((rand()%100)*0.1f);   //随机获得x轴坐标  
  89.             _sprite[i].pos.y=5;                     //获得固定高度5  
  90.             _sprite[i].pos.z=((rand()%100)*-0.1f);  //随机获得z轴坐标  
  91.         }  
  92.           
  93.         v[i] = Vertex3(_sprite[i].pos.x, _sprite[i].pos.y,_sprite[i].pos.z,D3DCOLOR_XRGB(255,255,255));  
  94.     }  
  95.   
  96.     // 填充数据X负半轴,Z负半轴粒子顶点缓存数据  
  97.     for(int i=count/4;i<count/2;i++)  
  98.     {  
  99.         _sprite[i].pos.y-=0.01f*_sprite[i].speed;  
  100.         if(_sprite[i].pos.y<0.0f)  
  101.         {  
  102.             ::ZeroMemory(&v[i], sizeof(v[i]));              //清空数据  
  103.             ::ZeroMemory(&_sprite[i], sizeof(_sprite[i]));              //清空数据  
  104.             ::ZeroMemory(&_sprite[i].speed, sizeof(_sprite[i].speed));  //清空数据  
  105.             _sprite[i].speed=((rand()%20)*0.1f);  
  106.             _sprite[i].pos.x=((rand()%100)*-0.1f);  //随机获得x轴坐标  
  107.             _sprite[i].pos.y=5.0f;                  //获得固定高度5  
  108.             _sprite[i].pos.z=((rand()%100)*-0.1f);  //随机获得z轴坐标  
  109.         }  
  110.         v[i] = Vertex3(_sprite[i].pos.x, _sprite[i].pos.y,_sprite[i].pos.z,D3DCOLOR_XRGB(255,255,255));  
  111.     }  
  112.   
  113.     // 填充数据X正半轴,Z正半轴粒子顶点缓存数据  
  114.     for(int i=count/2;i<count*3/4;i++)  
  115.     {  
  116.         _sprite[i].pos.y-=0.01f*_sprite[i].speed;  
  117.         if(_sprite[i].pos.y<0.0f)  
  118.         {  
  119.             ::ZeroMemory(&v[i], sizeof(v[i]));              //清空数据  
  120.             ::ZeroMemory(&_sprite[i], sizeof(_sprite[i]));              //清空数据  
  121.             ::ZeroMemory(&_sprite[i].speed, sizeof(_sprite[i].speed));  //清空数据  
  122.             _sprite[i].speed=((rand()%20)*0.1f);  
  123.             _sprite[i].pos.x=((rand()%100)*0.1f);   //随机获得x轴坐标  
  124.             _sprite[i].pos.y=5.0f;                  //获得固定高度5  
  125.             _sprite[i].pos.z=((rand()%100)*0.1f);   //随机获得z轴坐标  
  126.         }  
  127.         v[i] = Vertex3(_sprite[i].pos.x, _sprite[i].pos.y,_sprite[i].pos.z,D3DCOLOR_XRGB(255,255,255));  
  128.     }  
  129.   
  130.     // 填充数据X负半轴,Z正半轴粒子顶点缓存数据  
  131.     for(int i=count*3/4;i<=count;i++)  
  132.     {  
  133.         _sprite[i].pos.y-=0.01f*_sprite[i].speed;  
  134.         if(_sprite[i].pos.y<0.0f)  
  135.         {  
  136.             ::ZeroMemory(&v[i], sizeof(v[i]));              //清空数据  
  137.             ::ZeroMemory(&_sprite[i], sizeof(_sprite[i]));              //清空数据  
  138.             ::ZeroMemory(&_sprite[i].speed, sizeof(_sprite[i].speed));  //清空数据  
  139.             _sprite[i].speed=((rand()%20)*0.1f);  
  140.             _sprite[i].pos.x=((rand()%100)*-0.1f);  //随机获得x轴坐标  
  141.             _sprite[i].pos.y=5.0f;                  //获得固定高度5  
  142.             _sprite[i].pos.z=((rand()%100)*0.1f);   //随机获得z轴坐标  
  143.         }  
  144.         v[i] = Vertex3(_sprite[i].pos.x, _sprite[i].pos.y,_sprite[i].pos.z,D3DCOLOR_XRGB(255,255,255));  
  145.     }  
  146.     _vb->Unlock();  
  147.       
  148. }  

这个代码有点重复,但也不修改了,只是测试一下,还是有漏洞

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值