D3DXSprite Size

Started by
9 comments, last by Galaximo 17 years, 5 months ago
I'm using the Sprite class for a particle system, but I don't know how to change the size of the rendered sprite. It's rendering a small 16x16 JPG as a massive circle in the world. I've tried using the a scaling matrix for the World matrix, but this scales the position as well, so that doesn't do the trick.
Advertisement
You should be able to scale around a pivot. If you set the pivot to 0,0 then the position of the sprite will appear to change as well. Setting the pivot to the centre of the image will scale it without modifying its position.
NextWar: The Quest for Earth available now for Windows Phone 7.
How do I set a pivot?

Also, that might not work because I only set the World matrix once and render about 400 particles.

Here is the code I'm using to render the particles:

			Sprite.SetWorldViewLH( Matrix.Scaling(0.2f,0.2f,0.2f), D3DDevice.Transform.View );			Sprite.Begin( SpriteFlags.Billboard );									// draw the particles			for (int i=0; i < Particles.Count; i++)			{				// get the current particle				Particle p = (Particle)Particles;				// get particle's interpolated position				Vector3 interpPosition = Vector3.Lerp( p.LastPosition, p.Position, interpolator );				Sprite.Draw( Texture, new Vector3(), interpPosition, p.GetCurrentColor().ToArgb() );			}			Sprite.End();
Use the D3DXMatrixAffineTransformation2D() to transform sprites. Give it all your parameters, and it will generate a matrix for you. Then set that matrix using Sprite.SetTransform(). See the DirectX SDK for more information on these functions.
NextWar: The Quest for Earth available now for Windows Phone 7.
Oh I forgot to mention that I'm drawing them in 3D space, not 2D. Do I still use the D3DXMatrixAffineTransformation2D()?
yes, im doing the same thing when tiling a 2d map. i have to scale them down to 0.15f of their original size (96x96). but D3DXMatrixAffineTransformation2D() will still work for that. but the scale size affects both x and y together with the same scale. use D3DXMatrixTransformation2D() if you want to have different scale values for x and y.

just remember that in your case 16x16 world units (which is directx default it seems) is NOT 16x16 screen pixels.
On the other hand you could simply back the camera waaaaaay up to give you the same effect.
-----------------------------Real programmers code in pen.-----------------------------
I tried D3DXMatrixAffineTransformation2D() using Sprite.SetTransform() but it scaled the position as well.

Any other ideas?
Are you sure you set the pivot to the centre of the image?

On second thought, the pivot might be defined as an offset from the centre of the image. So you might want to try and set the pivot to 0,0 and just give it the position of the centre of your image.
NextWar: The Quest for Earth available now for Windows Phone 7.
Well there are two problems using AffineTransformation2D.
-It's meant for 2-dimensions, im using 3
-you only set it once, not for each sprite. I'm doing a batch of sprite.draw calls, so each sprite has vertex position information, so you can't do a position transform on each one.

There really doesn't look like there is any support to scale the image. quite pitiful. I've made my own textured quad engine but it doesn't get as good performance for some reason.

Thanks for the help guys, I geuss there isn't a way. :(
You can definately set it more than once. In your for() loop, recalculate the transform matrix and set it again using Sprite.SetTransform(). The SetTransform() function sets the transformation matrix for every sprite being drawn after that call. Calling it again sets the transformation matrix to something different. For example:

Sprite.SetTransform(&TransformMatrix1);
// ... everything drawn here will be tranformed using TransformMatrix1

Sprite.SetTransform(&TransformMatrix2);
// ... and now everything drawn in here will be transformed using TransformMatrix2

You can set it as many times as you want, you are not limited to once.


And according to the DirectX SDK:
Quote:...The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixAffineTransformation2D function can be used as a parameter for another function.

For 3D affine transformations, use D3DXMatrixAffineTransformation.

So there you have it. The 3D version of D3DXMatrixAffineTransformation2D() is called D3DXMatrixAffineTransformation(). I suggest you read the DirectX SDK documentation for more information.
NextWar: The Quest for Earth available now for Windows Phone 7.

This topic is closed to new replies.

Advertisement