From 7d3abdc5124c4a0dc0ea201476ee3d7e964aff4d Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 31 Jul 2003 14:46:24 +0000 Subject: [PATCH] Add cloud movement direction and speed --- simgear/scene/sky/cloud.cxx | 32 ++++++++++++++++++++++++++------ simgear/scene/sky/cloud.hxx | 26 +++++++++++++++++++++++++- simgear/scene/sky/sky.cxx | 4 ++-- simgear/scene/sky/sky.hxx | 2 +- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index 7f52663f..eaf813c6 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -285,7 +285,7 @@ bool SGCloudLayer::repaint( sgVec3 fog_color ) { // spin specifies a rotation about the new Z axis (and orients the // sunrise/set effects bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, - double alt ) + double alt, double dt ) { sgMat4 T1, LON, LAT; sgVec3 axis; @@ -343,15 +343,35 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, last_lat = lat; } - if ( lon != last_lon || lat != last_lat ) { + double sp_dist = speed*dt; + + if ( lon != last_lon || lat != last_lat || sp_dist != 0 ) { Point3D start( last_lon, last_lat, 0.0 ); Point3D dest( lon, lat, 0.0 ); - double course, dist; - calc_gc_course_dist( dest, start, &course, &dist ); + double course = 0.0, dist = 0.0; + + if (dest != start) { + calc_gc_course_dist( dest, start, &course, &dist ); + } // cout << "course = " << course << ", dist = " << dist << endl; - double xoff = cos( course ) * dist / (2 * scale); - double yoff = sin( course ) * dist / (2 * scale); + + // calculate cloud movement due to external forces + double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0; + + if (dist > 0.0) { + ax = cos(course) * dist; + ay = sin(course) * dist; + } + + if (sp_dist > 0) { + bx = cos(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist; + by = sin(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist; + } + + + double xoff = (ax + bx) / (2 * scale); + double yoff = (ay + by) / (2 * scale); const float layer_scale = layer_span / scale; diff --git a/simgear/scene/sky/cloud.hxx b/simgear/scene/sky/cloud.hxx index 3853aeb3..90c33f62 100644 --- a/simgear/scene/sky/cloud.hxx +++ b/simgear/scene/sky/cloud.hxx @@ -98,6 +98,7 @@ public: * visibility. */ float getTransition_m () const; + /** * set the transition layer size in meters * @param transition_m the transition layer size in meters @@ -106,12 +107,31 @@ public: /** get coverage type */ Coverage getCoverage () const; + /** * set coverage type * @param coverage the coverage type */ void setCoverage (Coverage coverage); + /** + * set the cloud movement direction + * @param dir the cloud movement direction + */ + inline void setDirection(float dir) { direction = dir; } + + /** get the cloud movement direction */ + inline float getDirection() { return direction; } + + /** + * set the cloud movement speed + * @param sp the cloud movement speed + */ + inline void setSpeed(float sp) { speed = sp; } + + /** get the cloud movement speed */ + inline float getSpeed() { return speed; } + /** build the cloud object */ void rebuild(); @@ -130,8 +150,10 @@ public: * @param lat specifies a rotation about the new Y axis * @param spin specifies a rotation about the new Z axis * (and orients the sunrise/set effects) + * @param dt the time elapsed since the last call */ - bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt ); + bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt, + double dt = 0.0 ); /** draw the cloud layer */ void draw(); @@ -154,6 +176,8 @@ private: float layer_transition; Coverage layer_coverage; float scale; + float speed; + float direction; // for handling texture coordinates to simulate cloud movement // from winds, and to simulate the clouds being tied to ground diff --git a/simgear/scene/sky/sky.cxx b/simgear/scene/sky/sky.cxx index f3c01448..833b3df8 100644 --- a/simgear/scene/sky/sky.cxx +++ b/simgear/scene/sky/sky.cxx @@ -139,7 +139,7 @@ bool SGSky::repaint( const SGSkyColor &sc ) // spin specifies a rotation about the new Z axis (this allows // additional orientation for the sunrise/set effects and is used by // the skydome and perhaps clouds. -bool SGSky::reposition( SGSkyState &st ) +bool SGSky::reposition( SGSkyState &st, double dt ) { double angle = st.gst * 15; // degrees @@ -159,7 +159,7 @@ bool SGSky::reposition( SGSkyState &st ) for ( int i = 0; i < (int)cloud_layers.size(); ++i ) { if ( cloud_layers[i]->getCoverage() != SGCloudLayer::SG_CLOUD_CLEAR ) { cloud_layers[i]->reposition( st.zero_elev, st.view_up, - st.lon, st.lat, st.alt ); + st.lon, st.lat, st.alt, dt ); } } diff --git a/simgear/scene/sky/sky.hxx b/simgear/scene/sky/sky.hxx index 9c8899d9..2c3434b6 100644 --- a/simgear/scene/sky/sky.hxx +++ b/simgear/scene/sky/sky.hxx @@ -308,7 +308,7 @@ public: * @param moon_dec the moon's current declination * @param moon_dist the moon's distance from the current view point. */ - bool reposition( SGSkyState &st ); + bool reposition( SGSkyState &st, double dt = 0.0 ); /** * Modify the given visibility based on cloud layers, thickness, -- 2.39.5