X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=demos%2Fdesertpillars%2Fsource%2Fdesertpillars.cpp;h=513d81743d700dec32bc734eea0ff63357ea4a49;hb=be3b67fdd0d0420ffc1e97a6535159c63a97fdc8;hp=124df81cfb14e4cb41271c98ee9df943919bf7bd;hpb=b206e8ed328e63c0e3aef33e9aad61ce49496c8b;p=libs%2Fgl.git diff --git a/demos/desertpillars/source/desertpillars.cpp b/demos/desertpillars/source/desertpillars.cpp index 124df81c..513d8174 100644 --- a/demos/desertpillars/source/desertpillars.cpp +++ b/demos/desertpillars/source/desertpillars.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -28,23 +29,32 @@ DesertPillars::DesertPillars(int, char **): sphere_morph(0.0f), sphere_frozen(false), sphere_stopped(false), + sun(resources.get("Sun.light")), + sun_angle(Geometry::Angle::from_turns(0.1f)), camera_stopped(false) { window.set_title("Desert Pillars"); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &DesertPillars::exit), 0)); keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &DesertPillars::key_press), false)); - GL::Light &sun = resources.get("Sun.light"); - sky = make_unique(content, sun); + env_seq = make_unique(); + env_seq->set_clear_enabled(true); + env_seq->set_debug_name("Environment sequence"); + + global_env = make_unique(32, GL::RGB16F, 2, content, *env_seq); + global_env->set_fixed_position(GL::Vector3(0.0f, 0.0f, 0.0f)); + global_env->set_debug_name("Global environment"); + + sky = make_unique(*global_env, sun); sky->set_debug_name("Sky"); - unsigned shadow_size = 8192; - shadow_seq = make_unique(shadow_size, shadow_size); + shadow_seq = make_unique(); + shadow_seq->set_clear_enabled(true); shadow_seq->set_debug_name("Shadow sequence"); GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content); - step->set_depth_test(&GL::DepthTest::lequal()); + step->set_depth_test(GL::LEQUAL); - shadow_map = make_unique(shadow_size, *sky, sun, *shadow_seq); + shadow_map = make_unique(8192, *sky, sun, *shadow_seq); shadow_map->set_debug_name("Shadow map"); shadow_map->set_target(GL::Vector3(0.0f, 0.0f, 0.0f), 20.0f); @@ -53,12 +63,9 @@ DesertPillars::DesertPillars(int, char **): seq_bld.set_debug_name("Main sequence"); sequence.reset(seq_bld.build(view)); - unsigned env_size = 256; - env_seq = make_unique(env_size, env_size); - env_seq->set_debug_name("Environment sequence"); step = &env_seq->add_step("", *shadow_map); step->set_lighting(&resources.get("Desert.lightn")); - step->set_depth_test(&GL::DepthTest::lequal()); + step->set_depth_test(GL::LEQUAL); env_map = make_unique(256, GL::RGB16F, 7, sphere, *env_seq); env_map->set_debug_name("Environment map"); @@ -72,6 +79,10 @@ DesertPillars::DesertPillars(int, char **): view.set_content(sequence.get()); view.set_camera(&camera); + const GL::Vector3 &sun_direction = sun.get_direction(); + sun_node = normalize(GL::Vector3(sun_direction.y, -sun_direction.x, 0.0f)); + sun_axis = normalize(cross(sun_direction, sun_node)); + const GL::Vector3 &cam_pos = camera.get_position(); camera_distance = cam_pos.norm(); camera_angle = Geometry::atan2(cam_pos.y, cam_pos.x); @@ -112,6 +123,9 @@ void DesertPillars::tick() camera.set_look_direction(-cam_dir); } + sun_angle += Geometry::Angle::from_degrees(4*dt/Time::sec); + sun.set_direction(GL::Matrix::rotation(sun_angle, sun_axis)*-sun_node); + display.tick(); view.render(); }