Jump to content
  • Advertisement
Sign in to follow this  

OpenGL DirectX Sprite transformation origin

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

Hey, I've built an OpenGL 2D engine which works perfect for my needs and i'm porting it to DirectX. Everything works fine except one trick I can't figure out yet. I'm using sprites (LPD3DXSPRITE) to draw pixmaps and everything is working fine here too except for rotation and scaling transformations. The trouble comes from where DX takes the transformation origins. For the rotation it is say that LPD3DXMATRIXSTACK::rotateAxis() works in world coordinates while LPD3DXMATRIXSTACK::rotateLocalAxis() work in the sprite coordinate system. In my case, using a version of the rotate or another leads to the same result: a rotation around the left bottom corner of the pixmap. My question is: How can I set up a rotation origin anywhere? Same question with scaling. Code-wise, here is what the thing looks like: //We are on my Pixmap::Draw() method LPD3DXMATRIXSTACK stack = (LPD3DXMATRIXSTACK)m_matrixStack; stack->Push(); stack->Scale(scaling.x, scaling.y, 1.0f); stack->RotateAxis(&rotAxis, params.rotation * s_radConv); stack->Translate(trans.x, trans.y, 0.0f); m_direct3DXSprite->Begin(D3DXSPRITE_ALPHABLEND); m_direct3DXSprite->SetTransform(stack->GetTop()); m_direct3DXSprite->Draw(pTexture, &p, NULL, NULL, color); m_direct3DXSprite->End(); stack->Pop(); with "trans" being the translation vector (2D), "scaling" the scale vector (2D) and rotAxis being the Z axis (D3DXVECTOR3(0.0f, 0.0f, 1.0f)).

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!