Last active
August 29, 2015 14:04
-
-
Save NewProggie/924fbe55f16086158c2a to your computer and use it in GitHub Desktop.
Fast meshing of grid-like ordered vertices
This file contains 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
/***************************************************************************** | |
* Fast meshing of grid-like ordered vertices. | |
* This code snippet shows the indexing for a faces array to mesh grid-like | |
* ordered vertices using only one for loop. The indexing looks as follows: | |
* | |
* 0-----1-----2-----3 | |
* | //| //| //| | |
* | // | // | // | | |
* | // | // | // | | |
* |// |// |// | | |
* 4-----5-----6-----7 | |
* | //| //| //| | |
* | // | // | // | | |
* | // | // | // | | |
* |// |// |// | | |
* 8-----9-----10----11 | |
* | //| //| //| | |
* | // | // | // | | |
* | // | // | // | | |
* |// |// |// | | |
* 12----13----14----15 | |
*/ | |
#include <stdio.h> | |
int main() { | |
int cols = 4; | |
int rows = 4; | |
int nmax = (cols*rows)-2; | |
for(int n=0; n<cols*(rows-1); n+=1+((n+2)%cols==0)) { | |
printf("(%d, %d, %d), (%d, %d, %d)\n", n, n+cols, n+1, nmax-n, | |
nmax-n+1, nmax-n-cols+1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile with: gcc -std=c99 create_faces.c -o create_faces