xna吧 关注:585贴子:1,920
  • 1回复贴,共1
请问一下用XNA怎么大海波浪的特效,毕业设计要用,很急,跪求答复


1楼2015-10-14 19:33回复
    class cParticle{public://particle properties//source dataint tilenum;//like, its the 12th tile on the texture, etc...int tileid;//like, tile 1 is explosions, 2 is ships etc...RECT srcrect;//source rect of tile//dest dataD3DXVECTOR2 trans;//used to set the position of a tileD3DXVECTOR2 center; //used to set the center of a tileD3DXVECTOR2 scale;//scale of tilefloat rot;//rotation in degrees of tilefloat heading; //not the same as rotation, heading implies direction//otherfloat timestarted;float duration;bool isactive;float speed;};class cSprite{public:IDirect3DTexture8 *pTexExplosions;ID3DXSprite *pSprite;cSprite();virtual ~cSprite();void InitSprite();cParticle pea[512];//particle explosion arrayIDirect3DTexture8 *MakeTexture(const char *imgsrc, DWORD bmp);void DrawTile(int tilenum, float x, float y, float rot);//rot in degrees, counterclockwisevoid CleanupSprite();void CreateExplosion(int x, int y);void HandleExplosions();private:};#include "cSprite.h"#include "cStateManager.h"extern cStateManager *pStateManager;extern HWND ghWnd;extern HRESULT ghr;#define SAFERELEASE(pObj) if(pObj){pObj->Release(); pObj = NULL;}extern int MAXEXPLOSIONTILES; //512cSprite::cSprite(){InitSprite();}cSprite::~cSprite(){CleanupSprite();}void cSprite::InitSprite(){D3DXCreateSprite(pStateManager->pGraphics->pD3DDevice, &pSprite);ZeroMemory(&pea, sizeof(pea));//create texturespTexExplosions = MakeTexture("explosions.bmp", 1);}IDirect3DTexture8 *cSprite::MakeTexture(const char *imgsrc, DWORD bmp){DWORD dwKeyColor = D3DCOLOR_XRGB(0, 0, 0);IDirect3DTexture8 *pTemp = 0;ghr = D3DXCreateTextureFromFileEx(pStateManager->pGraphics->pD3DDevice, imgsrc, NULL,//width NULL, //height, NULL, //mip levels NULL,//usage D3DFMT_A8R8G8B8,//format D3DPOOL_DEFAULT,//pool D3DX_DEFAULT,//filter D3DX_DEFAULT, //mip filter dwKeyColor,//colorkey NULL, NULL, &pTemp);if(FAILED(ghr)){return NULL;}return pTemp;}void cSprite::CleanupSprite(){if(pTexExplosions) {pTexExplosions->Release();}if(pSprite){pSprite->Release(); pSprite = NULL;}}void cSprite::CreateExplosion(int xpos, int ypos){ZeroMemory(&pea, sizeof(pea));int x = 0;pea[x].center.x = pea[x].center.y = 16;pea[x].duration = rand()%200 + 9900;pea[x].heading = rand()%359;pea[x].isactive = true;pea[x].rot = 0;pea[x].scale.x = pea[x].scale.y = .1;pea[x].speed = 50;//pea[x].duration;pea[x].srcrect.bottom = 64;pea[x].srcrect.left = 0;pea[x].srcrect.right = 64;pea[x].srcrect.top = 0;pea[x].tileid = 1;pea[x].tilenum = 1;pea[x].timestarted = GetTickCount();pea[x].trans.x = xpos;pea[x].trans.y = ypos;}void cSprite::HandleExplosions(){int x = 0;//update positions based on time and headingwhile(x < MAXEXPLOSIONTILES){if(pea[x].isactive){float dist = pea[x].speed * pStateManager->elapsedpercent;float s = sin(pea[x].heading * 0.0174532f);float c = cos(pea[x].heading * 0.0174532f);float ammttomovex = dist * s;float ammttomovey = dist * c;pea[x].trans.x += ammttomovex;pea[x].trans.y += ammttomovey;if(GetTickCount() > pea[x].duration + pea[x].timestarted)pea[x].isactive = false;float lifetime = GetTickCount() - pea[x].timestarted;pea[x].scale.y = pea[x].scale.x = lifetime / pea[x].duration;pea[x].center.x = pea[x].center.y = lifetime / pea[x].duration;}x++;}//now draw em allx = 0;while(x < MAXEXPLOSIONTILES){if(pea[x].isactive){pSprite->Draw(pTexExplosions, //IDirect3DTexture8 &pea[x].srcrect, //source rect &pea[x].scale, //&scale, //scaling (D3DVECTOR) &pea[x].center,//center (D3DVECTOR) D3DXToRadian(pea[x].rot), //rot, //rot, //rotation, in radians &pea[x].trans, //translation, (D3DVECTOR) D3DCOLOR_XRGB(255, 255, 255));//0xFFFFFFFF);//transparent color}x++;}}void cSprite::DrawTile(int tilenum, float x, float y, float rot){}


    2楼2015-10-16 20:30
    回复