Generation functions use struct pointers now :)
This commit is contained in:
parent
5c579bed90
commit
8c507756c3
@ -67,7 +67,7 @@ int main()
|
||||
glBindVertexArray(vertexArrayID);
|
||||
|
||||
|
||||
GLuint programID = loadShaders( "src/SimpleVertexShader.vertexshader", "src/SimpleFragmentShader.fragmentshader" );
|
||||
GLuint programID = loadShaders( "src/shader.vert", "src/shader.frag" );
|
||||
|
||||
GLuint matrixID = glGetUniformLocation(programID, "MVP");
|
||||
|
||||
@ -78,7 +78,7 @@ int main()
|
||||
vec3s up = {0.0f, 1.0f, 0.0f};
|
||||
|
||||
vec3s planetPos = {0.0f, 0.0f, 0.0f};
|
||||
worldMesh mesh = generateWorld(planetPos);
|
||||
worldMesh* mesh = generateWorld(planetPos);
|
||||
setVertexBufferData(mesh.vertices, mesh.triangles, mesh.triangleArrayCount);
|
||||
|
||||
GLuint vertexbuffer;
|
||||
|
@ -9,17 +9,18 @@
|
||||
#define TWICE_RSQRT5 0.8944271909999159f
|
||||
#define GOLDEN 1.618033988749895f
|
||||
|
||||
worldMesh generateWorld(vec3s position)
|
||||
worldMesh* generateWorld(vec3s position)
|
||||
{
|
||||
// placeholder struct for world mesh
|
||||
world
|
||||
worldMesh* mesh = (worldMesh*) malloc(sizeof(worldMesh));
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
void populateIcosphere(unsigned char order, GLfloat radius)
|
||||
void populateIcosphere(worldMesh* mesh, unsigned char order, GLfloat radius)
|
||||
{
|
||||
int T = powf(4, order);
|
||||
mesh.vertexArrayCount = (10*T + 2) * 3; // Final heap array size for vertices
|
||||
mesh->vertexArrayCount = (10*T + 2) * 3; // Final heap array size for vertices
|
||||
|
||||
// Initial vertex array. Not used other than to initialize heap array in mesh
|
||||
GLfloat vertices[] = {
|
||||
@ -36,15 +37,15 @@ void populateIcosphere(unsigned char order, GLfloat radius)
|
||||
9, 8, 1, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7
|
||||
};
|
||||
|
||||
mesh.triangleArrayCount = 20*T*3;
|
||||
normalizeVertices(vertices, mesh.vertexArrayCount, radius);
|
||||
mesh->triangleArrayCount = 20*T*3;
|
||||
normalizeVertices(vertices, mesh->vertexArrayCount, radius);
|
||||
|
||||
// Move vetex and triangle data into mesh struct
|
||||
mesh.vertices = (GLfloat*) malloc(sizeof(GLfloat) * mesh.vertexArrayCount);
|
||||
memcpy(mesh.vertices, vertices, sizeof(GLfloat) * mesh.vertexArrayCount);
|
||||
mesh->vertices = (GLfloat*) malloc(sizeof(GLfloat) * mesh->vertexArrayCount);
|
||||
memcpy(mesh->vertices, vertices, sizeof(GLfloat) * mesh->vertexArrayCount);
|
||||
|
||||
mesh.triangles = (unsigned int*) malloc(sizeof(unsigned int) * mesh.triangleArrayCount);
|
||||
memcpy(mesh.triangles, triangles, sizeof(unsigned int) * 60);
|
||||
mesh->triangles = (unsigned int*) malloc(sizeof(unsigned int) * mesh->triangleArrayCount);
|
||||
memcpy(mesh->triangles, triangles, sizeof(unsigned int) * 60);
|
||||
}
|
||||
|
||||
void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius)
|
||||
|
@ -16,6 +16,6 @@ typedef struct worldMesh
|
||||
* @param[in] pos the position of the center of the roughly spherical world
|
||||
* @return the world mesh as a heap-allocated list of vertices.
|
||||
*/
|
||||
worldMesh generateWorld(vec3s pos);
|
||||
worldMesh populateIcosphere(unsigned char order, GLfoat radius);
|
||||
|
||||
worldMesh* generateWorld(vec3s pos);
|
||||
void populateIcosphere(worldMesh* mesh, unsigned char order, GLfoat radius);
|
||||
void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius);
|
||||
|
Loading…
Reference in New Issue
Block a user