Sign in to follow this  

OpenGL DirectX Sprite transformation origin

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

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