X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Flayout.cpp;h=29e6bb40daeb4a45dd686871bae173122eebf4dd;hb=6aa6e3a60c31d71e8f8117be1ddf547897d19bd8;hp=0b457559f92d7bd8c532c1273a619606a613f225;hpb=894276fb6284f817be627a92ac68584e8cb3c288;p=r2c2.git diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index 0b45755..29e6bb4 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -17,8 +17,8 @@ Layout3D::Layout3D(Layout &l): { // South, 15° from zenith sun.set_position(GL::Vector4(0, -0.259, 0.966, 0)); - sun.set_diffuse(GL::Color(0.9)); - lighting.set_ambient(GL::Color(0.4)); + sun.set_diffuse(GL::Color(0.7)); + lighting.set_ambient(GL::Color(0.2)); lighting.attach(0, sun); layout.signal_object_added.connect(sigc::mem_fun(this, &Layout3D::object_added)); @@ -62,6 +62,24 @@ void Layout3D::remove(Utility3D &u) utilities.erase(&u); } +void Layout3D::tick() +{ + Time::TimeDelta t = layout.get_clock().get_current_time(); + Angle time_of_day = Angle::from_turns(t/Time::day); + Angle latitude = Angle::from_degrees(52.5); + Angle axial_tilt = Angle::from_degrees(23.45); + Transform trans = Transform::rotation(Angle::quarter_turn()-latitude, Vector(-1, 0, 0))* + Transform::rotation(Angle::half_turn()-time_of_day, Vector(0, 0, 1))* + Transform::rotation(axial_tilt, Vector(-1, 0, 0)); + Vector sun_dir = trans.transform_linear(Vector(0, -1, 0)); + Vector diff = Vector(sun.get_position())-sun_dir; + if(diff.norm()>0.0025f) + sun.set_position(GL::Vector4(sun_dir, 0.0f)); + // TODO replace these very unscientific guesses with correct formulas + lighting.set_ambient(GL::Color(pow(0.2f*(sun_dir.z+1.0f), 2.0f))); + sun.set_diffuse(GL::Color(0.7f*max(sun_dir.z, 0.0f))); +} + void Layout3D::object_added(Object &o) { if(Track *t = dynamic_cast(&o))