Sign in to follow this  
DFX

Rotating Multiple 2D Sprites on the Z axis?

Recommended Posts

So I've setup a sprite Renderer class based on some tutorials online and some posts on this forum. It uses the ID3DXSprite interface and like I've read on this forum, I only create one instance of it to do all my rendering of the sprites. It works exceptionally well (rending 9K worth of sprites and still maintaining 60+ FPS). However, now I want to add in the ability to rotate the sprites (multiple sprites rotating in different directions at different speeds) but I'm having some trouble. The only function I see available to me for this purpose is SetTransform(). However, this isn't working. From what I'm seeing this is what I believe is happening: every time I call SetTransform() it's just replacing the previous SetTransform() and because nothing actually renders to the screen until End() is called, all my sprites are being rotated by exactly the same matrices. The reason I suspect this is because I'm drawing 10 sprites to the screen, each one is suppose to have a separate rotation/rotation speed but instead they are all orbiting around the top left of the screen, so something is obviously not right. Any ideas what I'm doing wrong? Or is this the completely wrong path to begin with? How else could you achieve this? Thanks in advance -DFX

Share this post


Link to post
Share on other sites
i assume you already setup 10 quads for 10 sprites.
do like this (pseudocode):

for n = 0 to 9
Zrotation(angle[n])
Translate(x[n],y[n])
Scale(xscale[n],yscale[n],1.0)
Settransform()
Drawprimitive(quad[n])
next n

hope you can convert them to true c/c++

Share this post


Link to post
Share on other sites
Quote:
i assume you already setup 10 quads for 10 sprites.
do like this (pseudocode):


He is using the ID3DXSprite interface, and so doesn not have to create quads. Here is the pseudo of what you need to do:


D3DXMatrixTransformation(...) for sprite A
SetTransform(apply above transform)
sprite->Draw(sprite A)

D3DXMatrixTransformation(...) for sprite B
SetTransform(apply above transform)
sprite->Draw(sprite B)

...etc.


U can make it a loop of course if you store your sprite textures in an array. If you have set a transform previously you can concatenate it with the rotation/scaling/translation transform by doing this:


sprite->GetTransform(current)
D3DXMatrixTransformation(&mat) for sprite A
mat = mat * current;
sprite->SetTransform(mat);
sprite->Draw(..)
sprite->SetTransform(current) //restore the old transform state

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