Added vertex rotation support to DrawSpriteExRotate

Allows for rotations that are not a multiple of 90 degrees
master
palana 2013-09-12 03:39:32 +02:00
parent 6e8b6824a2
commit 8890fdfe11
4 changed files with 24 additions and 7 deletions

View File

@ -513,7 +513,7 @@ protected:
public:
virtual void CopyTexture(Texture *texDest, Texture *texSrc)=0;
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees)=0;
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float degrees, float u, float v, float u2, float v2, float texDegrees)=0;
};

View File

@ -799,10 +799,10 @@ void D3D10System::SetCropping(float left, float top, float right, float bottom)
void D3D10System::DrawSpriteEx(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2)
{
DrawSpriteExRotate(texture, color, x, y, x2, y2, u, v, u2, v2, 0.0f);
DrawSpriteExRotate(texture, color, x, y, x2, y2, 0.0f, u, v, u2, v2, 0.0f);
}
void D3D10System::DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees)
void D3D10System::DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float degrees, float u, float v, float u2, float v2, float texDegrees)
{
if(!curPixelShader)
return;
@ -866,16 +866,33 @@ void D3D10System::DrawSpriteExRotate(Texture *texture, DWORD color, float x, flo
data->VertList[2].Set(x2, y, 0.0f);
data->VertList[3].Set(x2, y2, 0.0f);
if (!CloseFloat(degrees, 0.0f)) {
List<Vect> &coords = data->VertList;
Vect2 center(x+totalSize.x/2, y+totalSize.y/2);
Matrix rotMatrix;
rotMatrix.SetIdentity();
rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, RAD(degrees)));
for (int i = 0; i < 4; i++) {
Vect val = coords[i]-Vect(center);
val.TransformVector(rotMatrix);
coords[i] = val;
coords[i] += Vect(center);
}
}
List<UVCoord> &coords = data->UVList[0];
coords[0].Set(u, v);
coords[1].Set(u, v2);
coords[2].Set(u2, v);
coords[3].Set(u2, v2);
if (!CloseFloat(degrees, 0.0f)) {
if (!CloseFloat(texDegrees, 0.0f)) {
Matrix rotMatrix;
rotMatrix.SetIdentity();
rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, -RAD(degrees)));
rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, -RAD(texDegrees)));
Vect2 minVal = Vect2(0.0f, 0.0f);
for (int i = 0; i < 4; i++) {

View File

@ -459,7 +459,7 @@ public:
virtual void SetCropping(float left, float top, float right, float bottom);
virtual void CopyTexture(Texture *texDest, Texture *texSrc);
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2, float degrees);
virtual void DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float degrees, float u, float v, float u2, float v2, float texDegrees);
};
inline ID3D10Device* GetD3D() {return static_cast<ID3D10Device*>(GS->GetDevice());}

View File

@ -483,7 +483,7 @@ public:
lrCoord.x, lrCoord.y);
else
GS->DrawSpriteExRotate(lastRendered, (opacity255<<24) | 0xFFFFFF,
pos.x, pos.y, pos.x+size.x, pos.y+size.y,
pos.x, pos.y, pos.x+size.x, pos.y+size.y, 0.0f,
ulCoord.x, ulCoord.y,
lrCoord.x, lrCoord.y, rotateDegrees);