Add cloud movement direction and speed

This commit is contained in:
ehofman
2003-07-31 14:46:24 +00:00
parent db4c2243e3
commit 7d3abdc512
4 changed files with 54 additions and 10 deletions
+26 -6
View File
@@ -285,7 +285,7 @@ bool SGCloudLayer::repaint( sgVec3 fog_color ) {
// spin specifies a rotation about the new Z axis (and orients the // spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects // sunrise/set effects
bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
double alt ) double alt, double dt )
{ {
sgMat4 T1, LON, LAT; sgMat4 T1, LON, LAT;
sgVec3 axis; sgVec3 axis;
@@ -343,15 +343,35 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
last_lat = 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 start( last_lon, last_lat, 0.0 );
Point3D dest( lon, lat, 0.0 ); Point3D dest( lon, lat, 0.0 );
double course, dist; double course = 0.0, dist = 0.0;
calc_gc_course_dist( dest, start, &course, &dist );
if (dest != start) {
calc_gc_course_dist( dest, start, &course, &dist );
}
// cout << "course = " << course << ", dist = " << dist << endl; // 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; const float layer_scale = layer_span / scale;
+25 -1
View File
@@ -98,6 +98,7 @@ public:
* visibility. * visibility.
*/ */
float getTransition_m () const; float getTransition_m () const;
/** /**
* set the transition layer size in meters * set the transition layer size in meters
* @param transition_m the transition layer size in meters * @param transition_m the transition layer size in meters
@@ -106,12 +107,31 @@ public:
/** get coverage type */ /** get coverage type */
Coverage getCoverage () const; Coverage getCoverage () const;
/** /**
* set coverage type * set coverage type
* @param coverage the coverage type * @param coverage the coverage type
*/ */
void setCoverage (Coverage coverage); 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 */ /** build the cloud object */
void rebuild(); void rebuild();
@@ -130,8 +150,10 @@ public:
* @param lat specifies a rotation about the new Y axis * @param lat specifies a rotation about the new Y axis
* @param spin specifies a rotation about the new Z axis * @param spin specifies a rotation about the new Z axis
* (and orients the sunrise/set effects) * (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 */ /** draw the cloud layer */
void draw(); void draw();
@@ -154,6 +176,8 @@ private:
float layer_transition; float layer_transition;
Coverage layer_coverage; Coverage layer_coverage;
float scale; float scale;
float speed;
float direction;
// for handling texture coordinates to simulate cloud movement // for handling texture coordinates to simulate cloud movement
// from winds, and to simulate the clouds being tied to ground // from winds, and to simulate the clouds being tied to ground
+2 -2
View File
@@ -139,7 +139,7 @@ bool SGSky::repaint( const SGSkyColor &sc )
// spin specifies a rotation about the new Z axis (this allows // spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used by // additional orientation for the sunrise/set effects and is used by
// the skydome and perhaps clouds. // the skydome and perhaps clouds.
bool SGSky::reposition( SGSkyState &st ) bool SGSky::reposition( SGSkyState &st, double dt )
{ {
double angle = st.gst * 15; // degrees 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 ) { for ( int i = 0; i < (int)cloud_layers.size(); ++i ) {
if ( cloud_layers[i]->getCoverage() != SGCloudLayer::SG_CLOUD_CLEAR ) { if ( cloud_layers[i]->getCoverage() != SGCloudLayer::SG_CLOUD_CLEAR ) {
cloud_layers[i]->reposition( st.zero_elev, st.view_up, cloud_layers[i]->reposition( st.zero_elev, st.view_up,
st.lon, st.lat, st.alt ); st.lon, st.lat, st.alt, dt );
} }
} }
+1 -1
View File
@@ -308,7 +308,7 @@ public:
* @param moon_dec the moon's current declination * @param moon_dec the moon's current declination
* @param moon_dist the moon's distance from the current view point. * @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, * Modify the given visibility based on cloud layers, thickness,