Icosohedron scaling from worldgen

This commit is contained in:
Adog64 2023-12-13 21:43:12 -05:00
parent 8c507756c3
commit 53c6256e9c
7 changed files with 17 additions and 39 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -79,7 +79,7 @@ int main()
vec3s planetPos = {0.0f, 0.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); setVertexBufferData(mesh->vertices, mesh->triangles, mesh->triangleArrayCount);
GLuint vertexbuffer; GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer); glGenBuffers(1, &vertexbuffer);
@ -90,42 +90,10 @@ int main()
printf("Entering main loop\n"); printf("Entering main loop\n");
float theta = 0.0f;
float radius = 5.0f;
do do
{ {
glClear( GL_COLOR_BUFFER_BIT ); 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 view = glms_lookat(eye, center, up);
mat4s model = glms_mat4_identity(); mat4s model = glms_mat4_identity();
mat4s mvp = glms_mat4_mul(glms_mat4_mul(projection, view), model); 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) 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 ) 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];
} }
} }

View File

@ -13,7 +13,7 @@ worldMesh* generateWorld(vec3s position)
{ {
// placeholder struct for world mesh // placeholder struct for world mesh
worldMesh* mesh = (worldMesh*) malloc(sizeof(worldMesh)); worldMesh* mesh = (worldMesh*) malloc(sizeof(worldMesh));
populateIcosphere(mesh, ORDER, 1.0f);
return mesh; return mesh;
} }
@ -57,9 +57,8 @@ void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat
vertex.x = vertices[i]; vertex.x = vertices[i];
vertex.y = vertices[i + 1]; vertex.y = vertices[i + 1];
vertex.z = vertices[i + 2]; vertex.z = vertices[i + 2];
glms_vec3_normalize(vertex); vertex = glms_vec3_scale_as(vertex, radius);
glms_vec3_scale(vertex, radius);
vertices[i] = vertex.x; vertices[i] = vertex.x;
vertices[i + 1] = vertex.y; vertices[i + 1] = vertex.y;

View File

@ -17,5 +17,5 @@ typedef struct worldMesh
* @return the world mesh as a heap-allocated list of vertices. * @return the world mesh as a heap-allocated list of vertices.
*/ */
worldMesh* generateWorld(vec3s pos); 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); void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat radius);

View File

@ -5,6 +5,7 @@
- [x] Render a cube - [x] Render a cube
- [x] Render icosahedron - [x] Render icosahedron
- [ ] Vertices to triangle mesh - [ ] Vertices to triangle mesh
- [ ] Diffuse shader
- [ ] Subdivide icosahedron - [ ] Subdivide icosahedron
2. Procedural worlds 2. Procedural worlds
- [ ] Morph vertices of the subdivided icosphere - [ ] Morph vertices of the subdivided icosphere
@ -41,8 +42,16 @@
- Game starts on an Earth-like planet - Game starts on an Earth-like planet
- Make basic tool with sticks rope and stone fragments - Make basic tool with sticks rope and stone fragments
- Stone fragments from smashing stones on rock - Stone fragments from smashing stones on rock
- Crash Landed ship, rebuild it as part of the tutorial
- Build warp drive to unlock multiplayer
- Warp to beacon or something
- Invite only/whitelist beacons?
- Public beacons
4. Documentation 4. Documentation
- Error Codes! - Error Codes!
- In-Game Wiki-System - In-Game Wiki-System
- Build wiki with some kind of knowledge tree