Icosohedron scaling from worldgen
This commit is contained in:
38
src/main.c
38
src/main.c
@ -79,7 +79,7 @@ int main()
|
||||
|
||||
vec3s planetPos = {0.0f, 0.0f, 0.0f};
|
||||
worldMesh* mesh = generateWorld(planetPos);
|
||||
setVertexBufferData(mesh.vertices, mesh.triangles, mesh.triangleArrayCount);
|
||||
setVertexBufferData(mesh->vertices, mesh->triangles, mesh->triangleArrayCount);
|
||||
|
||||
GLuint vertexbuffer;
|
||||
glGenBuffers(1, &vertexbuffer);
|
||||
@ -90,42 +90,10 @@ int main()
|
||||
|
||||
printf("Entering main loop\n");
|
||||
|
||||
float theta = 0.0f;
|
||||
float radius = 5.0f;
|
||||
|
||||
do
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
if( glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS )
|
||||
{
|
||||
radius -= 0.05f;
|
||||
}
|
||||
if( glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS )
|
||||
{
|
||||
radius += 0.05f;
|
||||
}
|
||||
if( glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS )
|
||||
{
|
||||
theta += 0.05f;
|
||||
}
|
||||
if( glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS )
|
||||
{
|
||||
theta -= 0.05f;
|
||||
}
|
||||
if( glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS )
|
||||
{
|
||||
// eye.y += 0.05f;
|
||||
}
|
||||
if( glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS )
|
||||
{
|
||||
// eye.y -= 0.05f;
|
||||
}
|
||||
|
||||
// center = glms_vec3_add(eye, direction);
|
||||
eye.x = radius * sinf(theta);
|
||||
eye.z = radius * cosf(theta);
|
||||
|
||||
mat4s view = glms_lookat(eye, center, up);
|
||||
mat4s model = glms_mat4_identity();
|
||||
mat4s mvp = glms_mat4_mul(glms_mat4_mul(projection, view), model);
|
||||
@ -230,8 +198,10 @@ GLuint loadShaders(const char* vertexShaderPath, const char* fragmentShaderPath)
|
||||
|
||||
void setVertexBufferData(GLfloat* vertices, unsigned int* triangles, unsigned int triangleCount)
|
||||
{
|
||||
printf("Loading %d triangles into buffer\n", triangleCount);
|
||||
for( int i = 0; i < triangleCount; ++i )
|
||||
{
|
||||
vertexBufferData[i*3] = vertices[triangles[i]*3];
|
||||
vertexBufferData[i*3 + 1] = vertices[triangles[i]*3 + 1];
|
||||
vertexBufferData[i*3 + 2] = vertices[triangles[i]*3 + 2];
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ worldMesh* generateWorld(vec3s position)
|
||||
{
|
||||
// placeholder struct for world mesh
|
||||
worldMesh* mesh = (worldMesh*) malloc(sizeof(worldMesh));
|
||||
|
||||
populateIcosphere(mesh, ORDER, 1.0f);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -57,9 +57,8 @@ void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat
|
||||
vertex.x = vertices[i];
|
||||
vertex.y = vertices[i + 1];
|
||||
vertex.z = vertices[i + 2];
|
||||
|
||||
glms_vec3_normalize(vertex);
|
||||
glms_vec3_scale(vertex, radius);
|
||||
|
||||
vertex = glms_vec3_scale_as(vertex, radius);
|
||||
|
||||
vertices[i] = vertex.x;
|
||||
vertices[i + 1] = vertex.y;
|
||||
|
@ -17,5 +17,5 @@ typedef struct worldMesh
|
||||
* @return the world mesh as a heap-allocated list of vertices.
|
||||
*/
|
||||
worldMesh* generateWorld(vec3s pos);
|
||||
void populateIcosphere(worldMesh* mesh, unsigned char order, GLfoat radius);
|
||||
void populateIcosphere(worldMesh* mesh, unsigned char order, GLfloat radius);
|
||||
void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius);
|
||||
|
Reference in New Issue
Block a user