Rotating Multiple 2D Sprites on the Z axis?

This topic is 5071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
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()
next n

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

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 ASetTransform(apply above transform)sprite->Draw(sprite A)D3DXMatrixTransformation(...) for sprite BSetTransform(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 Amat = mat * current;sprite->SetTransform(mat);sprite->Draw(..)sprite->SetTransform(current)     //restore the old transform state

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631424
• Total Posts
3000008
×