It's up to you to which draw2DImage functions you will add this, it should work for all the same way. But as this are interface functions you will have to add the parameters to IVideoDriver and all it's derived classes.
Example:
Code: Select all
virtual void draw2DImage(video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false
, f32 angleInDegree=0.f) = 0;
1. translate to the center of the image (arbitrary centers not yet supported, but would be trivial to add)
2. rotate by given angle
3. translate back to original position
4. call the old draw code
5. reset the modelview/world matrix
For d3d it looks like this:
Code: Select all
if ( angleInDegree != 0.f )
{
f32 cx = (vtx[0].Pos.X + vtx[2].Pos.X) / 2;
f32 cy = (vtx[0].Pos.Y + vtx[2].Pos.Y) / 2;
D3DXMATRIX mtrans1;
D3DXMATRIX mRotation;
D3DXMATRIX mtrans2;
D3DXMATRIX mAllTogetherNow;
D3DXMatrixTranslation( &mtrans1, cx, cy, 0.f );
D3DXMatrixRotationZ( &mRotation, D3DXToRadian( angleInDegree ) );
D3DXMatrixTranslation( &mtrans2, -cx, -cy, 0.f );
mAllTogetherNow = mtrans2 * mRotation * mtrans1;
pID3DDevice->SetTransform( D3DTS_WORLD, &mAllTogetherNow );
}
// here is the usual drawing code like:
// pID3DDevice->DrawIndexedPrimitiveUP
if ( angleInDegree != 0.f )
{
core::matrix4 mat;
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)mat.pointer()));
}
Code: Select all
if ( angleInDegree != 0.f )
{
f32 cx = (npos.UpperLeftCorner.X + npos.LowerRightCorner.X) / 2;
f32 cy = (npos.UpperLeftCorner.Y + npos.LowerRightCorner.Y) / 2;
glMatrixMode(GL_MODELVIEW);
glTranslatef(cx, cy, 0);
glRotatef(angleInDegree, 0.0, 0.0, 1.0);
glTranslatef(-cx, -cy, 0);
}
// here is the usual drawing code like:
// glColor4ub
// glBegin(GL_QUADS);
// <snip>
// glEnd();
if ( angleInDegree != 0.f )
{
glLoadIdentity();
}