Sign in to follow this  

special effects

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Are there any special effects that go along with the cSprite class, maybe some weird texture blending or texture color manipulation? Ive been working on making explosions with an array of tiles, anyone else do this? How did you go about it? Heres a snippet that shows how im going about it :
class cParticle
{
public:
	//particle properties

	//source data
	int 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 data
	D3DXVECTOR2 trans;//used to set the position of a tile
	D3DXVECTOR2 center; //used to set the center of a tile
	D3DXVECTOR2 scale;//scale of tile
	float rot;//rotation in degrees of tile
	float heading; //not the same as rotation, heading implies direction

	//other
	float timestarted;
	float duration;
	bool isactive;
	float speed;


};




class cSprite
{
public:
	
	IDirect3DTexture8 *pTexExplosions;
	ID3DXSprite *pSprite;

	cSprite();
	virtual ~cSprite();
	void InitSprite();	

	cParticle pea[512];//particle explosion array
	
	IDirect3DTexture8 *MakeTexture(const char *imgsrc, DWORD bmp);
	void DrawTile(int tilenum, float x, float y, float rot);//rot in degrees, counterclockwise
	void 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; //512

cSprite::cSprite()
{
	InitSprite();
}

cSprite::~cSprite()
{
	CleanupSprite();
}

void cSprite::InitSprite()
{
	D3DXCreateSprite(pStateManager->pGraphics->pD3DDevice, &pSprite);

	ZeroMemory(&pea, sizeof(pea));
	
	//create textures	
	pTexExplosions = 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 heading
	while(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 all
	x = 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)
{



}




Im sure you can kinda get the gist of it from the above. How else would you do it? I guess my point is, what effects have you made that are interesting, and how did you go about it. -Jason

Share this post


Link to post
Share on other sites
Quote:
Original post by nosajghoul
Are there any special effects that go along with the cSprite class ...
-Jason


Well, a sprite entity in DirectX will always face the camera, hence its like billboard texture. No special alpha stuff etc. In order to making a cool explosion you need to combine a few effects, for instance add blending smoke textures or play a sequence of textures together with the sprite stuff - this is the "old school" way of doing it.

For killer effects (like in DOOM3 etc) you would have to look into shaders. HLSL even talk about "effect files". NVidia has got a tool called FX Composer, with all kinds of different effects made with shaders, so cool that it makes me wanna cry!

Modern effects in games today are a full time shader job, keep that in mind!

Share this post


Link to post
Share on other sites

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this