Skip to content

Instantly share code, notes, and snippets.

@yuriks
Created January 26, 2012 05:19
Show Gist options
  • Save yuriks/1681154 to your computer and use it in GitHub Desktop.
Save yuriks/1681154 to your computer and use it in GitHub Desktop.
u32 readWrappedTexel(CubeFace face, int x, int y) {
assert(face < NUM_FACES);
static const CubeFace face_left_of[] = {
/* FACE_POS_X */ FACE_POS_Z,
/* FACE_NEG_X */ FACE_NEG_Z,
/* FACE_POS_Y */ FACE_NEG_X,
/* FACE_NEG_Y */ FACE_NEG_X,
/* FACE_POS_Z */ FACE_NEG_X,
/* FACE_NEG_Z */ FACE_POS_X
};
static const CubeFace face_right_of[] = {
/* FACE_POS_X */ FACE_NEG_Z,
/* FACE_NEG_X */ FACE_POS_Z,
/* FACE_POS_Y */ FACE_POS_X,
/* FACE_NEG_Y */ FACE_POS_X,
/* FACE_POS_Z */ FACE_POS_X,
/* FACE_NEG_Z */ FACE_NEG_X
};
static const CubeFace face_above[] = {
/* FACE_POS_X */ FACE_POS_Y,
/* FACE_NEG_X */ FACE_POS_Y,
/* FACE_POS_Y */ FACE_NEG_Z,
/* FACE_NEG_Y */ FACE_POS_Z,
/* FACE_POS_Z */ FACE_POS_Y,
/* FACE_NEG_Z */ FACE_POS_Y
};
static const CubeFace face_under[] = {
/* FACE_POS_X */ FACE_NEG_Y,
/* FACE_NEG_X */ FACE_NEG_Y,
/* FACE_POS_Y */ FACE_POS_Z,
/* FACE_NEG_Y */ FACE_NEG_Z,
/* FACE_POS_Z */ FACE_NEG_Y,
/* FACE_NEG_Z */ FACE_NEG_Y
};
while (true) {
if (x < 0) {
CubeFace new_face = face_left_of[face];
if (face == FACE_POS_Y) {
int new_y = -x - 1;
x = y;
y = new_y;
} else if (face == FACE_NEG_Y) {
int new_x = faces[new_face].width - y - 1;
int new_y = faces[new_face].height + x;
x = new_x;
y = new_y;
} else {
x = faces[new_face].width + x;
}
face = new_face;
} else if (x >= faces[face].width) {
CubeFace new_face = face_right_of[face];
if (face == FACE_POS_Y) {
int new_x = faces[new_face].width - y - 1;
int new_y = x - faces[face].width;
x = new_x;
y = new_y;
} else if (face == FACE_NEG_Y) {
int new_y = faces[new_face].height - (x - faces[face].width) - 1;
x = y;
y = new_y;
} else {
x = x - faces[face].width;
}
face = new_face;
} else if (y < 0) {
CubeFace new_face = face_above[face];
if (false) {
// ...
} else {
y = faces[new_face].height + y;
}
} else if (y >= faces[face].height) {
// ...
} else {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment