Skip to content

Instantly share code, notes, and snippets.

@NewProggie
Last active August 29, 2015 14:04
Show Gist options
  • Save NewProggie/924fbe55f16086158c2a to your computer and use it in GitHub Desktop.
Save NewProggie/924fbe55f16086158c2a to your computer and use it in GitHub Desktop.
Fast meshing of grid-like ordered vertices
/*****************************************************************************
* 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;
}
@NewProggie
Copy link
Author

Compile with: gcc -std=c99 create_faces.c -o create_faces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment