X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=aeb57a64e2b572cf667323e822792361d1747b9e;hb=HEAD;hp=1246d2f6edec544c5188f56eff50ad09c2e5986c;hpb=978140660bed8a4bbe782dc5ca0516a80e1ba233;p=demo diff --git a/src/main.cc b/src/main.cc index 1246d2f..aeb57a6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -27,6 +28,7 @@ static bool init(Gfx_API api); static void cleanup(); static void display(); +static bool gen_poisson(std::vector &points, float min_dist, float radius); /* glfw callbacks */ @@ -58,13 +60,19 @@ static Vec3 cam_pos; static float aspect; static OrbitCamera *camera; +static float fog_density; + +static int num_cows = 1; +static float cow_gap = 4; static Scene *cow_scene; -static Object *cow_object; static MorphRenderer *cow_rend; static Terrain terrain; +static TerrainParams p; static Texture *skybox_tex; +static Texture *irradiance_tex; static Texture *terrain_tex; +static Texture *dirt_tex; static Material terrain_mat; static Renderer *terrain_rend; @@ -74,7 +82,7 @@ int main(int argc, char **argv) { Gfx_API api; - for(int i=0; iload("data/spot/spot.obj")) { - fprintf(stderr, "Failed to load scene: spot.obj.\n"); - return false; - } - - cow_rend = new MorphRenderer; - cow_rend->camera = camera; - cow_rend->scene = cow_scene; - - if(!cow_rend->create()) { - fprintf(stderr, "Failed to create renderer for cows.\n"); + terrain_tex = gfx_create_texture(); + if(!terrain_tex->load("data/grass.jpeg")) { + fprintf(stderr, "Failed to load ground grass texture.\n"); return false; } - cow_object = cow_scene->objects[0]; - - terrain_tex = gfx_create_texture(); - if(!terrain_tex->load("data/grass.jpeg")) { - fprintf(stderr, "Failed to load ground texture.\n"); + dirt_tex = gfx_create_texture(); + if(!dirt_tex->load("data/dirt.jpg")) { + fprintf(stderr, "Failed to load ground dirt texture.\n"); return false; } @@ -152,12 +153,11 @@ static bool init(Gfx_API api) return false; } - TerrainParams p; - p.xsz = 200; - p.ysz = 200; - p.max_height = 30; - p.xtiles = 40; - p.ytiles = 40; + p.xsz = 20;//200; + p.ysz = 20; //200; + p.max_height = 3;//30; + p.xtiles = 4;//40; + p.ytiles = 4;//40; p.tile_usub = 10; p.tile_vsub = 10; p.num_octaves = 3; @@ -183,11 +183,56 @@ static bool init(Gfx_API api) skybox_tex->load("data/cubemap/cubemap.hdr"); terrain_rend->set_sky_tex(skybox_tex); + irradiance_tex = gfx_create_texture(); + irradiance_tex->load("data/cubemap/irradiance.hdr"); + terrain_rend->set_diffuse_sky_tex(irradiance_tex); + if(!terrain_rend->create()) { fprintf(stderr, "terrain fail\n"); return false; } + terrain_rend->fog_density = fog_density; + + cow_scene = new Scene; + if(!cow_scene->load("data/spot/spot.obj")) { + fprintf(stderr, "Failed to load scene: spot.obj.\n"); + return false; + } + + cow_rend = new MorphRenderer; + cow_rend->camera = camera; + cow_rend->scene = cow_scene; + cow_rend->fog_density = fog_density; + + if(!cow_rend->create()) { + fprintf(stderr, "Failed to create renderer for cows.\n"); + return false; + } + + /* create cow objects */ + Object *cow0 = cow_scene->objects[0]; + cow0->transform.rotation_y(M_PI); + cow_scene->objects.clear(); + + float disk_radius = std::min(p.xsz, p.ysz) / 2.0 * 0.65; + std::vector cow_pos; + for(int i=0; itransform.translate(pos.x, y, pos.y); + cow_scene->objects.push_back(cow); + } + +cowgen_end: + printf("generated: %d cows from %d\n", (int)cow_pos.size(), num_cows); + delete cow0; return true; } @@ -199,9 +244,11 @@ static void cleanup() delete cow_scene; delete cow_rend; -//TODO + delete skybox_tex; + delete irradiance_tex; delete terrain_tex; delete terrain_rend; + gfx_cleanup(); } @@ -223,6 +270,22 @@ static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mod move_camera = !move_camera; break; + // case 'F': + // fog_density = fog_density < 1 - 0.0009 ? fog_density + 0.0001 : 1; + // break; + + // case 'U': + // fog_density = fog_density > 0.0001 ? fog_density - 0.0001 : 0; + // break; + + case 'P': + gfx_wireframe(true); + break; + + case 'F': + gfx_wireframe(false); + break; + default: break; } @@ -260,7 +323,7 @@ static void clbk_motion(GLFWwindow *win, double x, double y) cam_dist = 0.0; } } - } +} static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods) { @@ -270,6 +333,7 @@ static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods) static void clbk_reshape(GLFWwindow *win, int width, int height) { + gfx_reshape(width, height); gfx_viewport(0, 0, width, height); aspect = (float)width / (float)height; mprojection = calc_projection_matrix(45, aspect, 0.5, 1000.0); @@ -310,11 +374,38 @@ static void display() camera->set_orbit_params(cam_theta, cam_phi, cam_dist); camera->set_position(cam_pos.x, cam_pos.y, cam_pos.z); + gfx_begin_drawing(); + gfx_clear(0.1, 0.1, 0.1); terrain_rend->draw(); - - cow_pos.y = terrain.get_height(cow_pos); - cow_object->transform.translation(cow_pos); cow_rend->draw(); -} \ No newline at end of file + + gfx_end_drawing(); +} + +static bool gen_poisson(std::vector &points, float min_dist, float radius) +{ + /* poisson radius */ + for(int i = 0; i < 1000; i++) { + float angle = (float)rand() / (float)RAND_MAX * 2 * M_PI; + float r = sqrt((float)rand() / (float)RAND_MAX) * radius; + + Vec2 p; + p.x = cos(angle) * r; + p.y = sin(angle) * r; + + bool valid = true; + for(size_t j=0; j