diff options
| author | Chris <[email protected]> | 2021-03-23 13:40:26 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-23 14:40:26 +0100 |
| commit | 2532c396edf08c997588c4fe2d8ddebaf224508b (patch) | |
| tree | c427178a0e2a49d6d808f2e49fb0f50c6ad9f8de /src/shapes.c | |
| parent | 71fe0bff95108fc905c3bcf5da3d95a09ce824ae (diff) | |
| download | raylib-2532c396edf08c997588c4fe2d8ddebaf224508b.tar.gz raylib-2532c396edf08c997588c4fe2d8ddebaf224508b.zip | |
Fix 90 degree bug with DrawTexturePro and DrawRectanglePro (#1673)
- The vertices did not map to where I expected causing rotation to be
off by 90 degrees. I reorganized the vertices making it easier to
reason about which fixes this.
- The order for drawing is now topLeft, bottomLeft, bottomRight,
topRight.
Diffstat (limited to 'src/shapes.c')
| -rw-r--r-- | src/shapes.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/shapes.c b/src/shapes.c index 0c580172..71287f52 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -619,20 +619,20 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color { rlCheckRenderBatchLimit(4); + Vector2 topLeft = { 0 }; + Vector2 topRight = { 0 }; Vector2 bottomLeft = { 0 }; Vector2 bottomRight = { 0 }; - Vector2 topRight = { 0 }; - Vector2 topLeft = { 0 }; // Only calculate rotation if needed if (rotation == 0.0f) { float x = rec.x - origin.x; float y = rec.y - origin.y; - bottomLeft = (Vector2){ x, y }; - bottomRight = (Vector2){ x, y + rec.height }; - topRight = (Vector2){ x + rec.width, y + rec.height }; - topLeft = (Vector2){ x + rec.width, y }; + topLeft = (Vector2){ x, y }; + topRight = (Vector2){ x + rec.width, y }; + bottomLeft = (Vector2){ x, y + rec.height }; + bottomRight = (Vector2){ x + rec.width, y + rec.height }; } else { @@ -643,17 +643,17 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color float dx = -origin.x; float dy = -origin.y; + topLeft.x = x + dx*cosRotation - dy*sinRotation; + topLeft.y = y + dx*sinRotation + dy*cosRotation; + + topRight.x = x + (dx + rec.width)*cosRotation - dy*sinRotation; + topRight.y = y + (dx + rec.width)*sinRotation + dy*cosRotation; + bottomLeft.x = x + dx*cosRotation - (dy + rec.height)*sinRotation; bottomLeft.y = y + dx*sinRotation + (dy + rec.height)*cosRotation; bottomRight.x = x + (dx + rec.width)*cosRotation - (dy + rec.height)*sinRotation; bottomRight.y = y + (dx + rec.width)*sinRotation + (dy + rec.height)*cosRotation; - - topRight.x = x + (dx + rec.width)*cosRotation - dy*sinRotation; - topRight.y = y + (dx + rec.width)*sinRotation + dy*cosRotation; - - topLeft.x = x + dx*cosRotation - dy*sinRotation; - topLeft.y = y + dx*sinRotation + dy*cosRotation; } rlEnableTexture(rlGetShapesTexture().id); @@ -663,16 +663,16 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color rlColor4ub(color.r, color.g, color.b, color.a); rlTexCoord2f(rlGetShapesTextureRec().x/rlGetShapesTexture().width, rlGetShapesTextureRec().y/rlGetShapesTexture().height); - rlVertex2f(bottomLeft.x, bottomLeft.y); + rlVertex2f(topLeft.x, topLeft.y); rlTexCoord2f(rlGetShapesTextureRec().x/rlGetShapesTexture().width, (rlGetShapesTextureRec().y + rlGetShapesTextureRec().height)/rlGetShapesTexture().height); - rlVertex2f(bottomRight.x, bottomRight.y); + rlVertex2f(bottomLeft.x, bottomLeft.y); rlTexCoord2f((rlGetShapesTextureRec().x + rlGetShapesTextureRec().width)/rlGetShapesTexture().width, (rlGetShapesTextureRec().y + rlGetShapesTextureRec().height)/rlGetShapesTexture().height); - rlVertex2f(topRight.x, topRight.y); + rlVertex2f(bottomRight.x, bottomRight.y); rlTexCoord2f((rlGetShapesTextureRec().x + rlGetShapesTextureRec().width)/rlGetShapesTexture().width, rlGetShapesTextureRec().y/rlGetShapesTexture().height); - rlVertex2f(topLeft.x, topLeft.y); + rlVertex2f(topRight.x, topRight.y); rlEnd(); rlDisableTexture(); |
