Jump to content
  • Advertisement
Sign in to follow this  
Besome Games

Anyone know why my zoom wont work?

This topic is 3503 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

Hello, I have been using a 2D library written with DirectX 9. I have been trying to modify the draw() function to enable me to zoom in and out. After following a conclusion I have made the following edits to the draw() function:
void draw(Image* image,int dx,int dy,int dw,int dh,int sx,int sy,int sw,int sh,unsigned int color,int cx,int cy,int rotation)
	{
		int scale = 10;
		D3DXMATRIX newMat;
		RECT srcRect={sx,sy,sx+sw,sy+sh};
		D3DXVECTOR2 scaling((float)dw/(float)image->getImageWidth(),(float)dh/(float)image->getImageHeight());
		D3DXMatrixTransformation2D(&newMat,NULL,0.0,&scaling,&D3DXVECTOR2(cx,cy),D3DXToRadian(rotation),&D3DXVECTOR2(dx,dy));
		sprite->SetTransform(&newMat);
		// zoom code
		D3DXMATRIX matrix;
		device->SetTransform(D3DTS_PROJECTION, D3DXMatrixOrthoRH(&matrix, 1024*scale, 768*scale, 1, 1000));
		//end of zoom code
		sprite->Draw(image->getTexture(),&srcRect,0,0,color);
	}

but for some reason after I run it, everything goes black, and I cant continue to see what im working with. I am aware that scale is hardcoded, which will be changed after I figure this out, but does any DirectX guru have any idea as to why this happens?

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure if passing the address of a temporary to a parameter taking a pointer is valid. When you do this in D3DXMatrixTransformation2D:

&D3DXVECTOR2(cx,cy)


I think it might destroy the temporary D3DXVECTOR2 before jumping in to the function so the function gets trash memory. Anyone know the actual spec for this?

Still you don't need to set the transform for both the sprite and device, just changing the device projection should do the trick. Or, if you're using a camera, move the camera further forwards :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!