Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

scaling matrix question

$
0
0
I can't seem to get the scaling matrix to work. when i apply it the sprite disappears on my application

class CSprite {
public:
	LPD3DXSPRITE		pSprite;
	LPDIRECT3DTEXTURE9	pTexture;
	D3DXIMAGE_INFO		imageInfo;

	D3DXVECTOR2			pos;
	float zAngle, xSize, ySize, zSize ;

	void Init(char imageFilename[]) {
		D3DXCreateSprite(pD3DDevice, &pSprite);
				
		D3DXCreateTextureFromFileEx(pD3DDevice, imageFilename, 0, 0, 0, 0,
                  D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, 
                  D3DX_DEFAULT, D3DCOLOR_ARGB(0, 0, 0, 255), 
                  &imageInfo, 0, &pTexture);

		pos = D3DXVECTOR2(0, 0);
		zAngle = 0;
		

	}
	void Move(float dx, float dy)
	{
		pos.x += dx;
		pos.y += dy;
	}

	void Rotate(float dAngle)
	{
		zAngle += dAngle;
	}
	void Scale(float dxs, float dys, float dzs)
	{
		xSize += dxs;
		ySize += dys;
		zSize += dzs;

	}

	void Draw() {

		D3DXVECTOR3 center(imageInfo.Width/2, imageInfo.Height/2, 0);
		D3DXMATRIX t, rz, c, s;
		

		D3DXMatrixTranslation(&t, pos.x, pos.y, 0);
		D3DXMatrixRotationZ(&rz, zAngle * D3DX_PI/180);
		D3DXMatrixScaling(&s, xSize, ySize, zSize);

		c = s * rz * t;
		pSprite->Begin(D3DXSPRITE_ALPHABLEND);

		pSprite->SetTransform(&c);

		pSprite->Draw(pTexture, NULL, &center, NULL, D3DCOLOR_ARGB(255, 255, 255, 255));

		pSprite->End();
	}


Then to implement the tranformations.

void Update(float dt) {

	//check for user input
	if (KEY_DOWN(0x41)) // A key
	{
		Sprite1.Move(-0.1, 0);
	}

	if (KEY_DOWN(0x44)) // D Key
	{
		Sprite1.Move(0.1, 0);
	}
			 
	if (KEY_DOWN(0x57)) // W key
	{
		Sprite1.Move(0, -0.1);
	}

	if (KEY_DOWN(0x53)) // S key
	{
		Sprite1.Move(0, 0.1);
	}

	if (KEY_DOWN(VK_RBUTTON))
	{
		Sprite1.Rotate(0.1);
	}
	if (KEY_DOWN(VK_LBUTTON))
	{
		Sprite1.Rotate(-0.1);
	}

	if (KEY_DOWN(VK_UP))
	{
		Sprite1.Scale(0.2, 0.2, 0.2);
	}
	if (KEY_DOWN(VK_DOWN))
	{
		Sprite1.Scale(-0.2, -0.2, -0.2);
	}


im just not sure whats wrong.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>