Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for rotated sprite geometries coming from the new atlas api #8863

Merged
merged 1 commit into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -263,9 +263,21 @@ private static SpriteGeometry.Builder createSpriteGeometryFromRect(Rect rect) {

int imageWidth = rect.getWidth();
int imageHeight = rect.getHeight();
builder.setWidth(imageWidth);
builder.setHeight(imageHeight);
builder.setRotated(rect.getRotated());
boolean rotated = rect.getRotated();
builder.setRotated(rotated);

if (rotated)
{
// for legacy reasons, we need to rotate it back
// The geometry wants the size in unrotated form
builder.setWidth(imageHeight);
builder.setHeight(imageWidth);
}
else
{
builder.setWidth(imageWidth);
builder.setHeight(imageHeight);
}
Comment on lines +269 to +280
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually, I'd like to centralize these things even more, but for now I think it's good enough.


TextureSetLayout.Point center = rect.getCenter();
builder.setCenterX(center.x);
Expand Down Expand Up @@ -783,11 +795,6 @@ private static void putTexDim(ByteBuffer texDimsBuffer, float w, float h) {
private static void putRect(Rect r, float oneOverWidth, float oneOverHeight, ByteBuffer texCoordsBuffer, ByteBuffer texDimsBuffer) {
float width = r.getWidth();
float height = r.getHeight();
float x0 = r.getX();
float y0 = r.getY();
float x1 = x0 + width;
float y1 = y0 + height;

if (r.getRotated()) {
putRotatedQuad(texCoordsBuffer, r, oneOverWidth, oneOverHeight);
putTexDim(texDimsBuffer, height, width);
Expand Down
Expand Up @@ -510,6 +510,28 @@ public List<Integer> getIndices() {
public void setIndices(List<Integer> indices) {
this.indices = indices;
}

public void debugPrint() {
System.out.printf("SourceImage {\n");
System.out.printf(" name: %s\n", name);
System.out.printf(" rotated: %s\n", rotated?"true":"false");
//System.out.printf(" originalSize: %f, %f\n", originalSize.width, originalSize.height);
System.out.printf(" rect: %f, %f\n", rect.width, rect.height);
System.out.printf(" vertices: {\n");
for (Point p : vertices)
{
System.out.printf(" %f, %f\n", p.x, p.y);
}
System.out.printf(" }\n");
System.out.printf(" indices: {\n");
for (int i : indices)
{
System.out.printf(" %d", i);
}
System.out.printf("\n");
System.out.printf(" }\n");
System.out.printf("}\n");
}
}

// Public api for extensions!
Expand Down