Created
September 30, 2012 20:43
-
-
Save emoon/3808389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct Poly | |
{ | |
int x, y, z, .. // etc values | |
struct Poly* next; | |
} Poly; | |
Poly* g_sortArray[MaxBuckets]; | |
static void addPoly(Poly* poly, int z) | |
{ | |
poly->next = 0; | |
// must make sure Z is within range here otherwise it can go bad (memory trashing) | |
Poly* sortPoly = &g_sortArray[z]; | |
if (!sortPoly) | |
g_sortArray[z] = poly; | |
else | |
sortPoly->next = poly; | |
} | |
void updateScene() | |
{ | |
memset(g_sortArray, 0, sizeof(Poly*) * MaxBuckets); | |
// rotate, etc stuff here | |
for (poly in polys) | |
addPoly(poly, Poly_calcZ(poly)); | |
renderPolys(); | |
} | |
void renderPolys() | |
{ | |
for (uint i = 0; i < MaxBuckets; ++i) | |
{ | |
const Poly* poly = &g_sortArray[i]; | |
if (!poly) | |
continue; | |
while (poly) | |
{ | |
drawPoly(poly); | |
poly = poly->next; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment