Skip to content

Instantly share code, notes, and snippets.

@chengkehan
Created August 12, 2020 12:42
Show Gist options
  • Save chengkehan/edc0140c938ed2c8e1b5b36f78d37f89 to your computer and use it in GitHub Desktop.
Save chengkehan/edc0140c938ed2c8e1b5b36f78d37f89 to your computer and use it in GitHub Desktop.
// rotation and transform a 2d array
// aniticlockwise 90 degree
Vector2[] tUV2 = new Vector2[tUV.Length];
System.Array.Copy(tUV, 0, tUV2, 0, tUV.Length);
for (int pi = 0; pi < h; ++pi)
{
for (int pj = 0; pj < w; ++pj)
{
Vector2 pc = tUV2[pi * w + pj];
tUV[(w - pj - 1) * w + pi] = pc;
}
}
System.Array.Copy(tUV, 0, tUV2, 0, tUV.Length);
// Flip horizontal
for (int pi = 0; pi < h; ++pi)
{
for (int pj = 0; pj < w; ++pj)
{
Vector2 pc = tUV2[pi * w + pj];
tUV[(w - pi - 1) * w + pj] = pc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment