Icosohedron scaling from worldgen
This commit is contained in:
parent
8c507756c3
commit
53c6256e9c
BIN
PlanetMiner
BIN
PlanetMiner
Binary file not shown.
BIN
bin/main.o
BIN
bin/main.o
Binary file not shown.
BIN
bin/worldgen.o
BIN
bin/worldgen.o
Binary file not shown.
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;
|
||||
}
|
||||
|
||||
@ -58,8 +58,7 @@ void normalizeVertices(GLfloat* vertices, unsigned int vertexArrayCount, GLfloat
|
||||
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);
|
||||
|
9
todo.md
9
todo.md
@ -5,6 +5,7 @@
|
||||
- [x] Render a cube
|
||||
- [x] Render icosahedron
|
||||
- [ ] Vertices to triangle mesh
|
||||
- [ ] Diffuse shader
|
||||
- [ ] Subdivide icosahedron
|
||||
2. Procedural worlds
|
||||
- [ ] Morph vertices of the subdivided icosphere
|
||||
@ -41,8 +42,16 @@
|
||||
- Game starts on an Earth-like planet
|
||||
- Make basic tool with sticks rope and stone fragments
|
||||
- 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
|
||||
- Error Codes!
|
||||
- In-Game Wiki-System
|
||||
- Build wiki with some kind of knowledge tree
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user