Jump to content
  • Advertisement
Sign in to follow this  
VanKurt

OpenGL Rotating several sprites around ONE point

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

Hi there! I'm having a little trouble rotating sprites correctly (back then with OpenGl things were so much easier) ;-) The poroblem is this: rotating a single sprite is easy. But now I have a bunch of sprites forming ONE object. And I want to rotate all of them around ONE point (not each of them around its own center or something...). So I used this code:
// Store current matrix
D3DXMATRIX matOld;
mc.mVideo->getD3DDevice()->GetTransform( D3DTS_WORLD, &matOld );

// Create and apply new one
D3DXMATRIX matNew;
D3DXMatrixTransformation2D( &matNew, NULL, 0.0, NULL, NULL, curAngle, NULL );
matNew = matOld*matNew;
mc.mVideo->getD3DDevice()->SetTransform( D3DTS_WORLD ,&matNew );

// Draw them all
drawSprites();

// Restore old matrix
mc.mVideo->getD3DDevice()->SetTransform( D3DTS_WORLD ,&matOld );


But sadly NOTHING happens. No rotation at all. But if I remove the last function (restoring), suddenly the whole scene starts to rotate. What's the problem here? Why is either nothing or everything moving??? Thanks for your help! :-D

Share this post


Link to post
Share on other sites
Advertisement
ID3DXSprite doesn't do any actual drawing until you call End() or Flush(). Until that point, it only collects draw calls to execute later. If you set the world matrix, call Draw() a bunch of times, unset the world matrix and call End(), by the time ID3DXSprite does the drawing, the matrix has already been restored to its older value.

Could this be the case here? (You didn't include the begin/end calls in your code, so I can't tell).

Hope this helps.

Share this post


Link to post
Share on other sites
Yeah, sounded like a good idea ;-) But it still won't work.

Here's the new (pseudo)code:

1) store old matrix
2) set new rotation matrix
3) begin sprite drawing
4) draw sprites
5) end sprite drawing
6) restore matrix

still the rotation is just discarded :-(

Share this post


Link to post
Share on other sites
Seems I was a bit out of it when I replied. ID3DXSprite completetly ignores the transformation matrices (world, view and projection). As such, changing them will have no effect on the actual rendering.

ID3DXSprite has the SetWorldViewLH method, for setting a World matrix, but it is only used if you use the OBJECTSPACE flag, which would then cause all drawing to be done in object space, not screen space. This might be the only solution for a global transformation on all sprites drawn -- I'm not aware of a simpler method.

Off the top of my head, using Identity for both the View (in SetWorldViewLH) and as the projection matrix (in SetTransform) would cause drawing to skip all steps except the world matrix. I'm not really sure this is accurate.

Hope this helps.

Share this post


Link to post
Share on other sites
Gnarr! It won't work :-(

Here's what I do at the moment:


// remove previous transforms from sprite
D3DXMATRIX id;
D3DXMatrixIdentity(&id);
spr->SetTransform(&id);

// begin drawing in evil objectspace
spr->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_OBJECTSPACE );

// try to set some matrices
spr->SetWorldViewLH( &id, &id );

//render sprite
spr->Draw( media.texBlocks, NULL, NULL, NULL, D3DCOLOR_RGBA(255,255,255,255) );

// end drawing
spr->Flush();
spr->End();



But this code makes the sprite just disappear...

Share this post


Link to post
Share on other sites
I don't see why you have to do it in object space. You can do it in screen space, and when you do your D3DXMatrixTransformation2D(), you can set a value for the pRotationCenter value. This is the rotation pivot, which by default resides at the centre of the sprite. Set this to the point you want to rotate around, and it should work.

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!