void GLInterface::DrawImage( unsigned int layerNum, unsigned int size, unsigned int frame, float x, float y, float hScale, float vScale, float angle, const TColour* colour )
{
assert( layerNum < _dynamicLayers.size() );
y = _h - y;
float w = frameSizes[ size ] * hScale;
float h = frameSizes[ size ] * vScale;
float xOfs = w * 0.5;
float yOfs = h * 0.5;
TRect quad;
quad.x[ 0 ] = x - xOfs;
quad.y[ 0 ] = y - yOfs;
quad.x[ 1 ] = quad.x[ 0 ] + w;
quad.y[ 1 ] = quad.y[ 0 ] + h;
TRect* texRect = &_textures[ _dynamicLayers[ layerNum ]->textureNum ]->texRects[ size ][ frame ];
const TColour* destColour = &_white;
if (colour) { destColour = colour; }
if ( angle == 0.0 ) // add non-rotated quad
{
_dynamicLayers[ layerNum ]->buffer->AddQuad( quad, *texRect, *destColour );
}
else // add rotated quad.
{
// all this stuff is what rotates the corners. probably a way faster way to do it.. affine matrices? i dunno
float newX[ 4 ];
float newY[ 4 ];
newX[ 0 ] = cosf( angle ) * ( quad.x[ 0 ] - x ) - sinf( angle ) * ( quad.y[ 0 ] - y ) + x;
newY[ 0 ] = sinf( angle ) * ( quad.x[ 0 ] - x ) + cosf( angle ) * ( quad.y[ 0 ] - y ) + y;
newX[ 1 ] = cosf( angle ) * ( quad.x[ 1 ] - x ) - sinf( angle ) * ( quad.y[ 0 ] - y ) + x;
newY[ 1 ] = sinf( angle ) * ( quad.x[ 1 ] - x ) + cosf( angle ) * ( quad.y[ 0 ] - y ) + y;
newX[ 2 ] = cosf( angle ) * ( quad.x[ 0 ] - x ) - sinf( angle ) * ( quad.y[ 1 ] - y ) + x;
newY[ 2 ] = sinf( angle ) * ( quad.x[ 0 ] - x ) + cosf( angle ) * ( quad.y[ 1 ] - y ) + y;
newX[ 3 ] = cosf( angle ) * ( quad.x[ 1 ] - x ) - sinf( angle ) * ( quad.y[ 1 ] - y ) + x;
newY[ 3 ] = sinf( angle ) * ( quad.x[ 1 ] - x ) + cosf( angle ) * ( quad.y[ 1 ] - y ) + y;
_dynamicLayers[ layerNum ]->buffer->AddQuad(newX[ 0 ], newY[ 0 ], newX[ 1 ], newY[ 1 ], newX[ 2 ], newY[ 2 ], newX[ 3 ], newY[ 3 ], *texRect, *destColour );
}
}