* Use "const string&" rather than "string" in function calls when appropriate.
* Use "const Point3D&" instead of "Pint3D" in function calls when appropriate.
* Improved course calculation in calc_gc_course_dist()
* Safer thread handling code.
Vassilii Khachaturov:
Dont use "const Point3D&" for return types unless you're absolutely sure.
Erik Hofman:
* Use SGD_(2)PI(_[24]) as defined in simgear/constants.h rather than
calculating it by hand every time.
double clat_rad = clat * SGD_DEGREES_TO_RADIANS;
double cos_lat = cos( clat_rad );
double local_radius = cos_lat * SG_EQUATORIAL_RADIUS_M;
- double local_perimeter = 2.0 * local_radius * SGD_PI;
+ double local_perimeter = local_radius * SGD_2PI;
double degree_width = local_perimeter / 360.0;
return sg_bucket_span( get_center_lat() ) * degree_width;
// return height of the tile in meters
double SGBucket::get_height_m() const {
- double perimeter = 2.0 * SG_EQUATORIAL_RADIUS_M * SGD_PI;
+ double perimeter = SG_EQUATORIAL_RADIUS_M * SGD_2PI;
double degree_height = perimeter / 360.0;
return SG_BUCKET_SPAN * degree_height;
inline const char *getFrictionString() const { return _friction_string; }
inline const char *getComment() const { return _comment; }
inline const bool getWindShear() const { return _wind_shear; }
- inline SGMetarVisibility getMinVisibility() const { return _min_visibility; }
- inline SGMetarVisibility getMaxVisibility() const { return _max_visibility; }
+ inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
+ inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
protected:
SGMetarVisibility _min_visibility;
inline int getWindRangeFrom() const { return _wind_range_from; }
inline int getWindRangeTo() const { return _wind_range_to; }
- inline SGMetarVisibility& getMinVisibility() { return _min_visibility; }
- inline SGMetarVisibility& getMaxVisibility() { return _max_visibility; }
- inline SGMetarVisibility& getVertVisibility() { return _vert_visibility; }
- inline SGMetarVisibility *getDirVisibility() { return _dir_visibility; }
+ inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
+ inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
+ inline const SGMetarVisibility& getVertVisibility() const { return _vert_visibility; }
+ inline const SGMetarVisibility *getDirVisibility() const { return _dir_visibility; }
inline double getTemperature_C() const { return _temp; }
inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
double getRelHumidity() const;
- inline vector<SGMetarCloud>& getClouds() { return _clouds; }
- inline map<string, SGMetarRunway>& getRunways() { return _runways; }
- inline vector<string>& getWeather() { return _weather; }
+ inline const vector<SGMetarCloud>& getClouds() const { return _clouds; }
+ inline const map<string, SGMetarRunway>& getRunways() const { return _runways; }
+ inline const vector<string>& getWeather() const { return _weather; }
protected:
string _url;
// SG_LOG( SG_GENERAL, SG_INFO, "rho = " << rho );
if (geoRa < 0)
- geoRa += (2*SGD_PI);
+ geoRa += SGD_2PI;
HA = lst - (3.8197186 * geoRa);
/* SG_LOG( SG_GENERAL, SG_INFO, "t->getLst() = " << t->getLst()
*/
+#include <simgear/constants.h>
#include "fastmath.hxx"
-#define SGD_PI_2 1.57079632679489661923
/**
* This function is on avarage 9 times faster than the system exp() function
// CONSTRUCTORS
-inline Point3D::Point3D() {}
+inline Point3D::Point3D()
+{
+ n[PX] = n[PY] = 0.0;
+ n[PZ] = -9999.0;
+}
inline Point3D::Point3D(const double x, const double y, const double z)
{
#include "polar3d.hxx"
-// Find the Altitude above the Ellipsoid (WGS84) given the Earth
-// Centered Cartesian coordinate vector Distances are specified in
-// meters.
-double fgGeodAltFromCart(const Point3D& cp)
+/**
+ * Find the Altitude above the Ellipsoid (WGS84) given the Earth
+ * Centered Cartesian coordinate vector Distances are specified in
+ * meters.
+ * @param cp point specified in cartesian coordinates
+ * @return altitude above the (wgs84) earth in meters
+ */
+double sgGeodAltFromCart(const Point3D& cp)
{
double t_lat, x_alpha, mu_alpha;
double lat_geoc, radius;
return(result);
}
+/**
+ * Convert a polar coordinate to a cartesian coordinate. Lon and Lat
+ * must be specified in radians. The SG convention is for distances
+ * to be specified in meters
+ * @param p point specified in polar coordinates
+ * @return the same point in cartesian coordinates
+ */
+Point3D sgPolarToCart3d(const Point3D& p) {
+ double tmp = cos( p.lat() ) * p.radius();
+ return Point3D( cos( p.lon() ) * tmp,
+ sin( p.lon() ) * tmp,
+ sin( p.lat() ) * p.radius() );
+}
+
+/**
+ * Convert a cartesian coordinate to polar coordinates (lon/lat
+ * specified in radians. Distances are specified in meters.
+ * @param cp point specified in cartesian coordinates
+ * @return the same point in polar coordinates
+ */
+Point3D sgCartToPolar3d(const Point3D& cp) {
+ return Point3D( atan2( cp.y(), cp.x() ),
+ SGD_PI_2 -
+ atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
+ sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
+}
+
+/**
+ * Calculate new lon/lat given starting lon/lat, and offset radial, and
+ * distance. NOTE: starting point is specifed in radians, distance is
+ * specified in meters (and converted internally to radians)
+ * ... assumes a spherical world.
+ * @param orig specified in polar coordinates
+ * @param course offset radial
+ * @param dist offset distance
+ * @return destination point in polar coordinates
+ */
+Point3D calc_gc_lon_lat( const Point3D& orig, double course,
+ double dist ) {
+ Point3D result;
+
+ // lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
+ // IF (cos(lat)=0)
+ // lon=lon1 // endpoint a pole
+ // ELSE
+ // lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
+ // ENDIF
+
+ // printf("calc_lon_lat() offset.theta = %.2f offset.dist = %.2f\n",
+ // offset.theta, offset.dist);
+
+ dist *= SG_METER_TO_NM * SG_NM_TO_RAD;
+
+ result.sety( asin( sin(orig.y()) * cos(dist) +
+ cos(orig.y()) * sin(dist) * cos(course) ) );
+
+ if ( cos(result.y()) < SG_EPSILON ) {
+ result.setx( orig.x() ); // endpoint a pole
+ } else {
+ result.setx(
+ fmod(orig.x() - asin( sin(course) * sin(dist) /
+ cos(result.y()) )
+ + SGD_PI, SGD_2PI) - SGD_PI );
+ }
+
+ return result;
+}
+
+/**
+ * Calculate course/dist given two spherical points.
+ * @param start starting point
+ * @param dest ending point
+ * @param course resulting course
+ * @param dist resulting distance
+ */
+void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
+ double *course, double *dist )
+{
+ if ( start == dest) {
+ *dist=0;
+ *course=0;
+ return;
+ }
+ // d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
+ // cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
+ double cos_start_y = cos( start.y() );
+ double tmp1 = sin( (start.y() - dest.y()) * 0.5 );
+ double tmp2 = sin( (start.x() - dest.x()) * 0.5 );
+ double d = 2.0 * asin( sqrt( tmp1 * tmp1 +
+ cos_start_y * cos(dest.y()) * tmp2 * tmp2));
+
+ *dist = d * SG_RAD_TO_NM * SG_NM_TO_METER;
+
+#if 1
+ double c1 = atan2(
+ cos(dest.y())*sin(dest.x()-start.x()),
+ cos(start.y())*sin(dest.y())-
+ sin(start.y())*cos(dest.y())*cos(dest.x()-start.x()));
+ if (c1 >= 0)
+ *course = SGD_2PI-c1;
+ else
+ *course = -c1;
+#else
+ // We obtain the initial course, tc1, (at point 1) from point 1 to
+ // point 2 by the following. The formula fails if the initial
+ // point is a pole. We can special case this with:
+ //
+ // IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
+ // IF (lat1 > 0)
+ // tc1= pi // starting from N pole
+ // ELSE
+ // tc1= 0 // starting from S pole
+ // ENDIF
+ // ENDIF
+ //
+ // For starting points other than the poles:
+ //
+ // IF sin(lon2-lon1)<0
+ // tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
+ // ELSE
+ // tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
+ // ENDIF
+
+ // if ( cos(start.y()) < SG_EPSILON ) {
+ // doing it this way saves a transcendental call
+ double sin_start_y = sin( start.y() );
+ if ( fabs(1.0-sin_start_y) < SG_EPSILON ) {
+ // EPS a small number ~ machine precision
+ if ( start.y() > 0 ) {
+ *course = SGD_PI; // starting from N pole
+ } else {
+ *course = 0; // starting from S pole
+ }
+ } else {
+ // For starting points other than the poles:
+ // double tmp3 = sin(d)*cos_start_y);
+ // double tmp4 = sin(dest.y())-sin(start.y())*cos(d);
+ // double tmp5 = acos(tmp4/tmp3);
+
+ // Doing this way gaurentees that the temps are
+ // not stored into memory
+ double tmp5 = acos( (sin(dest.y()) - sin_start_y * cos(d)) /
+ (sin(d) * cos_start_y) );
+
+ // if ( sin( dest.x() - start.x() ) < 0 ) {
+ // the sin of the negative angle is just the opposite sign
+ // of the sin of the angle so tmp2 will have the opposite
+ // sign of sin( dest.x() - start.x() )
+ if ( tmp2 >= 0 ) {
+ *course = tmp5;
+ } else {
+ *course = SGD_2PI - tmp5;
+ }
+ }
+#endif
+}
+
+
+#if 0
+/**
+ * Calculate course/dist given two spherical points.
+ * @param start starting point
+ * @param dest ending point
+ * @param course resulting course
+ * @param dist resulting distance
+ */
+void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
+ double *course, double *dist ) {
+ // d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
+ // cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
+ double tmp1 = sin( (start.y() - dest.y()) / 2 );
+ double tmp2 = sin( (start.x() - dest.x()) / 2 );
+ double d = 2.0 * asin( sqrt( tmp1 * tmp1 +
+ cos(start.y()) * cos(dest.y()) * tmp2 * tmp2));
+ // We obtain the initial course, tc1, (at point 1) from point 1 to
+ // point 2 by the following. The formula fails if the initial
+ // point is a pole. We can special case this with:
+ //
+ // IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
+ // IF (lat1 > 0)
+ // tc1= pi // starting from N pole
+ // ELSE
+ // tc1= 0 // starting from S pole
+ // ENDIF
+ // ENDIF
+ //
+ // For starting points other than the poles:
+ //
+ // IF sin(lon2-lon1)<0
+ // tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
+ // ELSE
+ // tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
+ // ENDIF
+
+ double tc1;
+
+ if ( cos(start.y()) < SG_EPSILON ) {
+ // EPS a small number ~ machine precision
+ if ( start.y() > 0 ) {
+ tc1 = SGD_PI; // starting from N pole
+ } else {
+ tc1 = 0; // starting from S pole
+ }
+ }
+
+ // For starting points other than the poles:
+
+ double tmp3 = sin(d)*cos(start.y());
+ double tmp4 = sin(dest.y())-sin(start.y())*cos(d);
+ double tmp5 = acos(tmp4/tmp3);
+ if ( sin( dest.x() - start.x() ) < 0 ) {
+ tc1 = tmp5;
+ } else {
+ tc1 = SGD_2PI - tmp5;
+ }
+
+ *course = tc1;
+ *dist = d * SG_RAD_TO_NM * SG_NM_TO_METER;
+}
+#endif // 0
* @param p point specified in polar coordinates
* @return the same point in cartesian coordinates
*/
-inline Point3D sgPolarToCart3d(const Point3D& p) {
- double tmp = cos( p.lat() ) * p.radius();
-
- return Point3D( cos( p.lon() ) * tmp,
- sin( p.lon() ) * tmp,
- sin( p.lat() ) * p.radius() );
-}
+Point3D sgPolarToCart3d(const Point3D& p);
/**
* @param cp point specified in cartesian coordinates
* @return the same point in polar coordinates
*/
-inline Point3D sgCartToPolar3d(const Point3D& cp) {
- return Point3D( atan2( cp.y(), cp.x() ),
- SGD_PI_2 -
- atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
- sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
-}
+Point3D sgCartToPolar3d(const Point3D& cp);
/**
* @param dist offset distance
* @return destination point in polar coordinates
*/
-inline Point3D calc_gc_lon_lat( const Point3D& orig, double course,
- double dist ) {
- Point3D result;
-
- // lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
- // IF (cos(lat)=0)
- // lon=lon1 // endpoint a pole
- // ELSE
- // lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
- // ENDIF
-
- // printf("calc_lon_lat() offset.theta = %.2f offset.dist = %.2f\n",
- // offset.theta, offset.dist);
-
- dist *= SG_METER_TO_NM * SG_NM_TO_RAD;
-
- result.sety( asin( sin(orig.y()) * cos(dist) +
- cos(orig.y()) * sin(dist) * cos(course) ) );
-
- if ( cos(result.y()) < SG_EPSILON ) {
- result.setx( orig.x() ); // endpoint a pole
- } else {
- result.setx(
- fmod(orig.x() - asin( sin(course) * sin(dist) /
- cos(result.y()) )
- + SGD_PI, SGD_2PI) - SGD_PI );
- }
-
- return result;
-}
+Point3D calc_gc_lon_lat( const Point3D& orig, double course, double dist );
/**
* @param course resulting course
* @param dist resulting distance
*/
-inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
- double *course, double *dist )
-{
- // d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
- // cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
- double cos_start_y = cos( start.y() );
- volatile double tmp1 = sin( (start.y() - dest.y()) * 0.5 );
- volatile double tmp2 = sin( (start.x() - dest.x()) * 0.5 );
- double d = 2.0 * asin( sqrt( tmp1 * tmp1 +
- cos_start_y * cos(dest.y()) * tmp2 * tmp2));
-
- *dist = d * SG_RAD_TO_NM * SG_NM_TO_METER;
-
- // We obtain the initial course, tc1, (at point 1) from point 1 to
- // point 2 by the following. The formula fails if the initial
- // point is a pole. We can special case this with:
- //
- // IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
- // IF (lat1 > 0)
- // tc1= pi // starting from N pole
- // ELSE
- // tc1= 0 // starting from S pole
- // ENDIF
- // ENDIF
- //
- // For starting points other than the poles:
- //
- // IF sin(lon2-lon1)<0
- // tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
- // ELSE
- // tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
- // ENDIF
-
- // if ( cos(start.y()) < SG_EPSILON ) {
- // doing it this way saves a transcendental call
- double sin_start_y = sin( start.y() );
- if ( fabs(1.0-sin_start_y) < SG_EPSILON ) {
- // EPS a small number ~ machine precision
- if ( start.y() > 0 ) {
- *course = SGD_PI; // starting from N pole
- } else {
- *course = 0; // starting from S pole
- }
- } else {
- // For starting points other than the poles:
- // double tmp3 = sin(d)*cos_start_y);
- // double tmp4 = sin(dest.y())-sin(start.y())*cos(d);
- // double tmp5 = acos(tmp4/tmp3);
-
- // Doing this way gaurentees that the temps are
- // not stored into memory
- double tmp5 = acos( (sin(dest.y()) - sin_start_y * cos(d)) /
- (sin(d) * cos_start_y) );
-
- // if ( sin( dest.x() - start.x() ) < 0 ) {
- // the sin of the negative angle is just the opposite sign
- // of the sin of the angle so tmp2 will have the opposite
- // sign of sin( dest.x() - start.x() )
- if ( tmp2 >= 0 ) {
- *course = tmp5;
- } else {
- *course = 2 * SGD_PI - tmp5;
- }
- }
-}
+void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
+ double *course, double *dist );
#if 0
/**
* @param course resulting course
* @param dist resulting distance
*/
-inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
- double *course, double *dist ) {
- // d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
- // cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
- double tmp1 = sin( (start.y() - dest.y()) / 2 );
- double tmp2 = sin( (start.x() - dest.x()) / 2 );
- double d = 2.0 * asin( sqrt( tmp1 * tmp1 +
- cos(start.y()) * cos(dest.y()) * tmp2 * tmp2));
-
- // We obtain the initial course, tc1, (at point 1) from point 1 to
- // point 2 by the following. The formula fails if the initial
- // point is a pole. We can special case this with:
- //
- // IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
- // IF (lat1 > 0)
- // tc1= pi // starting from N pole
- // ELSE
- // tc1= 0 // starting from S pole
- // ENDIF
- // ENDIF
- //
- // For starting points other than the poles:
- //
- // IF sin(lon2-lon1)<0
- // tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
- // ELSE
- // tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
- // ENDIF
-
- double tc1;
-
- if ( cos(start.y()) < SG_EPSILON ) {
- // EPS a small number ~ machine precision
- if ( start.y() > 0 ) {
- tc1 = SGD_PI; // starting from N pole
- } else {
- tc1 = 0; // starting from S pole
- }
- }
-
- // For starting points other than the poles:
-
- double tmp3 = sin(d)*cos(start.y());
- double tmp4 = sin(dest.y())-sin(start.y())*cos(d);
- double tmp5 = acos(tmp4/tmp3);
- if ( sin( dest.x() - start.x() ) < 0 ) {
- tc1 = tmp5;
- } else {
- tc1 = 2 * SGD_PI - tmp5;
- }
-
- *course = tc1;
- *dist = d * SG_RAD_TO_NM * SG_NM_TO_METER;
-}
+void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
+ double *course, double *dist );
#endif // 0
#endif // _POLAR3D_HXX
+
double clat_rad = clat * SGD_DEGREES_TO_RADIANS;
double cos_lat = cos( clat_rad );
double local_radius = cos_lat * SG_EQUATORIAL_RADIUS_M;
- double local_perimeter = 2.0 * local_radius * SGD_PI;
+ double local_perimeter = local_radius * SGD_2PI;
double degree_width = local_perimeter / 360.0;
// cout << "clat = " << clat << endl;
// cout << "local_perimeter = " << local_perimeter << endl;
// cout << "degree_width = " << degree_width << endl;
- double perimeter = 2.0 * SG_EQUATORIAL_RADIUS_M * SGD_PI;
+ double perimeter = SG_EQUATORIAL_RADIUS_M * SGD_2PI;
double degree_height = perimeter / 360.0;
// cout << "degree_height = " << degree_height << endl;
inline void set_distance( double d ) { distance = d; }
/** @return waypoint id */
- inline string get_id() const { return id; }
+ inline const string& get_id() const { return id; }
/** @return waypoint name */
- inline string get_name() const { return name; }
+ inline const string& get_name() const { return name; }
};
// modify actual_visibility based on puff envelope
if ( puff_progression <= ramp_up ) {
- double x = 0.5 * SGD_PI * puff_progression / ramp_up;
+ double x = SGD_PI_2 * puff_progression / ramp_up;
double factor = 1.0 - sin( x );
// cout << "ramp up = " << puff_progression
// << " factor = " << factor << endl;
effvis = effvis * factor;
} else if ( puff_progression >= ramp_up + puff_length ) {
- double x = 0.5 * SGD_PI *
+ double x = SGD_PI_2 *
(puff_progression - (ramp_up + puff_length)) /
ramp_down;
double factor = sin( x );
#include <simgear/compiler.h>
+#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include STL_IOSTREAM
sgVec3 vec3;
drho = SGD_PI / (float) stacks;
- dtheta = 2.0 * SGD_PI / (float) slices;
+ dtheta = SGD_2PI / (float) slices;
/* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y
axis t goes from -1.0/+1.0 at z = -radius/+radius (linear along
#include <simgear/compiler.h>
+#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <stdio.h>
int phase;
// determine which star structure to draw
- if ( sun_angle > (0.5 * SGD_PI + 10.0 * SGD_DEGREES_TO_RADIANS ) ) {
+ if ( sun_angle > (SGD_PI_2 + 10.0 * SGD_DEGREES_TO_RADIANS ) ) {
// deep night
factor = 1.0;
cutoff = 4.5;
phase = 0;
- } else if ( sun_angle > (0.5 * SGD_PI + 8.8 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 8.8 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 1.0;
cutoff = 3.8;
phase = 1;
- } else if ( sun_angle > (0.5 * SGD_PI + 7.5 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 7.5 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 0.95;
cutoff = 3.1;
phase = 2;
- } else if ( sun_angle > (0.5 * SGD_PI + 7.0 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 7.0 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 0.9;
cutoff = 2.4;
phase = 3;
- } else if ( sun_angle > (0.5 * SGD_PI + 6.5 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 6.5 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 0.85;
cutoff = 1.8;
phase = 4;
- } else if ( sun_angle > (0.5 * SGD_PI + 6.0 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 6.0 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 0.8;
cutoff = 1.2;
phase = 5;
- } else if ( sun_angle > (0.5 * SGD_PI + 5.5 * SGD_DEGREES_TO_RADIANS ) ) {
+ } else if ( sun_angle > (SGD_PI_2 + 5.5 * SGD_DEGREES_TO_RADIANS ) ) {
factor = 0.75;
cutoff = 0.6;
phase = 6;
inline int
SGThread::start( unsigned cpu )
{
- int status = pthread_create( &tid, 0, start_handler, this );
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ int status = pthread_create( &tid, &attr, start_handler, this );
assert( status == 0 );
+ pthread_attr_destroy(&attr);
#if defined( sgi )
if ( !status && !cpu )
pthread_setrunon_np( cpu );
inline SGMutex::SGMutex()
{
- int status = pthread_mutex_init( &mutex, 0 );
+ pthread_mutexattr_t mutex_attr;
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);
+ int status = pthread_mutex_init( &mutex, &mutex_attr );
assert( status == 0 );
+ pthread_mutexattr_destroy(&mutex_attr);
}
inline SGMutex::~SGMutex()
// not within -180 ... 180
lon_rad = 0.0;
}
- if ( lat_rad < -SGD_PI * 0.5 || lat_rad > SGD_PI * 0.5 ) {
+ if ( lat_rad < -SGD_PI_2 || lat_rad > SGD_PI_2 ) {
// not within -90 ... 90
lat_rad = 0.0;
}