4 Replies - 281 Views - Last Post: 18 January 2013 - 03:24 PM Rate Topic: -----

#1 Altbeau  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 07-July 09

scaling matrix question

Posted 18 January 2013 - 01:45 PM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: scaling matrix question

#2 Djabby  Icon User is offline

  • D.I.C Head

Reputation: 37
  • View blog
  • Posts: 131
  • Joined: 02-November 10

Re: scaling matrix question

Posted 18 January 2013 - 02:08 PM

Upon initialising a CSprite xSize, ySize and zSize are 0. With these sizes, your sprite has a 0 size and won't be drawn.

Try to set xSize, ySize and zSize to 1 in your Init.
Was This Post Helpful? 0
  • +
  • -

#3 Altbeau  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 07-July 09

Re: scaling matrix question

Posted 18 January 2013 - 02:52 PM

thanks.... I didn't think about that. the other question i had was how would i set the mouse wheel to control the scrolling... i have seen VK_MOUSEWHEEL, and short GET_WHEEL_DELTA_WPARAM(
WPARAM wParam

but i get an error that says wParam not instanced... or whatever.

also i would like to place limits on the scaling... my book doesn't tell me how and im not finding anything of value on the web yet.
Was This Post Helpful? 0
  • +
  • -

#4 Altbeau  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 07-July 09

Re: scaling matrix question

Posted 18 January 2013 - 03:02 PM

View PostAltbeau, on 18 January 2013 - 03:52 PM, said:

thanks.... I didn't think about that. the other question i had was how would i set the mouse wheel to control the scrolling... i have seen VK_MOUSEWHEEL, and short GET_WHEEL_DELTA_WPARAM(
WPARAM wParam

but i get an error that says wParam not instanced... or whatever.

also i would like to place limits on the scaling... my book doesn't tell me how and im not finding anything of value on the web yet.


i guess the code would help
	if (short GET_WHEEL_DELTA_WPARAM(WPARAM wParam) > 0)
	{
		Sprite.Scale(0.002, 0.002, 0.002);
	}
	if (short GET_WHEEL_DELTA_WPARAM(WPARAM wParam) < 0)
	{
		Sprite.Scale(-0.002, -0.002, -0.002);
	}

Was This Post Helpful? 0
  • +
  • -

#5 Altbeau  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 07-July 09

Re: scaling matrix question

Posted 18 January 2013 - 03:24 PM

error C2065: 'wParam' : undeclared identifier is the error i get... and how do you edit posts?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1