Jump to content

Texture altas and pivot points


knoxcoder

Recommended Posts

I'm having trouble getting the images to line up correctly when we export a texture atlas that trims empty space.

Correct version:

post-10655-14159834127904_thumb.png

I thought I could scale the quad based on the original vs atlas size:


Rect size(0, 0, originalSize.x, originalSize.y);
Vector2 temp(originalSize.x * pivot.x, originalSize.y * pivot.y);
size -= temp;

float sx = textureSize.x / originalSize.x;
float sy = textureSize.y / originalSize.y;

size.left *= sx; size.right *= sx;
size.top *= sy; size.bottom *= sy;

It produces this:

post-10655-14159834125658_thumb.png

So next I tried to use the offset from the top/left which is the amount removed from the top/left. The idea is to compute the original quad and then get the true quad based on that:


Rect size(0, 0, originalSize.x, originalSize.y);
Vector2 temp(originalSize.x * pivot.x, originalSize.y * pivot.y);
size -= temp;

size.left += offset.x;
size.right += offset.y;
size.right = size.left + textureSize.x;
size.bottom = size.top + textureSize.y;

It produces this:

post-10655-14159834127072_thumb.png

Any ideas what I'm doing wrong here?

Robert

Link to comment
Share on other sites

Hi Robert,

I think the following would work, and if I were making the implementation, I would personally do this at load time, and keep the updated pivot points in your dom in place of the ones from the file.

Sorry for the late reply, and let me know if this works:

originalSize (as written in the scml file for each file)

newSize(the new size based on the trimmed atlas file)

topLeft(the top left offset in the trimmed atlas)

originalPivotAbsoluteX=originalSize.x*pivotX;

newPivotAbsoluteX=originalPivotX-topLeft.x;

newPivotX=newPivotAbsoluteX/newSize.x;

originalPivotAbsoluteY=originalSize.y*pivotY;

newPivotAbsoluteY=originalPivotY-topLeft.y;

newPivotY=newPivotAbsoluteY/newSize.y;

then your new pivot point is newPivotX,newPivotY

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...