//*******//
//DSPRITE//
//*******//
class DSPRITE
{
public:
DSPRITE();
HRESULT LoadSprite(char*, LPDIRECT3DDEVICE9*);
virtual HRESULT Render();
void SetPos(int, int);
POINT GetSize();
UINT GetHeight();
UINT GetWidth();
protected:
LPD3DXSPRITE Sprite;
LPDIRECT3DTEXTURE9 SpriteTex;
D3DXIMAGE_INFO ImageInfo;
D3DXVECTOR2 Transform;
};
//***************//
//**CONSTRUCTOR**//
//***************//
DSPRITE::DSPRITE()
{
DSPRITE::Transform.x=0;
DSPRITE::Transform.y=0;
}
//***************//
//**LOAD METHOD**//
//***************//
HRESULT DSPRITE::LoadSprite(char* FileName, LPDIRECT3DDEVICE9* ppDev)
{
if (FAILED(D3DXCreateTextureFromFileEx(*(ppDev), FileName, D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0xFFFF00FF, &(DSPRITE::ImageInfo), NULL, &(DSPRITE::SpriteTex))))return E_FAIL;
if (FAILED(D3DXCreateSprite(*ppDev, &(DSPRITE::Sprite))))return E_FAIL;
return S_OK;
}
//***************//
//SET POS METHOD*//
//***************//
void DSPRITE::SetPos(int x, int y)
{
DSPRITE::Transform.x=(float)x;
DSPRITE::Transform.y=(float)y;
}
//***************//
//*RENDER METHOD*//
//***************//
HRESULT DSPRITE::Render()
{
DSPRITE::Sprite->Begin();
if (FAILED(DSPRITE::Sprite->Draw(DSPRITE::SpriteTex, NULL, NULL, NULL, NULL,&(DSPRITE::Transform), 0xFFFFFFFF)))return E_FAIL;
DSPRITE::Sprite->End();
return S_OK;
return E_FAIL;
}
POINT DSPRITE::GetSize()
{
POINT size;
size.x=DSPRITE::ImageInfo.Width;
size.y=DSPRITE::ImageInfo.Height;
return size;
}
UINT DSPRITE::GetHeight()
{
return DSPRITE::ImageInfo.Height;
}
UINT DSPRITE::GetWidth()
{
return DSPRITE::ImageInfo.Width;
}
class DROTATESPRITE: public DSPRITE
{
public:
DROTATESPRITE();
virtual HRESULT Render();
void LookAt(UINT, UINT);
void Init();
private:
D3DXVECTOR2 RotationCenter;
float rotation;
};
DROTATESPRITE::DROTATESPRITE()
{
DROTATESPRITE::RotationCenter.x=(float)0;
DROTATESPRITE::RotationCenter.y=(float)0;
DROTATESPRITE::rotation=0;
}
void DROTATESPRITE::Init()
{
DROTATESPRITE::RotationCenter.x=(DROTATESPRITE::ImageInfo.Width/(float)2);
DROTATESPRITE::RotationCenter.y=(DROTATESPRITE::ImageInfo.Height/(float)2);
}
void DROTATESPRITE::LookAt(UINT x, UINT y)
{
int xdiff=abs((int)(x-(int)DROTATESPRITE::RotationCenter.x));
int ydiff=abs((int)(x-(int)DROTATESPRITE::RotationCenter.y));
float tan=0;
if ((x>=(UINT)DROTATESPRITE::RotationCenter.x)&&(y<(UINT)DROTATESPRITE::RotationCenter.y))
{
tan=atan(xdiff/(float)ydiff);
DROTATESPRITE::rotation=FMAUDE(tan, (float)360);
}
else if ((x>(UINT)DROTATESPRITE::RotationCenter.x)&&(y>=(UINT)DROTATESPRITE::RotationCenter.y))
{
tan=atan(ydiff/(float)xdiff);
DROTATESPRITE::rotation=FMAUDE(tan, (float)360);
}
else if ((x<=(UINT)DROTATESPRITE::RotationCenter.x)&&(y>(UINT)DROTATESPRITE::RotationCenter.y))
{
tan=atan(xdiff/(float)ydiff);
DROTATESPRITE::rotation=FMAUDE(tan, (float)360);
}
else if ((x<(UINT)DROTATESPRITE::RotationCenter.x)&&(y<=(UINT)DROTATESPRITE::RotationCenter.y))
{
tan=atan(ydiff/(float)xdiff);
DROTATESPRITE::rotation=FMAUDE(tan, (float)360);
}
else
{
DROTATESPRITE::rotation=0;
}
}
//
//LOOK AT THIS!!!!
//this should be where the problem is
//
HRESULT DROTATESPRITE::Render()
{
DROTATESPRITE::Sprite->Begin();
if (FAILED(DROTATESPRITE::Sprite->Draw(DROTATESPRITE::SpriteTex, NULL, NULL, &(DROTATESPRITE::RotationCenter), DROTATESPRITE::rotation, &(DROTATESPRITE::Transform), NULL)))return E_FAIL;
DROTATESPRITE::Sprite->End();
return S_OK;
}
i know its a lot, and all, but i really appreciate the help, cuz im stumped
-Dan
Yes I realize im a n00b...
HELP dx9/8 rotate sprite
Ok, this is really wierd, but the proto for the ID3DXSprite::draw that i have doestn match the sdk''s even though im including the right files...
but heres my source...
The prototypes change between DirectX versions, and, with the "X" library, even between SDK releases. There was the 9.0a SDK, and then this summer the 9.0b SDK. If you get prototype differences, make sure your documentation is for the version you have installed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement