Sign in to follow this  
Galaximo

D3DXSprite Size

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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[i];

// 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();


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
That did it! Thanks a lot Sc4.

I put a Sprite.SetTransform() call before each Sprite.Draw() call. I used Matrix.Transformation() (Managed DirectX) which had pivot point support. Works beautifully, and didn't affect performance much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this