+
+ p.xsz = 200;
+ p.ysz = 200;
+ p.max_height = 30;
+ p.xtiles = 40;
+ p.ytiles = 40;
+ p.tile_usub = 10;
+ p.tile_vsub = 10;
+ p.num_octaves = 3;
+ p.noise_freq = 5;
+ p.coarse_heightmap = ter_hmap;
+
+ terrain.init();
+ terrain.generate(p);
+
+ terrain_mat.diffuse = Vec3(1, 1, 1);
+ terrain_mat.specular = Vec3(0, 0, 0);
+ terrain_mat.shininess = 40;
+ terrain_mat.dtex = terrain_tex;
+ terrain_mat.name = "tt";
+
+ terrain.material = terrain_mat;
+
+ terrain_rend = new Renderer;
+ terrain_rend->camera = camera;
+ terrain_rend->scene = terrain.get_visible(camera);
+
+ skybox_tex = gfx_create_texture();
+ 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<Vec2> cow_pos;
+
+ for(int i=0; i<num_cows; i++) {
+ Object *cow = new Object;
+ *cow = *cow0;
+
+ if(!gen_poisson(cow_pos, cow_gap, disk_radius))
+ goto cowgen_end;
+ Vec2 pos = cow_pos.back();
+ float y = terrain.get_height(Vec3(pos.x, 1, pos.y));
+
+ cow->transform.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;