SGCMath.hxx | SGCMath.hxx | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
#ifndef SGCMath_H | #ifndef SGCMath_H | |||
#define SGCMath_H | #define SGCMath_H | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#ifdef SG_HAVE_STD_INCLUDES | ||||
// We have cmath from the standard c++ lib available | ||||
#include <cmath> | #include <cmath> | |||
#else | ||||
// We only have math.h with the c89 double functions. | ||||
#include <math.h> | ||||
#endif | ||||
#endif | #endif | |||
End of changes. 2 change blocks. | ||||
6 lines changed or deleted | 0 lines changed or added | |||
SGGeoc.hxx | SGGeoc.hxx | |||
---|---|---|---|---|
skipping to change at line 77 | skipping to change at line 77 | |||
/// Return the geocentric radius in meters | /// Return the geocentric radius in meters | |||
double getRadiusM(void) const; | double getRadiusM(void) const; | |||
/// Set the geocentric radius from the argument given in meters | /// Set the geocentric radius from the argument given in meters | |||
void setRadiusM(double radius); | void setRadiusM(double radius); | |||
/// Return the geocentric radius in feet | /// Return the geocentric radius in feet | |||
double getRadiusFt(void) const; | double getRadiusFt(void) const; | |||
/// Set the geocentric radius from the argument given in feet | /// Set the geocentric radius from the argument given in feet | |||
void setRadiusFt(double radius); | void setRadiusFt(double radius); | |||
SGGeoc advanceRadM(double course, double distance) const; | ||||
static double courseRad(const SGGeoc& from, const SGGeoc& to); | ||||
static double courseDeg(const SGGeoc& from, const SGGeoc& to); | ||||
static double distanceM(const SGGeoc& from, const SGGeoc& to); | ||||
// Compare two geocentric positions for equality | ||||
bool operator == ( const SGGeoc & other ) const; | ||||
private: | private: | |||
/// This one is private since construction is not unique if you do | /// This one is private since construction is not unique if you do | |||
/// not know the units of the arguments, use the factory methods for | /// not know the units of the arguments, use the factory methods for | |||
/// that purpose | /// that purpose | |||
SGGeoc(double lon, double lat, double radius); | SGGeoc(double lon, double lat, double radius); | |||
/// The actual data, angles in degree, radius in meters | /// The actual data, angles in degree, radius in meters | |||
/// The rationale for storing the values in degrees is that most code pla ces | /// The rationale for storing the values in degrees is that most code pla ces | |||
/// in flightgear/terragear use degrees as a nativ input and output value . | /// in flightgear/terragear use degrees as a nativ input and output value . | |||
/// The places where it makes sense to use radians is when we convert | /// The places where it makes sense to use radians is when we convert | |||
skipping to change at line 204 | skipping to change at line 211 | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
double | double | |||
SGGeoc::getLongitudeDeg(void) const | SGGeoc::getLongitudeDeg(void) const | |||
{ | { | |||
#ifdef SG_GEOC_NATIVE_DEGREE | #ifdef SG_GEOC_NATIVE_DEGREE | |||
return _lon; | return _lon; | |||
#else | #else | |||
return _lon*SGD_DEGREES_TO_RADIANS; | return _lon*SGD_RADIANS_TO_DEGREES; | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
void | void | |||
SGGeoc::setLongitudeDeg(double lon) | SGGeoc::setLongitudeDeg(double lon) | |||
{ | { | |||
#ifdef SG_GEOC_NATIVE_DEGREE | #ifdef SG_GEOC_NATIVE_DEGREE | |||
_lon = lon; | _lon = lon; | |||
#else | #else | |||
_lon = lon*SGD_RADIANS_TO_DEGREES; | _lon = lon*SGD_DEGREES_TO_RADIANS; | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
double | double | |||
SGGeoc::getLatitudeRad(void) const | SGGeoc::getLatitudeRad(void) const | |||
{ | { | |||
#ifdef SG_GEOC_NATIVE_DEGREE | #ifdef SG_GEOC_NATIVE_DEGREE | |||
return _lat*SGD_DEGREES_TO_RADIANS; | return _lat*SGD_DEGREES_TO_RADIANS; | |||
#else | #else | |||
skipping to change at line 248 | skipping to change at line 255 | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
double | double | |||
SGGeoc::getLatitudeDeg(void) const | SGGeoc::getLatitudeDeg(void) const | |||
{ | { | |||
#ifdef SG_GEOC_NATIVE_DEGREE | #ifdef SG_GEOC_NATIVE_DEGREE | |||
return _lat; | return _lat; | |||
#else | #else | |||
return _lat*SGD_DEGREES_TO_RADIANS; | return _lat*SGD_RADIANS_TO_DEGREES; | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
void | void | |||
SGGeoc::setLatitudeDeg(double lat) | SGGeoc::setLatitudeDeg(double lat) | |||
{ | { | |||
#ifdef SG_GEOC_NATIVE_DEGREE | #ifdef SG_GEOC_NATIVE_DEGREE | |||
_lat = lat; | _lat = lat; | |||
#else | #else | |||
_lat = lat*SGD_RADIANS_TO_DEGREES; | _lat = lat*SGD_DEGREES_TO_RADIANS; | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
double | double | |||
SGGeoc::getRadiusM(void) const | SGGeoc::getRadiusM(void) const | |||
{ | { | |||
return _radius; | return _radius; | |||
} | } | |||
skipping to change at line 291 | skipping to change at line 298 | |||
return _radius*SG_METER_TO_FEET; | return _radius*SG_METER_TO_FEET; | |||
} | } | |||
inline | inline | |||
void | void | |||
SGGeoc::setRadiusFt(double radius) | SGGeoc::setRadiusFt(double radius) | |||
{ | { | |||
_radius = radius*SG_FEET_TO_METER; | _radius = radius*SG_FEET_TO_METER; | |||
} | } | |||
inline | ||||
SGGeoc | ||||
SGGeoc::advanceRadM(double course, double distance) const | ||||
{ | ||||
SGGeoc result; | ||||
SGGeodesy::advanceRadM(*this, course, distance, result); | ||||
return result; | ||||
} | ||||
inline | ||||
double | ||||
SGGeoc::courseRad(const SGGeoc& from, const SGGeoc& to) | ||||
{ | ||||
return SGGeodesy::courseRad(from, to); | ||||
} | ||||
inline | ||||
double | ||||
SGGeoc::courseDeg(const SGGeoc& from, const SGGeoc& to) | ||||
{ | ||||
return SGMiscd::rad2deg(courseRad(from, to)); | ||||
} | ||||
inline | ||||
double | ||||
SGGeoc::distanceM(const SGGeoc& from, const SGGeoc& to) | ||||
{ | ||||
return SGGeodesy::distanceM(from, to); | ||||
} | ||||
inline | ||||
bool | ||||
SGGeoc::operator == ( const SGGeoc & other ) const | ||||
{ | ||||
return _lon == other._lon && | ||||
_lat == other._lat && | ||||
_radius == other._radius; | ||||
} | ||||
/// Output to an ostream | /// Output to an ostream | |||
template<typename char_type, typename traits_type> | template<typename char_type, typename traits_type> | |||
inline | inline | |||
std::basic_ostream<char_type, traits_type>& | std::basic_ostream<char_type, traits_type>& | |||
operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeoc& g) | operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeoc& g) | |||
{ | { | |||
return s << "lon = " << g.getLongitudeDeg() | return s << "lon = " << g.getLongitudeDeg() | |||
<< ", lat = " << g.getLatitudeDeg() | << ", lat = " << g.getLatitudeDeg() | |||
<< ", radius = " << g.getRadiusM(); | << ", radius = " << g.getRadiusM(); | |||
} | } | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 50 lines changed or added | |||
SGGeod.hxx | SGGeod.hxx | |||
---|---|---|---|---|
skipping to change at line 43 | skipping to change at line 43 | |||
/// Factory from angular values in degrees and elevation is 0 | /// Factory from angular values in degrees and elevation is 0 | |||
static SGGeod fromDeg(double lon, double lat); | static SGGeod fromDeg(double lon, double lat); | |||
/// Factory from angular values in radians and elevation in ft | /// Factory from angular values in radians and elevation in ft | |||
static SGGeod fromRadFt(double lon, double lat, double elevation); | static SGGeod fromRadFt(double lon, double lat, double elevation); | |||
/// Factory from angular values in degrees and elevation in ft | /// Factory from angular values in degrees and elevation in ft | |||
static SGGeod fromDegFt(double lon, double lat, double elevation); | static SGGeod fromDegFt(double lon, double lat, double elevation); | |||
/// Factory from angular values in radians and elevation in m | /// Factory from angular values in radians and elevation in m | |||
static SGGeod fromRadM(double lon, double lat, double elevation); | static SGGeod fromRadM(double lon, double lat, double elevation); | |||
/// Factory from angular values in degrees and elevation in m | /// Factory from angular values in degrees and elevation in m | |||
static SGGeod fromDegM(double lon, double lat, double elevation); | static SGGeod fromDegM(double lon, double lat, double elevation); | |||
/// Factory from an other SGGeod and a different elevation in m | ||||
static SGGeod fromGeodM(const SGGeod& geod, double elevation); | ||||
/// Factory from an other SGGeod and a different elevation in ft | ||||
static SGGeod fromGeodFt(const SGGeod& geod, double elevation); | ||||
/// Factory to convert position from a cartesian position assumed to be | /// Factory to convert position from a cartesian position assumed to be | |||
/// in wgs84 measured in meters | /// in wgs84 measured in meters | |||
/// Note that this conversion is relatively expensive to compute | /// Note that this conversion is relatively expensive to compute | |||
static SGGeod fromCart(const SGVec3<double>& cart); | static SGGeod fromCart(const SGVec3<double>& cart); | |||
/// Factory to convert position from a geocentric position | /// Factory to convert position from a geocentric position | |||
/// Note that this conversion is relatively expensive to compute | /// Note that this conversion is relatively expensive to compute | |||
static SGGeod fromGeoc(const SGGeoc& geoc); | static SGGeod fromGeoc(const SGGeoc& geoc); | |||
/// Return the geodetic longitude in radians | /// Return the geodetic longitude in radians | |||
double getLongitudeRad(void) const; | double getLongitudeRad(void) const; | |||
skipping to change at line 81 | skipping to change at line 85 | |||
/// Return the geodetic elevation in meters | /// Return the geodetic elevation in meters | |||
double getElevationM(void) const; | double getElevationM(void) const; | |||
/// Set the geodetic elevation from the argument given in meters | /// Set the geodetic elevation from the argument given in meters | |||
void setElevationM(double elevation); | void setElevationM(double elevation); | |||
/// Return the geodetic elevation in feet | /// Return the geodetic elevation in feet | |||
double getElevationFt(void) const; | double getElevationFt(void) const; | |||
/// Set the geodetic elevation from the argument given in feet | /// Set the geodetic elevation from the argument given in feet | |||
void setElevationFt(double elevation); | void setElevationFt(double elevation); | |||
/// Compare two geodetic positions for equality | ||||
bool operator == ( const SGGeod & other ) const; | ||||
/// check the Geod contains sane values (finite, inside appropriate | ||||
/// ranges for lat/lon) | ||||
bool isValid() const; | ||||
private: | private: | |||
/// This one is private since construction is not unique if you do | /// This one is private since construction is not unique if you do | |||
/// not know the units of the arguments. Use the factory methods for | /// not know the units of the arguments. Use the factory methods for | |||
/// that purpose | /// that purpose | |||
SGGeod(double lon, double lat, double elevation); | SGGeod(double lon, double lat, double elevation); | |||
/// The actual data, angles in degree, elevation in meters | //// FIXME: wrong comment! | |||
/// The actual data, angles in degrees, elevation in meters | ||||
/// The rationale for storing the values in degrees is that most code pla ces | /// The rationale for storing the values in degrees is that most code pla ces | |||
/// in flightgear/terragear use degrees as a nativ input and output value . | /// in flightgear/terragear use degrees as a nativ input and output value . | |||
/// The places where it makes sense to use radians is when we convert | /// The places where it makes sense to use radians is when we convert | |||
/// to other representations or compute rotation matrices. But both tasks | /// to other representations or compute rotation matrices. But both tasks | |||
/// are computionally intensive anyway and that additional 'toRadian' | /// are computionally intensive anyway and that additional 'toRadian' | |||
/// conversion does not hurt too much | /// conversion does not hurt too much | |||
double _lon; | double _lon; | |||
double _lat; | double _lat; | |||
double _elevation; | double _elevation; | |||
}; | }; | |||
skipping to change at line 183 | skipping to change at line 194 | |||
#ifdef SG_GEOD_NATIVE_DEGREE | #ifdef SG_GEOD_NATIVE_DEGREE | |||
return SGGeod(lon, lat, elevation); | return SGGeod(lon, lat, elevation); | |||
#else | #else | |||
return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, | return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, | |||
elevation); | elevation); | |||
#endif | #endif | |||
} | } | |||
inline | inline | |||
SGGeod | SGGeod | |||
SGGeod::fromGeodM(const SGGeod& geod, double elevation) | ||||
{ | ||||
return SGGeod(geod._lon, geod._lat, elevation); | ||||
} | ||||
inline | ||||
SGGeod | ||||
SGGeod::fromGeodFt(const SGGeod& geod, double elevation) | ||||
{ | ||||
return SGGeod(geod._lon, geod._lat, elevation*SG_FEET_TO_METER); | ||||
} | ||||
inline | ||||
SGGeod | ||||
SGGeod::fromCart(const SGVec3<double>& cart) | SGGeod::fromCart(const SGVec3<double>& cart) | |||
{ | { | |||
SGGeod geod; | SGGeod geod; | |||
SGGeodesy::SGCartToGeod(cart, geod); | SGGeodesy::SGCartToGeod(cart, geod); | |||
return geod; | return geod; | |||
} | } | |||
inline | inline | |||
SGGeod | SGGeod | |||
SGGeod::fromGeoc(const SGGeoc& geoc) | SGGeod::fromGeoc(const SGGeoc& geoc) | |||
skipping to change at line 317 | skipping to change at line 342 | |||
return _elevation*SG_METER_TO_FEET; | return _elevation*SG_METER_TO_FEET; | |||
} | } | |||
inline | inline | |||
void | void | |||
SGGeod::setElevationFt(double elevation) | SGGeod::setElevationFt(double elevation) | |||
{ | { | |||
_elevation = elevation*SG_FEET_TO_METER; | _elevation = elevation*SG_FEET_TO_METER; | |||
} | } | |||
inline | ||||
bool | ||||
SGGeod::operator == ( const SGGeod & other ) const | ||||
{ | ||||
return _lon == other._lon && | ||||
_lat == other._lat && | ||||
_elevation == other._elevation; | ||||
} | ||||
inline | ||||
bool | ||||
SGGeod::isValid() const | ||||
{ | ||||
if (SGMiscd::isNaN(_lon)) | ||||
return false; | ||||
if (SGMiscd::isNaN(_lat)) | ||||
return false; | ||||
#ifdef SG_GEOD_NATIVE_DEGREE | ||||
return (_lon >= -180.0) && (_lon <= 180.0) && | ||||
(_lat >= -90.0) && (_lat <= 90.0); | ||||
#else | ||||
return (_lon >= -SGD_PI) && (_lon <= SGD_PI) && | ||||
(_lat >= -SGD_PI_2) && (_lat <= SGD_PI_2); | ||||
#endif | ||||
} | ||||
/// Output to an ostream | /// Output to an ostream | |||
template<typename char_type, typename traits_type> | template<typename char_type, typename traits_type> | |||
inline | inline | |||
std::basic_ostream<char_type, traits_type>& | std::basic_ostream<char_type, traits_type>& | |||
operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeod& g) | operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeod& g) | |||
{ | { | |||
return s << "lon = " << g.getLongitudeDeg() | return s << "lon = " << g.getLongitudeDeg() | |||
<< "deg, lat = " << g.getLatitudeDeg() | << "deg, lat = " << g.getLatitudeDeg() | |||
<< "deg, elev = " << g.getElevationM() | << "deg, elev = " << g.getElevationM() | |||
<< "m"; | << "m"; | |||
End of changes. 5 change blocks. | ||||
1 lines changed or deleted | 52 lines changed or added | |||
SGGeodesy.hxx | SGGeodesy.hxx | |||
---|---|---|---|---|
skipping to change at line 48 | skipping to change at line 48 | |||
/// Takes a geodetic coordinate data and returns the sea level radius. | /// Takes a geodetic coordinate data and returns the sea level radius. | |||
static double SGGeodToSeaLevelRadius(const SGGeod& geod); | static double SGGeodToSeaLevelRadius(const SGGeod& geod); | |||
/// Takes a cartesian coordinate data and returns the geocentric | /// Takes a cartesian coordinate data and returns the geocentric | |||
/// coordinates. | /// coordinates. | |||
static void SGCartToGeoc(const SGVec3<double>& cart, SGGeoc& geoc); | static void SGCartToGeoc(const SGVec3<double>& cart, SGGeoc& geoc); | |||
/// Takes a geocentric coordinate data and returns the cartesian | /// Takes a geocentric coordinate data and returns the cartesian | |||
/// coordinates. | /// coordinates. | |||
static void SGGeocToCart(const SGGeoc& geoc, SGVec3<double>& cart); | static void SGGeocToCart(const SGGeoc& geoc, SGVec3<double>& cart); | |||
// Geodetic course/distance computation | ||||
static bool direct(const SGGeod& p1, double course1, | ||||
double distance, SGGeod& p2, double& course2); | ||||
/// overloaded version of above, returns new value directly, throws | ||||
/// an sg_exception on failure. | ||||
static SGGeod direct(const SGGeod& p1, double course1, | ||||
double distance); | ||||
static bool inverse(const SGGeod& p1, const SGGeod& p2, double& course1, | ||||
double& course2, double& distance); | ||||
static double courseDeg(const SGGeod& from, const SGGeod& to); | ||||
static double distanceM(const SGGeod& from, const SGGeod& to); | ||||
static double distanceNm(const SGGeod& from, const SGGeod& to); | ||||
// Geocentric course/distance computation | ||||
static void advanceRadM(const SGGeoc& geoc, double course, double distanc | ||||
e, | ||||
SGGeoc& result); | ||||
static double courseRad(const SGGeoc& from, const SGGeoc& to); | ||||
static double distanceRad(const SGGeoc& from, const SGGeoc& to); | ||||
static double distanceM(const SGGeoc& from, const SGGeoc& to); | ||||
/** | ||||
* compute the intersection of two (true) radials (in degrees), or return | ||||
false | ||||
* if no intersection culd be computed. | ||||
*/ | ||||
static bool radialIntersection(const SGGeoc& a, double aRadial, | ||||
const SGGeoc& b, double bRadial, SGGeoc& result); | ||||
static bool radialIntersection(const SGGeod& a, double aRadial, | ||||
const SGGeod& b, double bRadial, SGGeod& result); | ||||
}; | }; | |||
#endif | #endif | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 35 lines changed or added | |||
SGMath.hxx | SGMath.hxx | |||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
/// Just include them all | /// Just include them all | |||
#include <iosfwd> | #include <iosfwd> | |||
#include "SGMathFwd.hxx" | #include "SGMathFwd.hxx" | |||
#include "SGCMath.hxx" | #include "SGCMath.hxx" | |||
#include "SGLimits.hxx" | #include "SGLimits.hxx" | |||
#include "SGMisc.hxx" | #include "SGMisc.hxx" | |||
#include "SGGeodesy.hxx" | #include "SGGeodesy.hxx" | |||
#include "SGVec2.hxx" | ||||
#include "SGVec3.hxx" | #include "SGVec3.hxx" | |||
#include "SGVec4.hxx" | #include "SGVec4.hxx" | |||
#include "SGGeoc.hxx" | #include "SGGeoc.hxx" | |||
#include "SGGeod.hxx" | #include "SGGeod.hxx" | |||
#include "SGQuat.hxx" | #include "SGQuat.hxx" | |||
#include "SGLocation.hxx" | ||||
#include "SGMatrix.hxx" | #include "SGMatrix.hxx" | |||
#endif | #endif | |||
End of changes. 2 change blocks. | ||||
0 lines changed or deleted | 2 lines changed or added | |||
SGMathFwd.hxx | SGMathFwd.hxx | |||
---|---|---|---|---|
skipping to change at line 27 | skipping to change at line 27 | |||
#ifndef SGMathFwd_H | #ifndef SGMathFwd_H | |||
#define SGMathFwd_H | #define SGMathFwd_H | |||
// All forward declarations in case they only need to be declared | // All forward declarations in case they only need to be declared | |||
class SGGeoc; | class SGGeoc; | |||
class SGGeod; | class SGGeod; | |||
template<typename T> | template<typename T> | |||
class SGLocation; | ||||
template<typename T> | ||||
class SGLimits; | class SGLimits; | |||
template<typename T> | template<typename T> | |||
class SGMatrix; | class SGMatrix; | |||
template<typename T> | template<typename T> | |||
class SGMisc; | class SGMisc; | |||
template<typename T> | template<typename T> | |||
class SGQuat; | class SGQuat; | |||
template<typename T> | template<typename T> | |||
class SGVec2; | ||||
template<typename T> | ||||
class SGVec3; | class SGVec3; | |||
template<typename T> | template<typename T> | |||
class SGVec4; | class SGVec4; | |||
typedef SGLocation<float> SGLocationf; | ||||
typedef SGLocation<double> SGLocationd; | ||||
typedef SGLimits<float> SGLimitsf; | typedef SGLimits<float> SGLimitsf; | |||
typedef SGLimits<double> SGLimitsd; | typedef SGLimits<double> SGLimitsd; | |||
typedef SGMatrix<float> SGMatrixf; | typedef SGMatrix<float> SGMatrixf; | |||
typedef SGMatrix<double> SGMatrixd; | typedef SGMatrix<double> SGMatrixd; | |||
typedef SGMisc<float> SGMiscf; | typedef SGMisc<float> SGMiscf; | |||
typedef SGMisc<double> SGMiscd; | typedef SGMisc<double> SGMiscd; | |||
typedef SGQuat<float> SGQuatf; | typedef SGQuat<float> SGQuatf; | |||
typedef SGQuat<double> SGQuatd; | typedef SGQuat<double> SGQuatd; | |||
typedef SGVec2<float> SGVec2f; | ||||
typedef SGVec2<double> SGVec2d; | ||||
typedef SGVec2<int> SGVec2i; | ||||
typedef SGVec3<float> SGVec3f; | typedef SGVec3<float> SGVec3f; | |||
typedef SGVec3<double> SGVec3d; | typedef SGVec3<double> SGVec3d; | |||
typedef SGVec3<int> SGVec3i; | ||||
typedef SGVec4<float> SGVec4f; | typedef SGVec4<float> SGVec4f; | |||
typedef SGVec4<double> SGVec4d; | typedef SGVec4<double> SGVec4d; | |||
typedef SGVec4<int> SGVec4i; | ||||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
0 lines changed or deleted | 11 lines changed or added | |||
SGMatrix.hxx | SGMatrix.hxx | |||
---|---|---|---|---|
skipping to change at line 66 | skipping to change at line 66 | |||
_data.flat[2] = m20; _data.flat[3] = m30; | _data.flat[2] = m20; _data.flat[3] = m30; | |||
_data.flat[4] = m01; _data.flat[5] = m11; | _data.flat[4] = m01; _data.flat[5] = m11; | |||
_data.flat[6] = m21; _data.flat[7] = m31; | _data.flat[6] = m21; _data.flat[7] = m31; | |||
_data.flat[8] = m02; _data.flat[9] = m12; | _data.flat[8] = m02; _data.flat[9] = m12; | |||
_data.flat[10] = m22; _data.flat[11] = m32; | _data.flat[10] = m22; _data.flat[11] = m32; | |||
_data.flat[12] = m03; _data.flat[13] = m13; | _data.flat[12] = m03; _data.flat[13] = m13; | |||
_data.flat[14] = m23; _data.flat[15] = m33; | _data.flat[14] = m23; _data.flat[15] = m33; | |||
} | } | |||
/// Constructor, build up a SGMatrix from a translation | /// Constructor, build up a SGMatrix from a translation | |||
SGMatrix(const SGVec3<T>& trans) | template<typename S> | |||
SGMatrix(const SGVec3<S>& trans) | ||||
{ set(trans); } | { set(trans); } | |||
/// Constructor, build up a SGMatrix from a rotation and a translation | /// Constructor, build up a SGMatrix from a rotation and a translation | |||
SGMatrix(const SGQuat<T>& quat, const SGVec3<T>& trans) | template<typename S> | |||
{ set(quat, trans); } | SGMatrix(const SGQuat<S>& quat) | |||
/// Constructor, build up a SGMatrix from a rotation and a translation | ||||
SGMatrix(const SGQuat<T>& quat) | ||||
{ set(quat); } | { set(quat); } | |||
/// Copy constructor for a transposed negated matrix | /// Copy constructor for a transposed negated matrix | |||
SGMatrix(const TransNegRef<T>& tm) | SGMatrix(const TransNegRef<T>& tm) | |||
{ set(tm); } | { set(tm); } | |||
/// Set from a tranlation | /// Set from a tranlation | |||
void set(const SGVec3<T>& trans) | template<typename S> | |||
void set(const SGVec3<S>& trans) | ||||
{ | { | |||
_data.flat[0] = 1; _data.flat[4] = 0; | _data.flat[0] = 1; _data.flat[4] = 0; | |||
_data.flat[8] = 0; _data.flat[12] = -trans(0); | _data.flat[8] = 0; _data.flat[12] = T(trans(0)); | |||
_data.flat[1] = 0; _data.flat[5] = 1; | _data.flat[1] = 0; _data.flat[5] = 1; | |||
_data.flat[9] = 0; _data.flat[13] = -trans(1); | _data.flat[9] = 0; _data.flat[13] = T(trans(1)); | |||
_data.flat[2] = 0; _data.flat[6] = 0; | _data.flat[2] = 0; _data.flat[6] = 0; | |||
_data.flat[10] = 1; _data.flat[14] = -trans(2); | _data.flat[10] = 1; _data.flat[14] = T(trans(2)); | |||
_data.flat[3] = 0; _data.flat[7] = 0; | _data.flat[3] = 0; _data.flat[7] = 0; | |||
_data.flat[11] = 0; _data.flat[15] = 1; | _data.flat[11] = 0; _data.flat[15] = 1; | |||
} | } | |||
/// Set from a scale/rotation and tranlation | /// Set from a scale/rotation and tranlation | |||
void set(const SGQuat<T>& quat, const SGVec3<T>& trans) | template<typename S> | |||
{ | void set(const SGQuat<S>& quat) | |||
T w = quat.w(); T x = quat.x(); T y = quat.y(); T z = quat.z(); | ||||
T xx = x*x; T yy = y*y; T zz = z*z; | ||||
T wx = w*x; T wy = w*y; T wz = w*z; | ||||
T xy = x*y; T xz = x*z; T yz = y*z; | ||||
_data.flat[0] = 1-2*(yy+zz); _data.flat[1] = 2*(xy-wz); | ||||
_data.flat[2] = 2*(xz+wy); _data.flat[3] = 0; | ||||
_data.flat[4] = 2*(xy+wz); _data.flat[5] = 1-2*(xx+zz); | ||||
_data.flat[6] = 2*(yz-wx); _data.flat[7] = 0; | ||||
_data.flat[8] = 2*(xz-wy); _data.flat[9] = 2*(yz+wx); | ||||
_data.flat[10] = 1-2*(xx+yy); _data.flat[11] = 0; | ||||
// Well, this one is ugly here, as that xform method on the current | ||||
// object needs the above data to be already set ... | ||||
SGVec3<T> t = xformVec(trans); | ||||
_data.flat[12] = -t(0); _data.flat[13] = -t(1); | ||||
_data.flat[14] = -t(2); _data.flat[15] = 1; | ||||
} | ||||
/// Set from a scale/rotation and tranlation | ||||
void set(const SGQuat<T>& quat) | ||||
{ | { | |||
T w = quat.w(); T x = quat.x(); T y = quat.y(); T z = quat.z(); | T w = quat.w(); T x = quat.x(); T y = quat.y(); T z = quat.z(); | |||
T xx = x*x; T yy = y*y; T zz = z*z; | T xx = x*x; T yy = y*y; T zz = z*z; | |||
T wx = w*x; T wy = w*y; T wz = w*z; | T wx = w*x; T wy = w*y; T wz = w*z; | |||
T xy = x*y; T xz = x*z; T yz = y*z; | T xy = x*y; T xz = x*z; T yz = y*z; | |||
_data.flat[0] = 1-2*(yy+zz); _data.flat[1] = 2*(xy-wz); | _data.flat[0] = 1-2*(yy+zz); _data.flat[1] = 2*(xy-wz); | |||
_data.flat[2] = 2*(xz+wy); _data.flat[3] = 0; | _data.flat[2] = 2*(xz+wy); _data.flat[3] = 0; | |||
_data.flat[4] = 2*(xy+wz); _data.flat[5] = 1-2*(xx+zz); | _data.flat[4] = 2*(xy+wz); _data.flat[5] = 1-2*(xx+zz); | |||
_data.flat[6] = 2*(yz-wx); _data.flat[7] = 0; | _data.flat[6] = 2*(yz-wx); _data.flat[7] = 0; | |||
_data.flat[8] = 2*(xz-wy); _data.flat[9] = 2*(yz+wx); | _data.flat[8] = 2*(xz-wy); _data.flat[9] = 2*(yz+wx); | |||
skipping to change at line 202 | skipping to change at line 184 | |||
template<typename S> | template<typename S> | |||
SGMatrix& operator*=(S s) | SGMatrix& operator*=(S s) | |||
{ for (unsigned i = 0; i < nEnts; ++i) _data.flat[i] *= s; return *this; } | { for (unsigned i = 0; i < nEnts; ++i) _data.flat[i] *= s; return *this; } | |||
/// Inplace scalar multiplication by 1/s | /// Inplace scalar multiplication by 1/s | |||
template<typename S> | template<typename S> | |||
SGMatrix& operator/=(S s) | SGMatrix& operator/=(S s) | |||
{ return operator*=(1/T(s)); } | { return operator*=(1/T(s)); } | |||
/// Inplace matrix multiplication, post multiply | /// Inplace matrix multiplication, post multiply | |||
SGMatrix& operator*=(const SGMatrix<T>& m2); | SGMatrix& operator*=(const SGMatrix<T>& m2); | |||
template<typename S> | ||||
SGMatrix& preMultTranslate(const SGVec3<S>& t) | ||||
{ | ||||
for (unsigned i = 0; i < 3; ++i) { | ||||
T tmp = T(t(i)); | ||||
if (tmp == 0) | ||||
continue; | ||||
(*this)(i,0) += tmp*(*this)(3,0); | ||||
(*this)(i,1) += tmp*(*this)(3,1); | ||||
(*this)(i,2) += tmp*(*this)(3,2); | ||||
(*this)(i,3) += tmp*(*this)(3,3); | ||||
} | ||||
return *this; | ||||
} | ||||
template<typename S> | ||||
SGMatrix& postMultTranslate(const SGVec3<S>& t) | ||||
{ | ||||
SGVec4<T> col3((*this)(0,3), (*this)(1,3), (*this)(2,3), (*this)(3,3)); | ||||
for (unsigned i = 0; i < SGMatrix<T>::nCols-1; ++i) { | ||||
SGVec4<T> tmp((*this)(0,i), (*this)(1,i), (*this)(2,i), (*this)(3,i)) | ||||
; | ||||
col3 += T(t(i))*tmp; | ||||
} | ||||
(*this)(0,3) = col3(0); (*this)(1,3) = col3(1); | ||||
(*this)(2,3) = col3(2); (*this)(3,3) = col3(3); | ||||
return *this; | ||||
} | ||||
SGMatrix& preMultRotate(const SGQuat<T>& r) | ||||
{ | ||||
for (unsigned i = 0; i < SGMatrix<T>::nCols; ++i) { | ||||
SGVec3<T> col((*this)(0,i), (*this)(1,i), (*this)(2,i)); | ||||
col = r.transform(col); | ||||
(*this)(0,i) = col(0); (*this)(1,i) = col(1); (*this)(2,i) = col(2); | ||||
} | ||||
return *this; | ||||
} | ||||
SGMatrix& postMultRotate(const SGQuat<T>& r) | ||||
{ | ||||
for (unsigned i = 0; i < SGMatrix<T>::nCols; ++i) { | ||||
SGVec3<T> col((*this)(i,0), (*this)(i,1), (*this)(i,2)); | ||||
col = r.backTransform(col); | ||||
(*this)(i,0) = col(0); (*this)(i,1) = col(1); (*this)(i,2) = col(2); | ||||
} | ||||
return *this; | ||||
} | ||||
SGVec3<T> xformPt(const SGVec3<T>& pt) const | SGVec3<T> xformPt(const SGVec3<T>& pt) const | |||
{ | { | |||
SGVec3<T> tpt; | SGVec3<T> tpt; | |||
tpt(0) = (*this)(0,3); | tpt(0) = (*this)(0,3); | |||
tpt(1) = (*this)(1,3); | tpt(1) = (*this)(1,3); | |||
tpt(2) = (*this)(2,3); | tpt(2) = (*this)(2,3); | |||
for (unsigned i = 0; i < SGMatrix<T>::nCols-1; ++i) { | for (unsigned i = 0; i < SGMatrix<T>::nCols-1; ++i) { | |||
T tmp = pt(i); | T tmp = pt(i); | |||
tpt(0) += tmp*(*this)(0,i); | tpt(0) += tmp*(*this)(0,i); | |||
tpt(1) += tmp*(*this)(1,i); | tpt(1) += tmp*(*this)(1,i); | |||
skipping to change at line 577 | skipping to change at line 605 | |||
s << " " << m(3,0) << ", " << m(3,1) << ", " << m(3,2) << ", " << m(3,3) << " ]"; | s << " " << m(3,0) << ", " << m(3,1) << ", " << m(3,2) << ", " << m(3,3) << " ]"; | |||
return s; | return s; | |||
} | } | |||
inline | inline | |||
SGMatrixf | SGMatrixf | |||
toMatrixf(const SGMatrixd& m) | toMatrixf(const SGMatrixd& m) | |||
{ | { | |||
return SGMatrixf((float)m(0,0), (float)m(0,1), (float)m(0,2), (float)m(0, 3), | return SGMatrixf((float)m(0,0), (float)m(0,1), (float)m(0,2), (float)m(0, 3), | |||
(float)m(1,0), (float)m(1,1), (float)m(1,2), (float)m(1, 3), | (float)m(1,0), (float)m(1,1), (float)m(1,2), (float)m(1, 3), | |||
(float)m(3,0), (float)m(2,1), (float)m(2,2), (float)m(2, | (float)m(2,0), (float)m(2,1), (float)m(2,2), (float)m(2, | |||
3), | 3), | |||
(float)m(4,0), (float)m(4,1), (float)m(4,2), (float)m(4, | (float)m(3,0), (float)m(3,1), (float)m(3,2), (float)m(3, | |||
3)); | 3)); | |||
} | } | |||
inline | inline | |||
SGMatrixd | SGMatrixd | |||
toMatrixd(const SGMatrixf& m) | toMatrixd(const SGMatrixf& m) | |||
{ | { | |||
return SGMatrixd(m(0,0), m(0,1), m(0,2), m(0,3), | return SGMatrixd(m(0,0), m(0,1), m(0,2), m(0,3), | |||
m(1,0), m(1,1), m(1,2), m(1,3), | m(1,0), m(1,1), m(1,2), m(1,3), | |||
m(3,0), m(2,1), m(2,2), m(2,3), | m(2,0), m(2,1), m(2,2), m(2,3), | |||
m(4,0), m(4,1), m(4,2), m(4,3)); | m(3,0), m(3,1), m(3,2), m(3,3)); | |||
} | } | |||
#endif | #endif | |||
End of changes. 10 change blocks. | ||||
35 lines changed or deleted | 64 lines changed or added | |||
SGMisc.hxx | SGMisc.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
#ifndef SGMisc_H | #ifndef SGMisc_H | |||
#define SGMisc_H | #define SGMisc_H | |||
template<typename T> | template<typename T> | |||
class SGMisc { | class SGMisc { | |||
public: | public: | |||
static T pi() { return T(3.1415926535897932384626433832795029L); } | static T pi() { return T(3.1415926535897932384626433832795029L); } | |||
static T twopi() { return 2*T(3.1415926535897932384626433832795029L); } | ||||
static T min(const T& a, const T& b) | static T min(const T& a, const T& b) | |||
{ return a < b ? a : b; } | { return a < b ? a : b; } | |||
static T min(const T& a, const T& b, const T& c) | static T min(const T& a, const T& b, const T& c) | |||
{ return min(min(a, b), c); } | { return min(min(a, b), c); } | |||
static T min(const T& a, const T& b, const T& c, const T& d) | static T min(const T& a, const T& b, const T& c, const T& d) | |||
{ return min(min(min(a, b), c), d); } | { return min(min(min(a, b), c), d); } | |||
static T max(const T& a, const T& b) | static T max(const T& a, const T& b) | |||
{ return a > b ? a : b; } | { return a > b ? a : b; } | |||
static T max(const T& a, const T& b, const T& c) | static T max(const T& a, const T& b, const T& c) | |||
{ return max(max(a, b), c); } | { return max(max(a, b), c); } | |||
static T max(const T& a, const T& b, const T& c, const T& d) | static T max(const T& a, const T& b, const T& c, const T& d) | |||
{ return max(max(max(a, b), c), d); } | { return max(max(max(a, b), c), d); } | |||
// clip the value of a to be in the range between and including _min and | ||||
_max | ||||
static T clip(const T& a, const T& _min, const T& _max) | ||||
{ return max(_min, min(_max, a)); } | ||||
/** | ||||
* Seek a variable towards a target value with given rate and timestep | ||||
* | ||||
* @param var Variable or eg. SGPropObj | ||||
* @param target Target value | ||||
* @param rate Max. change rate/sec | ||||
* @param dt Time step (sec) | ||||
*/ | ||||
template<class Var> | ||||
static T seek(Var& var, T target, T rate, T dt) | ||||
{ | ||||
if( var < target ) | ||||
return var = min(var + rate * dt, target); | ||||
else | ||||
return var = max(var - rate * dt, target); | ||||
} | ||||
/** | ||||
* Get @c base raised to the power of @c N | ||||
* | ||||
* @tparam N Exponent | ||||
* @param base Base | ||||
*/ | ||||
template<int N> | ||||
static T pow(T base) | ||||
{ | ||||
return (N < 0) | ||||
? (1. / pow<-N>(base)) | ||||
: ( ((N & 1) ? base : 1) | ||||
* ((N > 1) ? pow<N / 2>(base * base) : 1) | ||||
); | ||||
} | ||||
static int sign(const T& a) | static int sign(const T& a) | |||
{ | { | |||
if (a < -SGLimits<T>::min()) | if (a < -SGLimits<T>::min()) | |||
return -1; | return -1; | |||
else if (SGLimits<T>::min() < a) | else if (SGLimits<T>::min() < a) | |||
return 1; | return 1; | |||
else | else | |||
return 0; | return 0; | |||
} | } | |||
static T rad2deg(const T& val) | static T rad2deg(const T& val) | |||
{ return val*180/pi(); } | { return val*180/pi(); } | |||
static T deg2rad(const T& val) | static T deg2rad(const T& val) | |||
{ return val*pi()/180; } | { return val*pi()/180; } | |||
// normalize the value to be in a range between [min, max[ | ||||
static T | ||||
normalizePeriodic(const T& min, const T& max, const T& value) | ||||
{ | ||||
T range = max - min; | ||||
if (range < SGLimits<T>::min()) | ||||
return min; | ||||
T normalized = value - range*floor((value - min)/range); | ||||
// two security checks that can only happen due to roundoff | ||||
if (normalized <= min) | ||||
return min; | ||||
if (max <= normalized) | ||||
return min; | ||||
return normalized; | ||||
} | ||||
// normalize the angle to be in a range between [-pi, pi[ | ||||
static T | ||||
normalizeAngle(const T& angle) | ||||
{ return normalizePeriodic(-pi(), pi(), angle); } | ||||
// normalize the angle to be in a range between [0, 2pi[ | ||||
static T | ||||
normalizeAngle2(const T& angle) | ||||
{ return normalizePeriodic(0, twopi(), angle); } | ||||
static T round(const T& v) | static T round(const T& v) | |||
{ return floor(v + T(0.5)); } | { return floor(v + T(0.5)); } | |||
static int roundToInt(const T& v) | static int roundToInt(const T& v) | |||
{ return int(round(v)); } | { return int(round(v)); } | |||
#ifndef NDEBUG | // Linear interpolation between two arbitrary typed values | |||
template<typename S> | ||||
static S lerp(const S& val0, const S& val1, const T& t) | ||||
{ return val0*(T(1) - t) + val1*t; } | ||||
/// Returns true if v is a NaN value | /// Returns true if v is a NaN value | |||
/// Use with care: allways code that you do not need to use that! | /// Use with care: allways code that you do not need to use that! | |||
static bool isNaN(const T& v) | static bool isNaN(const T& v) | |||
{ | { | |||
#ifdef HAVE_ISNAN | #ifdef HAVE_ISNAN | |||
return isnan(v); | return isnan(v); | |||
#elif defined HAVE_STD_ISNAN | #elif defined HAVE_STD_ISNAN | |||
return std::isnan(v); | return std::isnan(v); | |||
#else | #else | |||
// Use that every compare involving a NaN returns false | // Use that every compare involving a NaN returns false | |||
// But be careful, some usual compiler switches like for example | // But be careful, some usual compiler switches like for example | |||
// -fast-math from gcc might optimize that expression to v != v which | // -fast-math from gcc might optimize that expression to v != v which | |||
// behaves exactly like the opposite ... | // behaves exactly like the opposite ... | |||
return !(v == v); | return !(v == v); | |||
#endif | #endif | |||
} | } | |||
#endif | ||||
}; | }; | |||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
2 lines changed or deleted | 72 lines changed or added | |||
SGQuat.hxx | SGQuat.hxx | |||
---|---|---|---|---|
// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de | // Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de | |||
// | // | |||
// This library is free software; you can redistribute it and/or | // This library is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU Library General Public | // modify it under the terms of the GNU Library General Public | |||
// License as published by the Free Software Foundation; either | // License as published by the Free Software Foundation; either | |||
// version 2 of the License, or (at your option) any later version. | // version 2 of the License, or (at your option) any later version. | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
skipping to change at line 29 | skipping to change at line 29 | |||
#define SGQuat_H | #define SGQuat_H | |||
#ifdef min | #ifdef min | |||
#undef min | #undef min | |||
#endif | #endif | |||
#ifdef max | #ifdef max | |||
#undef max | #undef max | |||
#endif | #endif | |||
/// 3D Vector Class | /// Quaternion Class | |||
template<typename T> | template<typename T> | |||
class SGQuat { | class SGQuat { | |||
public: | public: | |||
typedef T value_type; | typedef T value_type; | |||
/// Default constructor. Does not initialize at all. | /// Default constructor. Does not initialize at all. | |||
/// If you need them zero initialized, SGQuat::zeros() | /// If you need them zero initialized, SGQuat::zeros() | |||
SGQuat(void) | SGQuat(void) | |||
{ | { | |||
/// Initialize with nans in the debug build, that will guarantee to hav e | /// Initialize with nans in the debug build, that will guarantee to hav e | |||
/// a fast uninitialized default constructor in the release but shows u p | /// a fast uninitialized default constructor in the release but shows u p | |||
/// uninitialized values in the debug build very fast ... | /// uninitialized values in the debug build very fast ... | |||
#ifndef NDEBUG | #ifndef NDEBUG | |||
for (unsigned i = 0; i < 4; ++i) | for (unsigned i = 0; i < 4; ++i) | |||
_data[i] = SGLimits<T>::quiet_NaN(); | data()[i] = SGLimits<T>::quiet_NaN(); | |||
#endif | #endif | |||
} | } | |||
/// Constructor. Initialize by the given values | /// Constructor. Initialize by the given values | |||
SGQuat(T _x, T _y, T _z, T _w) | SGQuat(T _x, T _y, T _z, T _w) | |||
{ x() = _x; y() = _y; z() = _z; w() = _w; } | { x() = _x; y() = _y; z() = _z; w() = _w; } | |||
/// Constructor. Initialize by the content of a plain array, | /// Constructor. Initialize by the content of a plain array, | |||
/// make sure it has at least 4 elements | /// make sure it has at least 4 elements | |||
explicit SGQuat(const T* d) | explicit SGQuat(const T* d) | |||
{ _data[0] = d[0]; _data[1] = d[1]; _data[2] = d[2]; _data[3] = d[3]; } | { data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; } | |||
/// Return a unit quaternion | /// Return a unit quaternion | |||
static SGQuat unit(void) | static SGQuat unit(void) | |||
{ return fromRealImag(1, SGVec3<T>(0)); } | { return fromRealImag(1, SGVec3<T>(0, 0, 0)); } | |||
/// Return a quaternion from euler angles | /// Return a quaternion from euler angles | |||
static SGQuat fromEulerRad(T z, T y, T x) | static SGQuat fromEulerRad(T z, T y, T x) | |||
{ | { | |||
SGQuat q; | SGQuat q; | |||
T zd2 = T(0.5)*z; T yd2 = T(0.5)*y; T xd2 = T(0.5)*x; | T zd2 = T(0.5)*z; T yd2 = T(0.5)*y; T xd2 = T(0.5)*x; | |||
T Szd2 = sin(zd2); T Syd2 = sin(yd2); T Sxd2 = sin(xd2); | T Szd2 = sin(zd2); T Syd2 = sin(yd2); T Sxd2 = sin(xd2); | |||
T Czd2 = cos(zd2); T Cyd2 = cos(yd2); T Cxd2 = cos(xd2); | T Czd2 = cos(zd2); T Cyd2 = cos(yd2); T Cxd2 = cos(xd2); | |||
T Cxd2Czd2 = Cxd2*Czd2; T Cxd2Szd2 = Cxd2*Szd2; | T Cxd2Czd2 = Cxd2*Czd2; T Cxd2Szd2 = Cxd2*Szd2; | |||
T Sxd2Szd2 = Sxd2*Szd2; T Sxd2Czd2 = Sxd2*Czd2; | T Sxd2Szd2 = Sxd2*Szd2; T Sxd2Czd2 = Sxd2*Czd2; | |||
skipping to change at line 98 | skipping to change at line 98 | |||
{ return fromEulerDeg(y, p, r); } | { return fromEulerDeg(y, p, r); } | |||
/// Return a quaternion from euler angles | /// Return a quaternion from euler angles | |||
static SGQuat fromHeadAttBank(T h, T a, T b) | static SGQuat fromHeadAttBank(T h, T a, T b) | |||
{ return fromEulerRad(h, a, b); } | { return fromEulerRad(h, a, b); } | |||
/// Return a quaternion from euler angles | /// Return a quaternion from euler angles | |||
static SGQuat fromHeadAttBankDeg(T h, T a, T b) | static SGQuat fromHeadAttBankDeg(T h, T a, T b) | |||
{ return fromEulerDeg(h, a, b); } | { return fromEulerDeg(h, a, b); } | |||
/// Return a quaternion rotation the the horizontal local frame from give | /// Return a quaternion rotation from the earth centered to the | |||
n | /// simulation usual horizontal local frame from given | |||
/// longitude and latitude | /// longitude and latitude. | |||
/// The horizontal local frame used in simulations is the frame with x-ax | ||||
is | ||||
/// pointing north, the y-axis pointing eastwards and the z axis | ||||
/// pointing downwards. | ||||
static SGQuat fromLonLatRad(T lon, T lat) | static SGQuat fromLonLatRad(T lon, T lat) | |||
{ | { | |||
SGQuat q; | SGQuat q; | |||
T zd2 = T(0.5)*lon; | T zd2 = T(0.5)*lon; | |||
T yd2 = T(-0.25)*SGMisc<value_type>::pi() - T(0.5)*lat; | T yd2 = T(-0.25)*SGMisc<T>::pi() - T(0.5)*lat; | |||
T Szd2 = sin(zd2); | T Szd2 = sin(zd2); | |||
T Syd2 = sin(yd2); | T Syd2 = sin(yd2); | |||
T Czd2 = cos(zd2); | T Czd2 = cos(zd2); | |||
T Cyd2 = cos(yd2); | T Cyd2 = cos(yd2); | |||
q.w() = Czd2*Cyd2; | q.w() = Czd2*Cyd2; | |||
q.x() = -Szd2*Syd2; | q.x() = -Szd2*Syd2; | |||
q.y() = Czd2*Syd2; | q.y() = Czd2*Syd2; | |||
q.z() = Szd2*Cyd2; | q.z() = Szd2*Cyd2; | |||
return q; | return q; | |||
} | } | |||
/// Like the above provided for convenience | ||||
/// Return a quaternion rotation the the horizontal local frame from give | ||||
n | ||||
/// longitude and latitude | ||||
static SGQuat fromLonLatDeg(T lon, T lat) | static SGQuat fromLonLatDeg(T lon, T lat) | |||
{ return fromLonLatRad(SGMisc<T>::deg2rad(lon), SGMisc<T>::deg2rad(lat)); } | { return fromLonLatRad(SGMisc<T>::deg2rad(lon), SGMisc<T>::deg2rad(lat)); } | |||
/// Like the above provided for convenience | ||||
/// Return a quaternion rotation the the horizontal local frame from give | ||||
n | ||||
/// longitude and latitude | ||||
static SGQuat fromLonLat(const SGGeod& geod) | static SGQuat fromLonLat(const SGGeod& geod) | |||
{ return fromLonLatRad(geod.getLongitudeRad(), geod.getLatitudeRad()); } | { return fromLonLatRad(geod.getLongitudeRad(), geod.getLatitudeRad()); } | |||
/// Create a quaternion from the angle axis representation | /// Create a quaternion from the angle axis representation | |||
static SGQuat fromAngleAxis(T angle, const SGVec3<T>& axis) | static SGQuat fromAngleAxis(T angle, const SGVec3<T>& axis) | |||
{ | { | |||
T angle2 = 0.5*angle; | T angle2 = T(0.5)*angle; | |||
return fromRealImag(cos(angle2), T(sin(angle2))*axis); | return fromRealImag(cos(angle2), T(sin(angle2))*axis); | |||
} | } | |||
/// Create a quaternion from the angle axis representation | /// Create a quaternion from the angle axis representation | |||
static SGQuat fromAngleAxisDeg(T angle, const SGVec3<T>& axis) | static SGQuat fromAngleAxisDeg(T angle, const SGVec3<T>& axis) | |||
{ return fromAngleAxis(SGMisc<T>::deg2rad(angle), axis); } | { return fromAngleAxis(SGMisc<T>::deg2rad(angle), axis); } | |||
/// Create a quaternion from the angle axis representation where the angl e | /// Create a quaternion from the angle axis representation where the angl e | |||
/// is stored in the axis' length | /// is stored in the axis' length | |||
static SGQuat fromAngleAxis(const SGVec3<T>& axis) | static SGQuat fromAngleAxis(const SGVec3<T>& axis) | |||
{ | { | |||
T nAxis = norm(axis); | T nAxis = norm(axis); | |||
if (nAxis <= SGLimits<T>::min()) | if (nAxis <= SGLimits<T>::min()) | |||
return SGQuat(1, 0, 0, 0); | return SGQuat::unit(); | |||
T angle2 = 0.5*nAxis; | T angle2 = T(0.5)*nAxis; | |||
return fromRealImag(cos(angle2), T(sin(angle2)/nAxis)*axis); | return fromRealImag(cos(angle2), T(sin(angle2)/nAxis)*axis); | |||
} | } | |||
/// Create a normalized quaternion just from the imaginary part. | ||||
/// The imaginary part should point into that axis direction that results | ||||
in | ||||
/// a quaternion with a positive real part. | ||||
/// This is the smallest numerically stable representation of an orientat | ||||
ion | ||||
/// in space. See getPositiveRealImag() | ||||
static SGQuat fromPositiveRealImag(const SGVec3<T>& imag) | ||||
{ | ||||
T r = sqrt(SGMisc<T>::max(T(0), T(1) - dot(imag, imag))); | ||||
return fromRealImag(r, imag); | ||||
} | ||||
/// Return a quaternion that rotates the from vector onto the to vector. | ||||
static SGQuat fromRotateTo(const SGVec3<T>& from, const SGVec3<T>& to) | ||||
{ | ||||
T nfrom = norm(from); | ||||
T nto = norm(to); | ||||
if (nfrom <= SGLimits<T>::min() || nto <= SGLimits<T>::min()) | ||||
return SGQuat::unit(); | ||||
return SGQuat::fromRotateToNorm((1/nfrom)*from, (1/nto)*to); | ||||
} | ||||
/// Return a quaternion that rotates v1 onto the i1-th unit vector | ||||
/// and v2 into a plane that is spanned by the i2-th and i1-th unit vecto | ||||
r. | ||||
static SGQuat fromRotateTo(const SGVec3<T>& v1, unsigned i1, | ||||
const SGVec3<T>& v2, unsigned i2) | ||||
{ | ||||
T nrmv1 = norm(v1); | ||||
T nrmv2 = norm(v2); | ||||
if (nrmv1 <= SGLimits<T>::min() || nrmv2 <= SGLimits<T>::min()) | ||||
return SGQuat::unit(); | ||||
SGVec3<T> nv1 = (1/nrmv1)*v1; | ||||
SGVec3<T> nv2 = (1/nrmv2)*v2; | ||||
T dv1v2 = dot(nv1, nv2); | ||||
if (fabs(fabs(dv1v2)-1) <= SGLimits<T>::epsilon()) | ||||
return SGQuat::unit(); | ||||
// The target vector for the first rotation | ||||
SGVec3<T> nto1 = SGVec3<T>::zeros(); | ||||
SGVec3<T> nto2 = SGVec3<T>::zeros(); | ||||
nto1[i1] = 1; | ||||
nto2[i2] = 1; | ||||
// The first rotation can be done with the usual routine. | ||||
SGQuat q = SGQuat::fromRotateToNorm(nv1, nto1); | ||||
// The rotation axis for the second rotation is the | ||||
// target for the first one, so the rotation axis is nto1 | ||||
// We need to get the angle. | ||||
// Make nv2 exactly orthogonal to nv1. | ||||
nv2 = normalize(nv2 - dv1v2*nv1); | ||||
SGVec3<T> tnv2 = q.transform(nv2); | ||||
T cosang = dot(nto2, tnv2); | ||||
T cos05ang = T(0.5)+T(0.5)*cosang; | ||||
if (cos05ang <= 0) | ||||
cosang = 0; | ||||
cos05ang = sqrt(cos05ang); | ||||
T sig = dot(nto1, cross(nto2, tnv2)); | ||||
T sin05ang = T(0.5)-T(0.5)*cosang; | ||||
if (sin05ang <= 0) | ||||
sin05ang = 0; | ||||
sin05ang = copysign(sqrt(sin05ang), sig); | ||||
q *= SGQuat::fromRealImag(cos05ang, sin05ang*nto1); | ||||
return q; | ||||
} | ||||
// Return a quaternion which rotates the vector given by v | ||||
// to the vector -v. Other directions are *not* preserved. | ||||
static SGQuat fromChangeSign(const SGVec3<T>& v) | ||||
{ | ||||
// The vector from points to the oposite direction than to. | ||||
// Find a vector perpendicular to the vector to. | ||||
T absv1 = fabs(v(0)); | ||||
T absv2 = fabs(v(1)); | ||||
T absv3 = fabs(v(2)); | ||||
SGVec3<T> axis; | ||||
if (absv2 < absv1 && absv3 < absv1) { | ||||
T quot = v(1)/v(0); | ||||
axis = (1/sqrt(1+quot*quot))*SGVec3<T>(quot, -1, 0); | ||||
} else if (absv1 < absv2 && absv3 < absv2) { | ||||
T quot = v(2)/v(1); | ||||
axis = (1/sqrt(1+quot*quot))*SGVec3<T>(0, quot, -1); | ||||
} else if (absv1 < absv3 && absv2 < absv3) { | ||||
T quot = v(0)/v(2); | ||||
axis = (1/sqrt(1+quot*quot))*SGVec3<T>(-1, 0, quot); | ||||
} else { | ||||
// The all zero case. | ||||
return SGQuat::unit(); | ||||
} | ||||
return SGQuat::fromRealImag(0, axis); | ||||
} | ||||
/// Return a quaternion from real and imaginary part | /// Return a quaternion from real and imaginary part | |||
static SGQuat fromRealImag(T r, const SGVec3<T>& i) | static SGQuat fromRealImag(T r, const SGVec3<T>& i) | |||
{ | { | |||
SGQuat q; | SGQuat q; | |||
q.w() = r; | q.w() = r; | |||
q.x() = i(0); | q.x() = i.x(); | |||
q.y() = i(1); | q.y() = i.y(); | |||
q.z() = i(2); | q.z() = i.z(); | |||
return q; | return q; | |||
} | } | |||
/// Return an all zero vector | /// Return an all zero vector | |||
static SGQuat zeros(void) | static SGQuat zeros(void) | |||
{ return SGQuat(0, 0, 0, 0); } | { return SGQuat(0, 0, 0, 0); } | |||
/// write the euler angles into the references | /// write the euler angles into the references | |||
void getEulerRad(T& zRad, T& yRad, T& xRad) const | void getEulerRad(T& zRad, T& yRad, T& xRad) const | |||
{ | { | |||
value_type sqrQW = w()*w(); | T sqrQW = w()*w(); | |||
value_type sqrQX = x()*x(); | T sqrQX = x()*x(); | |||
value_type sqrQY = y()*y(); | T sqrQY = y()*y(); | |||
value_type sqrQZ = z()*z(); | T sqrQZ = z()*z(); | |||
value_type num = 2*(y()*z() + w()*x()); | T num = 2*(y()*z() + w()*x()); | |||
value_type den = sqrQW - sqrQX - sqrQY + sqrQZ; | T den = sqrQW - sqrQX - sqrQY + sqrQZ; | |||
if (fabs(den) < SGLimits<value_type>::min() && | if (fabs(den) <= SGLimits<T>::min() && | |||
fabs(num) < SGLimits<value_type>::min()) | fabs(num) <= SGLimits<T>::min()) | |||
xRad = 0; | xRad = 0; | |||
else | else | |||
xRad = atan2(num, den); | xRad = atan2(num, den); | |||
value_type tmp = 2*(x()*z() - w()*y()); | T tmp = 2*(x()*z() - w()*y()); | |||
if (tmp < -1) | if (tmp <= -1) | |||
yRad = 0.5*SGMisc<value_type>::pi(); | yRad = T(0.5)*SGMisc<T>::pi(); | |||
else if (1 < tmp) | else if (1 <= tmp) | |||
yRad = -0.5*SGMisc<value_type>::pi(); | yRad = -T(0.5)*SGMisc<T>::pi(); | |||
else | else | |||
yRad = -asin(tmp); | yRad = -asin(tmp); | |||
num = 2*(x()*y() + w()*z()); | num = 2*(x()*y() + w()*z()); | |||
den = sqrQW + sqrQX - sqrQY - sqrQZ; | den = sqrQW + sqrQX - sqrQY - sqrQZ; | |||
if (fabs(den) < SGLimits<value_type>::min() && | if (fabs(den) <= SGLimits<T>::min() && | |||
fabs(num) < SGLimits<value_type>::min()) | fabs(num) <= SGLimits<T>::min()) | |||
zRad = 0; | zRad = 0; | |||
else { | else { | |||
value_type psi = atan2(num, den); | T psi = atan2(num, den); | |||
if (psi < 0) | if (psi < 0) | |||
psi += 2*SGMisc<value_type>::pi(); | psi += 2*SGMisc<T>::pi(); | |||
zRad = psi; | zRad = psi; | |||
} | } | |||
} | } | |||
/// write the euler angles in degrees into the references | /// write the euler angles in degrees into the references | |||
void getEulerDeg(T& zDeg, T& yDeg, T& xDeg) const | void getEulerDeg(T& zDeg, T& yDeg, T& xDeg) const | |||
{ | { | |||
getEulerRad(zDeg, yDeg, xDeg); | getEulerRad(zDeg, yDeg, xDeg); | |||
zDeg = SGMisc<T>::rad2deg(zDeg); | zDeg = SGMisc<T>::rad2deg(zDeg); | |||
yDeg = SGMisc<T>::rad2deg(yDeg); | yDeg = SGMisc<T>::rad2deg(yDeg); | |||
xDeg = SGMisc<T>::rad2deg(xDeg); | xDeg = SGMisc<T>::rad2deg(xDeg); | |||
} | } | |||
/// write the angle axis representation into the references | /// write the angle axis representation into the references | |||
void getAngleAxis(T& angle, SGVec3<T>& axis) const | void getAngleAxis(T& angle, SGVec3<T>& axis) const | |||
{ | { | |||
T nrm = norm(*this); | T nrm = norm(*this); | |||
if (nrm < SGLimits<T>::min()) { | if (nrm <= SGLimits<T>::min()) { | |||
angle = 0; | angle = 0; | |||
axis = SGVec3<T>(0, 0, 0); | axis = SGVec3<T>(0, 0, 0); | |||
} else { | } else { | |||
T rNrm = 1/nrm; | T rNrm = 1/nrm; | |||
angle = acos(SGMisc<T>::max(-1, SGMisc<T>::min(1, rNrm*w()))); | angle = acos(SGMisc<T>::max(-1, SGMisc<T>::min(1, rNrm*w()))); | |||
T sAng = sin(angle); | T sAng = sin(angle); | |||
if (fabs(sAng) < SGLimits<T>::min()) | if (fabs(sAng) <= SGLimits<T>::min()) | |||
axis = SGVec3<T>(1, 0, 0); | axis = SGVec3<T>(1, 0, 0); | |||
else | else | |||
axis = (rNrm/sAng)*imag(*this); | axis = (rNrm/sAng)*imag(*this); | |||
angle *= 2; | angle *= 2; | |||
} | } | |||
} | } | |||
/// write the angle axis representation into the references | /// write the angle axis representation into the references | |||
void getAngleAxis(SGVec3<T>& axis) const | void getAngleAxis(SGVec3<T>& axis) const | |||
{ | { | |||
T angle; | T angle; | |||
getAngleAxis(angle, axis); | getAngleAxis(angle, axis); | |||
axis *= angle; | axis *= angle; | |||
} | } | |||
/// Get the imaginary part of the quaternion. | ||||
/// The imaginary part should point into that axis direction that results | ||||
in | ||||
/// a quaternion with a positive real part. | ||||
/// This is the smallest numerically stable representation of an orientat | ||||
ion | ||||
/// in space. See fromPositiveRealImag() | ||||
SGVec3<T> getPositiveRealImag() const | ||||
{ | ||||
if (real(*this) < T(0)) | ||||
return (T(-1)/norm(*this))*imag(*this); | ||||
else | ||||
return (T(1)/norm(*this))*imag(*this); | ||||
} | ||||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
const T& operator()(unsigned i) const | const T& operator()(unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
T& operator()(unsigned i) | T& operator()(unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
const T& operator[](unsigned i) const | const T& operator[](unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
T& operator[](unsigned i) | T& operator[](unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access the x component | /// Access the x component | |||
const T& x(void) const | const T& x(void) const | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the x component | /// Access the x component | |||
T& x(void) | T& x(void) | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the y component | /// Access the y component | |||
const T& y(void) const | const T& y(void) const | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the y component | /// Access the y component | |||
T& y(void) | T& y(void) | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the z component | /// Access the z component | |||
const T& z(void) const | const T& z(void) const | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Access the z component | /// Access the z component | |||
T& z(void) | T& z(void) | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Access the w component | /// Access the w component | |||
const T& w(void) const | const T& w(void) const | |||
{ return _data[3]; } | { return data()[3]; } | |||
/// Access the w component | /// Access the w component | |||
T& w(void) | T& w(void) | |||
{ return _data[3]; } | { return data()[3]; } | |||
/// Get the data pointer, usefull for interfacing with plib's sg*Vec | ||||
const T* data(void) const | ||||
{ return _data; } | ||||
/// Get the data pointer, usefull for interfacing with plib's sg*Vec | ||||
T* data(void) | ||||
{ return _data; } | ||||
/// Readonly interface function to ssg's sgQuat/sgdQuat | /// Get the data pointer | |||
const T (&sg(void) const)[4] | const T (&data(void) const)[4] | |||
{ return _data; } | { return _data; } | |||
/// Interface function to ssg's sgQuat/sgdQuat | /// Get the data pointer | |||
T (&sg(void))[4] | T (&data(void))[4] | |||
{ return _data; } | { return _data; } | |||
/// Inplace addition | /// Inplace addition | |||
SGQuat& operator+=(const SGQuat& v) | SGQuat& operator+=(const SGQuat& v) | |||
{ _data[0]+=v(0);_data[1]+=v(1);_data[2]+=v(2);_data[3]+=v(3);return *thi s; } | { data()[0]+=v(0);data()[1]+=v(1);data()[2]+=v(2);data()[3]+=v(3);return *this; } | |||
/// Inplace subtraction | /// Inplace subtraction | |||
SGQuat& operator-=(const SGQuat& v) | SGQuat& operator-=(const SGQuat& v) | |||
{ _data[0]-=v(0);_data[1]-=v(1);_data[2]-=v(2);_data[3]-=v(3);return *thi s; } | { data()[0]-=v(0);data()[1]-=v(1);data()[2]-=v(2);data()[3]-=v(3);return *this; } | |||
/// Inplace scalar multiplication | /// Inplace scalar multiplication | |||
template<typename S> | template<typename S> | |||
SGQuat& operator*=(S s) | SGQuat& operator*=(S s) | |||
{ _data[0] *= s; _data[1] *= s; _data[2] *= s; _data[3] *= s; return *thi s; } | { data()[0] *= s; data()[1] *= s; data()[2] *= s; data()[3] *= s; return *this; } | |||
/// Inplace scalar multiplication by 1/s | /// Inplace scalar multiplication by 1/s | |||
template<typename S> | template<typename S> | |||
SGQuat& operator/=(S s) | SGQuat& operator/=(S s) | |||
{ return operator*=(1/T(s)); } | { return operator*=(1/T(s)); } | |||
/// Inplace quaternion multiplication | /// Inplace quaternion multiplication | |||
SGQuat& operator*=(const SGQuat& v); | SGQuat& operator*=(const SGQuat& v); | |||
/// Transform a vector from the current coordinate frame to a coordinate | /// Transform a vector from the current coordinate frame to a coordinate | |||
/// frame rotated with the quaternion | /// frame rotated with the quaternion | |||
SGVec3<T> transform(const SGVec3<T>& v) const | SGVec3<T> transform(const SGVec3<T>& v) const | |||
{ | { | |||
value_type r = 2/dot(*this, *this); | T r = 2/dot(*this, *this); | |||
SGVec3<T> qimag = imag(*this); | SGVec3<T> qimag = imag(*this); | |||
value_type qr = real(*this); | T qr = real(*this); | |||
return (r*qr*qr - 1)*v + (r*dot(qimag, v))*qimag - (r*qr)*cross(qimag, v); | return (r*qr*qr - 1)*v + (r*dot(qimag, v))*qimag - (r*qr)*cross(qimag, v); | |||
} | } | |||
/// Transform a vector from the coordinate frame rotated with the quatern ion | /// Transform a vector from the coordinate frame rotated with the quatern ion | |||
/// to the current coordinate frame | /// to the current coordinate frame | |||
SGVec3<T> backTransform(const SGVec3<T>& v) const | SGVec3<T> backTransform(const SGVec3<T>& v) const | |||
{ | { | |||
value_type r = 2/dot(*this, *this); | T r = 2/dot(*this, *this); | |||
SGVec3<T> qimag = imag(*this); | SGVec3<T> qimag = imag(*this); | |||
value_type qr = real(*this); | T qr = real(*this); | |||
return (r*qr*qr - 1)*v + (r*dot(qimag, v))*qimag + (r*qr)*cross(qimag, v); | return (r*qr*qr - 1)*v + (r*dot(qimag, v))*qimag + (r*qr)*cross(qimag, v); | |||
} | } | |||
/// Rotate a given vector with the quaternion | /// Rotate a given vector with the quaternion | |||
SGVec3<T> rotate(const SGVec3<T>& v) const | SGVec3<T> rotate(const SGVec3<T>& v) const | |||
{ return backTransform(v); } | { return backTransform(v); } | |||
/// Rotate a given vector with the inverse quaternion | /// Rotate a given vector with the inverse quaternion | |||
SGVec3<T> rotateBack(const SGVec3<T>& v) const | SGVec3<T> rotateBack(const SGVec3<T>& v) const | |||
{ return transform(v); } | { return transform(v); } | |||
/// Return the time derivative of the quaternion given the angular veloci ty | /// Return the time derivative of the quaternion given the angular veloci ty | |||
SGQuat | SGQuat | |||
derivative(const SGVec3<T>& angVel) | derivative(const SGVec3<T>& angVel) const | |||
{ | { | |||
SGQuat deriv; | SGQuat deriv; | |||
deriv.w() = 0.5*(-x()*angVel(0) - y()*angVel(1) - z()*angVel(2)); | deriv.w() = T(0.5)*(-x()*angVel(0) - y()*angVel(1) - z()*angVel(2)); | |||
deriv.x() = 0.5*( w()*angVel(0) - z()*angVel(1) + y()*angVel(2)); | deriv.x() = T(0.5)*( w()*angVel(0) - z()*angVel(1) + y()*angVel(2)); | |||
deriv.y() = 0.5*( z()*angVel(0) + w()*angVel(1) - x()*angVel(2)); | deriv.y() = T(0.5)*( z()*angVel(0) + w()*angVel(1) - x()*angVel(2)); | |||
deriv.z() = 0.5*(-y()*angVel(0) + x()*angVel(1) + w()*angVel(2)); | deriv.z() = T(0.5)*(-y()*angVel(0) + x()*angVel(1) + w()*angVel(2)); | |||
return deriv; | return deriv; | |||
} | } | |||
/// Return the angular velocity w that makes q0 translate to q1 using | ||||
/// an explicit euler step with stepsize h. | ||||
/// That is, look for an w where | ||||
/// q1 = normalize(q0 + h*q0.derivative(w)) | ||||
static SGVec3<T> | ||||
forwardDifferenceVelocity(const SGQuat& q0, const SGQuat& q1, const T& h) | ||||
{ | ||||
// Let D_q0*w = q0.derivative(w), D_q0 the above 4x3 matrix. | ||||
// Then D_q0^t*D_q0 = 0.25*Id and D_q0*q0 = 0. | ||||
// Let lambda be a nonzero normailzation factor, then | ||||
// q1 = normalize(q0 + h*q0.derivative(w)) | ||||
// can be rewritten | ||||
// lambda*q1 = q0 + h*D_q0*w. | ||||
// Multiply left by the transpose D_q0^t and reorder gives | ||||
// 4*lambda/h*D_q0^t*q1 = w. | ||||
// Now compute lambda by substitution of w into the original | ||||
// equation | ||||
// lambda*q1 = q0 + 4*lambda*D_q0*D_q0^t*q1, | ||||
// multiply by q1^t from the left | ||||
// lambda*<q1,q1> = <q0,q1> + 4*lambda*<D_q0^t*q1,D_q0^t*q1> | ||||
// and solving for lambda gives | ||||
// lambda = <q0,q1>/(1 - 4*<D_q0^t*q1,D_q0^t*q1>). | ||||
// The transpose of the derivative matrix | ||||
// the 0.5 factor is handled below | ||||
// also note that the initializer uses x, y, z, w instead of w, x, y, z | ||||
SGQuat d0(q0.w(), q0.z(), -q0.y(), -q0.x()); | ||||
SGQuat d1(-q0.z(), q0.w(), q0.x(), -q0.y()); | ||||
SGQuat d2(q0.y(), -q0.x(), q0.w(), -q0.z()); | ||||
// 2*D_q0^t*q1 | ||||
SGVec3<T> Dq(dot(d0, q1), dot(d1, q1), dot(d2, q1)); | ||||
// Like above, but take into account that Dq = 2*D_q0^t*q1 | ||||
T lambda = dot(q0, q1)/(T(1) - dot(Dq, Dq)); | ||||
return (2*lambda/h)*Dq; | ||||
} | ||||
private: | private: | |||
/// The actual data | ||||
// Private because it assumes normalized inputs. | ||||
static SGQuat | ||||
fromRotateToSmaller90Deg(T cosang, | ||||
const SGVec3<T>& from, const SGVec3<T>& to) | ||||
{ | ||||
// In this function we assume that the angle required to rotate from | ||||
// the vector from to the vector to is <= 90 deg. | ||||
// That is done so because of possible instabilities when we rotate mor | ||||
e | ||||
// then 90deg. | ||||
// Note that the next comment does actually cover a *more* *general* ca | ||||
se | ||||
// than we need in this function. That shows that this formula is even | ||||
// valid for rotations up to 180deg. | ||||
// Because of the signs in the axis, it is sufficient to care for angle | ||||
s | ||||
// in the interval [-pi,pi]. That means that 0.5*angle is in the interv | ||||
al | ||||
// [-pi/2,pi/2]. But in that range the cosine is allways >= 0. | ||||
// So we do not need to care for egative roots in the following equatio | ||||
n: | ||||
T cos05ang = sqrt(T(0.5)+T(0.5)*cosang); | ||||
// Now our assumption of angles <= 90 deg comes in play. | ||||
// For that reason, we know that cos05ang is not zero. | ||||
// It is even more, we can see from the above formula that | ||||
// sqrt(0.5) < cos05ang. | ||||
// Compute the rotation axis, that is | ||||
// sin(angle)*normalized rotation axis | ||||
SGVec3<T> axis = cross(to, from); | ||||
// We need sin(0.5*angle)*normalized rotation axis. | ||||
// So rescale with sin(0.5*x)/sin(x). | ||||
// To do that we use the equation: | ||||
// sin(x) = 2*sin(0.5*x)*cos(0.5*x) | ||||
return SGQuat::fromRealImag( cos05ang, (1/(2*cos05ang))*axis); | ||||
} | ||||
// Private because it assumes normalized inputs. | ||||
static SGQuat | ||||
fromRotateToNorm(const SGVec3<T>& from, const SGVec3<T>& to) | ||||
{ | ||||
// To avoid instabilities with roundoff, we distinguish between rotatio | ||||
ns | ||||
// with more then 90deg and rotations with less than 90deg. | ||||
// Compute the cosine of the angle. | ||||
T cosang = dot(from, to); | ||||
// For the small ones do direct computation | ||||
if (T(-0.5) < cosang) | ||||
return SGQuat::fromRotateToSmaller90Deg(cosang, from, to); | ||||
// For larger rotations. first rotate from to -from. | ||||
// Past that we will have a smaller angle again. | ||||
SGQuat q1 = SGQuat::fromChangeSign(from); | ||||
SGQuat q2 = SGQuat::fromRotateToSmaller90Deg(-cosang, -from, to); | ||||
return q1*q2; | ||||
} | ||||
T _data[4]; | T _data[4]; | |||
}; | }; | |||
/// Unary +, do nothing ... | /// Unary +, do nothing ... | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
const SGQuat<T>& | const SGQuat<T>& | |||
operator+(const SGQuat<T>& v) | operator+(const SGQuat<T>& v) | |||
{ return v; } | { return v; } | |||
skipping to change at line 547 | skipping to change at line 744 | |||
// result is correct | // result is correct | |||
if (1 <= cosPhi) | if (1 <= cosPhi) | |||
return dst; | return dst; | |||
// now the half angle between the orientations | // now the half angle between the orientations | |||
T o = acos(cosPhi); | T o = acos(cosPhi); | |||
// need the scales now, if the angle is very small, do linear interpolati on | // need the scales now, if the angle is very small, do linear interpolati on | |||
// to avoid instabilities | // to avoid instabilities | |||
T scale0, scale1; | T scale0, scale1; | |||
if (fabs(o) < SGLimits<T>::epsilon()) { | if (fabs(o) <= SGLimits<T>::epsilon()) { | |||
scale0 = 1 - t; | scale0 = 1 - t; | |||
scale1 = t; | scale1 = t; | |||
} else { | } else { | |||
// note that we can give a positive lower bound for sin(o) here | // note that we can give a positive lower bound for sin(o) here | |||
T sino = sin(o); | T sino = sin(o); | |||
T so = 1/sino; | T so = 1/sino; | |||
scale0 = sin((1 - t)*o)*so; | scale0 = sin((1 - t)*o)*so; | |||
scale1 = sin(t*o)*so; | scale1 = sin(t*o)*so; | |||
} | } | |||
End of changes. 47 change blocks. | ||||
80 lines changed or deleted | 286 lines changed or added | |||
SGQueue.hxx | SGQueue.hxx | |||
---|---|---|---|---|
#ifndef SGQUEUE_HXX_INCLUDED | #ifndef SGQUEUE_HXX_INCLUDED | |||
#define SGQUEUE_HXX_INCLUDED 1 | #define SGQUEUE_HXX_INCLUDED 1 | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#if defined ( SG_HAVE_STD_INCLUDES ) | #include <cassert> | |||
# include <cassert> | ||||
#else | ||||
# include <assert.h> | ||||
#endif | ||||
#include <queue> | #include <queue> | |||
#include "SGThread.hxx" | ||||
#include "SGGuard.hxx" | #include "SGGuard.hxx" | |||
#include "SGThread.hxx" | ||||
/** | /** | |||
* SGQueue defines an interface for a FIFO. | * SGQueue defines an interface for a FIFO. | |||
* It can be implemented using different types of synchronization | * It can be implemented using different types of synchronization | |||
* and protection. | * and protection. | |||
*/ | */ | |||
template<class T> | template<class T> | |||
class SGQueue | class SGQueue | |||
{ | { | |||
public: | public: | |||
skipping to change at line 81 | skipping to change at line 76 | |||
protected: | protected: | |||
/** | /** | |||
* | * | |||
*/ | */ | |||
std::queue<T> fifo; | std::queue<T> fifo; | |||
}; | }; | |||
/** | /** | |||
* A simple thread safe queue. All access functions are guarded with a mut ex. | * A simple thread safe queue. All access functions are guarded with a mut ex. | |||
*/ | */ | |||
template<class T, class SGLOCK=SGMutex> | template<class T> | |||
class SGLockedQueue : public SGQueue<T> | class SGLockedQueue : public SGQueue<T> | |||
{ | { | |||
public: | public: | |||
/** | /** | |||
* Create a new SGLockedQueue object. | * Create a new SGLockedQueue object. | |||
*/ | */ | |||
SGLockedQueue() {} | SGLockedQueue() {} | |||
/** | /** | |||
* Destroy this object. | * Destroy this object. | |||
*/ | */ | |||
~SGLockedQueue() {} | ~SGLockedQueue() {} | |||
/** | /** | |||
* Returns whether this queue is empty (contains no elements). | * Returns whether this queue is empty (contains no elements). | |||
* | * | |||
* @return bool True if queue is empty, otherwisr false. | * @return bool True if queue is empty, otherwisr false. | |||
*/ | */ | |||
virtual bool empty() { | virtual bool empty() { | |||
SGGuard<SGLOCK> g(mutex); | SGGuard<SGMutex> g(mutex); | |||
return this->fifo.empty(); | return this->fifo.empty(); | |||
} | } | |||
/** | /** | |||
* Add an item to the end of the queue. | * Add an item to the end of the queue. | |||
* | * | |||
* @param T object to add. | * @param T object to add. | |||
*/ | */ | |||
virtual void push( const T& item ) { | virtual void push( const T& item ) { | |||
SGGuard<SGLOCK> g(mutex); | SGGuard<SGMutex> g(mutex); | |||
this->fifo.push( item ); | this->fifo.push( item ); | |||
} | } | |||
/** | /** | |||
* View the item from the head of the queue. | * View the item from the head of the queue. | |||
* | * | |||
* @return T next available object. | * @return T next available object. | |||
*/ | */ | |||
virtual T front() { | virtual T front() { | |||
SGGuard<SGLOCK> g(mutex); | SGGuard<SGMutex> g(mutex); | |||
assert( ! this->fifo.empty() ); | assert( ! this->fifo.empty() ); | |||
T item = this->fifo.front(); | T item = this->fifo.front(); | |||
return item; | return item; | |||
} | } | |||
/** | /** | |||
* Get an item from the head of the queue. | * Get an item from the head of the queue. | |||
* | * | |||
* @return T next available object. | * @return T next available object. | |||
*/ | */ | |||
virtual T pop() { | virtual T pop() { | |||
SGGuard<SGLOCK> g(mutex); | SGGuard<SGMutex> g(mutex); | |||
//if (fifo.empty()) throw NoSuchElementException(); | if (this->fifo.empty()) return T(); // assumes T is default cons | |||
assert( ! this->fifo.empty() ); | tructable | |||
// if (fifo.empty()) | // if (fifo.empty()) | |||
// { | // { | |||
// mutex.unlock(); | // mutex.unlock(); | |||
// pthread_exit( PTHREAD_CANCELED ); | // pthread_exit( PTHREAD_CANCELED ); | |||
// } | // } | |||
T item = this->fifo.front(); | T item = this->fifo.front(); | |||
this->fifo.pop(); | this->fifo.pop(); | |||
return item; | return item; | |||
} | } | |||
/** | /** | |||
* Query the size of the queue | * Query the size of the queue | |||
* | * | |||
* @return size_t size of queue. | * @return size_t size of queue. | |||
*/ | */ | |||
virtual size_t size() { | virtual size_t size() { | |||
SGGuard<SGLOCK> g(mutex); | SGGuard<SGMutex> g(mutex); | |||
return this->fifo.size(); | return this->fifo.size(); | |||
} | } | |||
private: | private: | |||
/** | /** | |||
* Mutex to serialise access. | * Mutex to serialise access. | |||
*/ | */ | |||
SGLOCK mutex; | SGMutex mutex; | |||
private: | private: | |||
// Prevent copying. | // Prevent copying. | |||
SGLockedQueue(const SGLockedQueue&); | SGLockedQueue(const SGLockedQueue&); | |||
SGLockedQueue& operator= (const SGLockedQueue&); | SGLockedQueue& operator= (const SGLockedQueue&); | |||
}; | }; | |||
/** | /** | |||
* A guarded queue blocks threads trying to retrieve items | * A guarded queue blocks threads trying to retrieve items | |||
* when none are available. | * when none are available. | |||
skipping to change at line 263 | skipping to change at line 258 | |||
private: | private: | |||
/** | /** | |||
* Mutex to serialise access. | * Mutex to serialise access. | |||
*/ | */ | |||
SGMutex mutex; | SGMutex mutex; | |||
/** | /** | |||
* Condition to signal when queue not empty. | * Condition to signal when queue not empty. | |||
*/ | */ | |||
SGPthreadCond not_empty; | SGWaitCondition not_empty; | |||
private: | private: | |||
// Prevent copying. | // Prevent copying. | |||
SGBlockingQueue( const SGBlockingQueue& ); | SGBlockingQueue( const SGBlockingQueue& ); | |||
SGBlockingQueue& operator=( const SGBlockingQueue& ); | SGBlockingQueue& operator=( const SGBlockingQueue& ); | |||
}; | }; | |||
/** | ||||
* A guarded deque blocks threads trying to retrieve items | ||||
* when none are available. | ||||
*/ | ||||
template<class T> | ||||
class SGBlockingDeque | ||||
{ | ||||
public: | ||||
/** | ||||
* Create a new SGBlockingDequeue. | ||||
*/ | ||||
SGBlockingDeque() {} | ||||
/** | ||||
* Destroy this dequeue. | ||||
*/ | ||||
~SGBlockingDeque() {} | ||||
/** | ||||
* | ||||
*/ | ||||
virtual void clear() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
this->queue.clear(); | ||||
} | ||||
/** | ||||
* | ||||
*/ | ||||
virtual bool empty() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
return this->queue.empty(); | ||||
} | ||||
/** | ||||
* Add an item to the front of the queue. | ||||
* | ||||
* @param T object to add. | ||||
*/ | ||||
virtual void push_front( const T& item ) { | ||||
SGGuard<SGMutex> g(mutex); | ||||
this->queue.push_front( item ); | ||||
not_empty.signal(); | ||||
} | ||||
/** | ||||
* Add an item to the back of the queue. | ||||
* | ||||
* @param T object to add. | ||||
*/ | ||||
virtual void push_back( const T& item ) { | ||||
SGGuard<SGMutex> g(mutex); | ||||
this->queue.push_back( item ); | ||||
not_empty.signal(); | ||||
} | ||||
/** | ||||
* View the item from the head of the queue. | ||||
* Calling thread is not suspended | ||||
* | ||||
* @return T next available object. | ||||
*/ | ||||
virtual T front() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
assert(this->queue.empty() != true); | ||||
//if (queue.empty()) throw ?? | ||||
T item = this->queue.front(); | ||||
return item; | ||||
} | ||||
/** | ||||
* Get an item from the head of the queue. | ||||
* If no items are available then the calling thread is suspended | ||||
* | ||||
* @return T next available object. | ||||
*/ | ||||
virtual T pop_front() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
while (this->queue.empty()) | ||||
not_empty.wait(mutex); | ||||
assert(this->queue.empty() != true); | ||||
//if (queue.empty()) throw ?? | ||||
T item = this->queue.front(); | ||||
this->queue.pop_front(); | ||||
return item; | ||||
} | ||||
/** | ||||
* Get an item from the tail of the queue. | ||||
* If no items are available then the calling thread is suspended | ||||
* | ||||
* @return T next available object. | ||||
*/ | ||||
virtual T pop_back() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
while (this->queue.empty()) | ||||
not_empty.wait(mutex); | ||||
assert(this->queue.empty() != true); | ||||
//if (queue.empty()) throw ?? | ||||
T item = this->queue.back(); | ||||
this->queue.pop_back(); | ||||
return item; | ||||
} | ||||
/** | ||||
* Query the size of the queue | ||||
* | ||||
* @return size_t size of queue. | ||||
*/ | ||||
virtual size_t size() { | ||||
SGGuard<SGMutex> g(mutex); | ||||
return this->queue.size(); | ||||
} | ||||
private: | ||||
/** | ||||
* Mutex to serialise access. | ||||
*/ | ||||
SGMutex mutex; | ||||
/** | ||||
* Condition to signal when queue not empty. | ||||
*/ | ||||
SGWaitCondition not_empty; | ||||
private: | ||||
// Prevent copying. | ||||
SGBlockingDeque( const SGBlockingDeque& ); | ||||
SGBlockingDeque& operator=( const SGBlockingDeque& ); | ||||
protected: | ||||
std::deque<T> queue; | ||||
}; | ||||
#endif // SGQUEUE_HXX_INCLUDED | #endif // SGQUEUE_HXX_INCLUDED | |||
End of changes. 12 change blocks. | ||||
17 lines changed or deleted | 156 lines changed or added | |||
SGReferenced.hxx | SGReferenced.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
*/ | */ | |||
#ifndef SGReferenced_HXX | #ifndef SGReferenced_HXX | |||
#define SGReferenced_HXX | #define SGReferenced_HXX | |||
#include "SGAtomic.hxx" | ||||
/// Base class for all reference counted SimGear objects | /// Base class for all reference counted SimGear objects | |||
/// Classes derived from this one are meant to be managed with | /// Classes derived from this one are meant to be managed with | |||
/// the SGSharedPtr class. | /// the SGSharedPtr class. | |||
/// For more info see @SGSharedPtr. | /// For more info see @SGSharedPtr. | |||
class SGReferenced { | class SGReferenced { | |||
public: | public: | |||
SGReferenced(void) : _refcount(0u) | SGReferenced(void) : _refcount(0u) | |||
{} | {} | |||
/// Do not copy reference counts. Each new object has it's own counter | /// Do not copy reference counts. Each new object has it's own counter | |||
skipping to change at line 50 | skipping to change at line 52 | |||
static unsigned get(const SGReferenced* ref) | static unsigned get(const SGReferenced* ref) | |||
{ if (ref) return ++(ref->_refcount); else return ~0u; } | { if (ref) return ++(ref->_refcount); else return ~0u; } | |||
static unsigned put(const SGReferenced* ref) | static unsigned put(const SGReferenced* ref) | |||
{ if (ref) return --(ref->_refcount); else return ~0u; } | { if (ref) return --(ref->_refcount); else return ~0u; } | |||
static unsigned count(const SGReferenced* ref) | static unsigned count(const SGReferenced* ref) | |||
{ if (ref) return ref->_refcount; else return ~0u; } | { if (ref) return ref->_refcount; else return ~0u; } | |||
static bool shared(const SGReferenced* ref) | static bool shared(const SGReferenced* ref) | |||
{ if (ref) return 1u < ref->_refcount; else return false; } | { if (ref) return 1u < ref->_refcount; else return false; } | |||
private: | private: | |||
mutable unsigned _refcount; | mutable SGAtomic _refcount; | |||
}; | }; | |||
#endif | #endif | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 3 lines changed or added | |||
SGSharedPtr.hxx | SGSharedPtr.hxx | |||
---|---|---|---|---|
/* -*-c++-*- | /* -*-c++-*- | |||
* | * | |||
* Copyright (C) 2005-2006 Mathias Froehlich | * Copyright (C) 2005-2012 Mathias Froehlich | |||
* | * | |||
* This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | * modify it under the terms of the GNU General Public License as | |||
* published by the Free Software Foundation; either version 2 of the | * published by the Free Software Foundation; either version 2 of the | |||
* License, or (at your option) any later version. | * License, or (at your option) any later version. | |||
* | * | |||
* This program is distributed in the hope that it will be useful, but | * This program is distributed in the hope that it will be useful, but | |||
* WITHOUT ANY WARRANTY; without even the implied warranty of | * WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* General Public License for more details. | * General Public License for more details. | |||
skipping to change at line 40 | skipping to change at line 40 | |||
/// Classes derived from @SGReferenced can be handled with SGSharedPtr. | /// Classes derived from @SGReferenced can be handled with SGSharedPtr. | |||
/// Once you have a SGSharedPtr available you can use it just like | /// Once you have a SGSharedPtr available you can use it just like | |||
/// a usual pointer with the exception that you don't need to delete it. | /// a usual pointer with the exception that you don't need to delete it. | |||
/// Such a reference is initialized by zero if not initialized with a | /// Such a reference is initialized by zero if not initialized with a | |||
/// class pointer. | /// class pointer. | |||
/// One thing you need to avoid are cyclic loops with such pointers. | /// One thing you need to avoid are cyclic loops with such pointers. | |||
/// As long as such a cyclic loop exists the reference count never drops | /// As long as such a cyclic loop exists the reference count never drops | |||
/// to zero and consequently the objects will never be destroyed. | /// to zero and consequently the objects will never be destroyed. | |||
/// Always try to use directed graphs where the references away from the | /// Always try to use directed graphs where the references away from the | |||
/// top node are made with SGSharedPtr's and the back references are done w ith | /// top node are made with SGSharedPtr's and the back references are done w ith | |||
/// ordinary pointers. | /// ordinary pointers or SGWeakPtr's. | |||
/// There is a very good description of OpenSceneGraphs ref_ptr which is | /// There is a very good description of OpenSceneGraphs ref_ptr which is | |||
/// pretty much the same than this one at | /// pretty much the same than this one at | |||
/// http://dburns.dhs.org/OSG/Articles/RefPointers/RefPointers.html | /// http://dburns.dhs.org/OSG/Articles/RefPointers/RefPointers.html | |||
template<typename T> | template<typename T> | |||
class SGWeakPtr; | ||||
template<typename T> | ||||
class SGSharedPtr { | class SGSharedPtr { | |||
public: | public: | |||
typedef T element_type; | ||||
SGSharedPtr(void) : _ptr(0) | SGSharedPtr(void) : _ptr(0) | |||
{} | {} | |||
SGSharedPtr(T* ptr) : _ptr(ptr) | SGSharedPtr(T* ptr) : _ptr(ptr) | |||
{ get(_ptr); } | { get(_ptr); } | |||
SGSharedPtr(const SGSharedPtr& p) : _ptr(p.ptr()) | SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) | |||
{ get(_ptr); } | { get(_ptr); } | |||
template<typename U> | template<typename U> | |||
SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.ptr()) | SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get()) | |||
{ get(_ptr); } | { get(_ptr); } | |||
~SGSharedPtr(void) | ~SGSharedPtr(void) | |||
{ put(); } | { put(); } | |||
SGSharedPtr& operator=(const SGSharedPtr& p) | SGSharedPtr& operator=(const SGSharedPtr& p) | |||
{ assign(p.ptr()); return *this; } | { assign(p.get()); return *this; } | |||
template<typename U> | template<typename U> | |||
SGSharedPtr& operator=(const SGSharedPtr<U>& p) | SGSharedPtr& operator=(const SGSharedPtr<U>& p) | |||
{ assign(p.ptr()); return *this; } | { assign(p.get()); return *this; } | |||
template<typename U> | template<typename U> | |||
SGSharedPtr& operator=(U* p) | SGSharedPtr& operator=(U* p) | |||
{ assign(p); return *this; } | { assign(p); return *this; } | |||
T* operator->(void) const | T* operator->(void) const | |||
{ return _ptr; } | { return _ptr; } | |||
T& operator*(void) const | T& operator*(void) const | |||
{ return *_ptr; } | { return *_ptr; } | |||
operator T*(void) const | operator T*(void) const | |||
{ return _ptr; } | { return _ptr; } | |||
T* ptr(void) const | T* ptr(void) const | |||
{ return _ptr; } | { return _ptr; } | |||
T* get(void) const | ||||
{ return _ptr; } | ||||
T* release() | ||||
{ T* tmp = _ptr; _ptr = 0; T::put(tmp); return tmp; } | ||||
bool isShared(void) const | bool isShared(void) const | |||
{ return SGReferenced::shared(_ptr); } | { return T::shared(_ptr); } | |||
unsigned getNumRefs(void) const | unsigned getNumRefs(void) const | |||
{ return SGReferenced::count(_ptr); } | { return T::count(_ptr); } | |||
bool valid(void) const | bool valid(void) const | |||
{ return _ptr; } | { return _ptr != (T*)0; } | |||
void clear() | ||||
{ put(); } | ||||
void swap(SGSharedPtr& sharedPtr) | ||||
{ T* tmp = _ptr; _ptr = sharedPtr._ptr; sharedPtr._ptr = tmp; } | ||||
private: | private: | |||
void assign(T* p) | void assign(T* p) | |||
{ get(p); put(); _ptr = p; } | { get(p); put(); _ptr = p; } | |||
void assignNonRef(T* p) | ||||
{ put(); _ptr = p; } | ||||
void get(const T* p) const | void get(const T* p) const | |||
{ SGReferenced::get(p); } | { T::get(p); } | |||
void put(void) | void put(void) | |||
{ if (!SGReferenced::put(_ptr)) { delete _ptr; _ptr = 0; } } | { if (!T::put(_ptr)) delete _ptr; _ptr = 0; } | |||
// The reference itself. | // The reference itself. | |||
T* _ptr; | T* _ptr; | |||
template<typename U> | ||||
friend class SGWeakPtr; | ||||
}; | }; | |||
/** | ||||
* Support for boost::mem_fn | ||||
*/ | ||||
template<typename T> | ||||
T* get_pointer(SGSharedPtr<T> const & p) | ||||
{ | ||||
return p.ptr(); | ||||
} | ||||
/** | ||||
* static_cast for SGSharedPtr | ||||
*/ | ||||
template<class T, class U> | ||||
SGSharedPtr<T> static_pointer_cast(SGSharedPtr<U> const & r) | ||||
{ | ||||
return SGSharedPtr<T>( static_cast<T*>(r.get()) ); | ||||
} | ||||
/** | ||||
* Compare two SGSharedPtr<T> objects for equality. | ||||
* | ||||
* @note Only pointer values are compared, not the actual objects they are | ||||
* pointing at. | ||||
*/ | ||||
template<class T, class U> | ||||
bool operator==(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs) | ||||
{ | ||||
return lhs.get() == rhs.get(); | ||||
} | ||||
/** | ||||
* Compare two SGSharedPtr<T> objects for equality. | ||||
* | ||||
* @note Only pointer values are compared, not the actual objects they are | ||||
* pointing at. | ||||
*/ | ||||
template<class T, class U> | ||||
bool operator!=(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs) | ||||
{ | ||||
return lhs.get() != rhs.get(); | ||||
} | ||||
/** | ||||
* Compare two SGSharedPtr<T> objects for weak ordering. | ||||
* | ||||
* @note Only pointer values are compared, not the actual objects they are | ||||
* pointing at. | ||||
* @note This allows using SGSharedPtr as key in associative containers lik | ||||
e for | ||||
* example std::map and std::set. | ||||
*/ | ||||
template<class T, class U> | ||||
bool operator<(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs) | ||||
{ | ||||
return lhs.get() < rhs.get(); | ||||
} | ||||
#endif | #endif | |||
End of changes. 17 change blocks. | ||||
11 lines changed or deleted | 86 lines changed or added | |||
SGSmplhist.hxx | SGSmplhist.hxx | |||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
This file is part of the GNU C++ Library. This library is free | This file is part of the GNU C++ Library. This library is free | |||
software; you can redistribute it and/or modify it under the terms of | software; you can redistribute it and/or modify it under the terms of | |||
the GNU Library General Public License as published by the Free | the GNU Library General Public License as published by the Free | |||
Software Foundation; either version 2 of the License, or (at your | Software Foundation; either version 2 of the License, or (at your | |||
option) any later version. This library is distributed in the hope | option) any later version. This library is distributed in the hope | |||
that it will be useful, but WITHOUT ANY WARRANTY; without even the | that it will be useful, but WITHOUT ANY WARRANTY; without even the | |||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |||
PURPOSE. See the GNU Library General Public License for more details. | PURPOSE. See the GNU Library General Public License for more details. | |||
You should have received a copy of the GNU Library General Public | You should have received a copy of the GNU Library General Public | |||
License along with this library; if not, write to the Free Software | License along with this library; if not, write to the Free Software | |||
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | */ | |||
#ifdef HAVE_CONFIG_H | ||||
#include <simgear_config.h> | ||||
#endif | ||||
#ifndef SampleHistogram_h | #ifndef SampleHistogram_h | |||
#ifdef __GNUG__ | ||||
#pragma interface | ||||
#endif | ||||
#define SampleHistogram_h 1 | #define SampleHistogram_h 1 | |||
#include <iostream> | #include <iosfwd> | |||
#include <fstream> | ||||
#include "SGSmplstat.hxx" | #include "SGSmplstat.hxx" | |||
using namespace std; | ||||
extern const int SampleHistogramMinimum; | extern const int SampleHistogramMinimum; | |||
extern const int SampleHistogramMaximum; | extern const int SampleHistogramMaximum; | |||
class SampleHistogram:public SampleStatistic | class SampleHistogram:public SampleStatistic | |||
{ | { | |||
protected: | protected: | |||
short howManyBuckets; | short howManyBuckets; | |||
int *bucketCount; | int *bucketCount; | |||
double *bucketLimit; | double *bucketLimit; | |||
skipping to change at line 59 | skipping to change at line 50 | |||
virtual void reset (); | virtual void reset (); | |||
virtual void operator += (double); | virtual void operator += (double); | |||
int similarSamples (double); | int similarSamples (double); | |||
int buckets (); | int buckets (); | |||
double bucketThreshold (int i); | double bucketThreshold (int i); | |||
int inBucket (int i); | int inBucket (int i); | |||
void printBuckets (ostream &); | void printBuckets (std::ostream &); | |||
}; | }; | |||
inline int SampleHistogram::buckets () | inline int SampleHistogram::buckets () | |||
{ | { | |||
return (howManyBuckets); | return (howManyBuckets); | |||
}; | } | |||
inline double SampleHistogram::bucketThreshold (int i) | inline double SampleHistogram::bucketThreshold (int i) | |||
{ | { | |||
if (i < 0 || i >= howManyBuckets) | if (i < 0 || i >= howManyBuckets) | |||
error ("invalid bucket access"); | error ("invalid bucket access"); | |||
return (bucketLimit[i]); | return (bucketLimit[i]); | |||
} | } | |||
inline int SampleHistogram::inBucket (int i) | inline int SampleHistogram::inBucket (int i) | |||
{ | { | |||
End of changes. 7 change blocks. | ||||
13 lines changed or deleted | 4 lines changed or added | |||
SGSmplstat.hxx | SGSmplstat.hxx | |||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
This file is part of the GNU C++ Library. This library is free | This file is part of the GNU C++ Library. This library is free | |||
software; you can redistribute it and/or modify it under the terms of | software; you can redistribute it and/or modify it under the terms of | |||
the GNU Library General Public License as published by the Free | the GNU Library General Public License as published by the Free | |||
Software Foundation; either version 2 of the License, or (at your | Software Foundation; either version 2 of the License, or (at your | |||
option) any later version. This library is distributed in the hope | option) any later version. This library is distributed in the hope | |||
that it will be useful, but WITHOUT ANY WARRANTY; without even the | that it will be useful, but WITHOUT ANY WARRANTY; without even the | |||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |||
PURPOSE. See the GNU Library General Public License for more details. | PURPOSE. See the GNU Library General Public License for more details. | |||
You should have received a copy of the GNU Library General Public | You should have received a copy of the GNU Library General Public | |||
License along with this library; if not, write to the Free Software | License along with this library; if not, write to the Free Software | |||
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | */ | |||
#ifndef SampleStatistic_h | #ifndef SampleStatistic_h | |||
#ifdef __GNUG__ | ||||
#pragma interface | ||||
#endif | ||||
#define SampleStatistic_h 1 | #define SampleStatistic_h 1 | |||
#undef min | #undef min | |||
#undef max | #undef max | |||
using namespace std; | ||||
class SampleStatistic | class SampleStatistic | |||
{ | { | |||
protected: | protected: | |||
int n; | int n; | |||
double x; | double x; | |||
double x2; | double x2; | |||
double minValue, maxValue; | double minValue, maxValue; | |||
double totalTime, cumulativeTime; | ||||
public: SampleStatistic (); | public: | |||
SampleStatistic (); | ||||
inline virtual ~ SampleStatistic (); | inline virtual ~ SampleStatistic (); | |||
virtual void reset (); | virtual void reset (); | |||
virtual void operator += (double); | virtual void operator += (double); | |||
int samples () const; | int samples () const; | |||
double mean () const; | double mean () const; | |||
double stdDev () const; | double stdDev () const; | |||
double var () const; | double var () const; | |||
double min () const; | double min () const; | |||
double max () const; | double max () const; | |||
double total () const; | ||||
double cumulative () const; | ||||
double confidence (int p_percentage) const; | double confidence (int p_percentage) const; | |||
double confidence (double p_value) const; | double confidence (double p_value) const; | |||
void error (const char *msg); | void error (const char *msg); | |||
}; | }; | |||
// error handlers | ||||
//extern void default_SampleStatistic_error_handler (const char *); | ||||
//extern one_arg_error_handler_t SampleStatistic_error_handler; | ||||
//extern one_arg_error_handler_t | ||||
//set_SampleStatistic_error_handler (one_arg_error_handler_t f); | ||||
inline SampleStatistic::SampleStatistic () | inline SampleStatistic::SampleStatistic () | |||
{ | { | |||
cumulativeTime = 0; | ||||
reset (); | reset (); | |||
} | } | |||
inline int SampleStatistic::samples () const | inline int SampleStatistic::samples () const | |||
{ | { | |||
return (n); | return (n); | |||
} | } | |||
inline double SampleStatistic::min () const | inline double SampleStatistic::min () const | |||
{ | { | |||
return (minValue); | return (minValue); | |||
} | } | |||
inline double SampleStatistic::max () const | inline double SampleStatistic::max () const | |||
{ | { | |||
return (maxValue); | return (maxValue); | |||
} | } | |||
inline double SampleStatistic::total () const | ||||
{ | ||||
return (totalTime); | ||||
} | ||||
inline double SampleStatistic::cumulative () const | ||||
{ | ||||
return (cumulativeTime); | ||||
} | ||||
inline SampleStatistic::~SampleStatistic () | inline SampleStatistic::~SampleStatistic () | |||
{ | { | |||
} | } | |||
#endif | #endif | |||
End of changes. 12 change blocks. | ||||
15 lines changed or deleted | 21 lines changed or added | |||
SGThread.hxx | SGThread.hxx | |||
---|---|---|---|---|
// SGThread - Simple pthread class wrappers. | // SGThread - Simple pthread class wrappers. | |||
// | // | |||
// Written by Bernie Bright, started April 2001. | // Written by Bernie Bright, started April 2001. | |||
// | // | |||
// Copyright (C) 2001 Bernard Bright - bbright@bigpond.net.au | // Copyright (C) 2001 Bernard Bright - bbright@bigpond.net.au | |||
// Copyright (C) 2011 Mathias Froehlich | ||||
// | // | |||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License as | // modify it under the terms of the GNU General Public License as | |||
// published by the Free Software Foundation; either version 2 of the | // published by the Free Software Foundation; either version 2 of the | |||
// License, or (at your option) any later version. | // License, or (at your option) any later version. | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: SGThread.hxx,v 1.7 2006-03-08 18:16:10 mfranz Exp $ | ||||
#ifndef SGTHREAD_HXX_INCLUDED | #ifndef SGTHREAD_HXX_INCLUDED | |||
#define SGTHREAD_HXX_INCLUDED 1 | #define SGTHREAD_HXX_INCLUDED 1 | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <pthread.h> | ||||
#if defined ( SG_HAVE_STD_INCLUDES ) | ||||
# include <cassert> | ||||
# include <cerrno> | ||||
#else | ||||
# include <assert.h> | ||||
# include <sys/errno.h> | ||||
#endif | ||||
class SGThread; | ||||
extern "C" { | ||||
void* start_handler( void* ); | ||||
}; | ||||
/** | /** | |||
* Encapsulate generic threading methods. | * Encapsulate generic threading methods. | |||
* Users derive a class from SGThread and implement the run() member functi on. | * Users derive a class from SGThread and implement the run() member functi on. | |||
*/ | */ | |||
class SGThread | class SGThread { | |||
{ | ||||
public: | ||||
/** | ||||
* SGThread cancelation modes. | ||||
*/ | ||||
enum cancel_t | ||||
{ | ||||
CANCEL_DISABLE = 0, | ||||
CANCEL_DEFERRED, | ||||
CANCEL_IMMEDIATE | ||||
}; | ||||
public: | public: | |||
/** | /** | |||
* Create a new thread object. | * Create a new thread object. | |||
* When a SGThread object is created it does not begin execution | * When a SGThread object is created it does not begin execution | |||
* immediately. It is started by calling the start() member function. | * immediately. It is started by calling the start() member function. | |||
*/ | */ | |||
SGThread(); | SGThread(); | |||
/** | /** | |||
* Start the underlying thread of execution. | * Start the underlying thread of execution. | |||
* @param cpu An optional parameter to specify on which CPU to run this | ||||
* thread (only supported on IRIX at this time). | ||||
* @return Pthread error code if execution fails, otherwise returns 0. | * @return Pthread error code if execution fails, otherwise returns 0. | |||
*/ | */ | |||
int start( unsigned cpu = 0 ); | bool start(); | |||
/** | ||||
* Sends a cancellation request to the underlying thread. The target | ||||
* thread will either ignore the request, honor it immediately or defer | ||||
* it until it reaches a cancellation point. | ||||
*/ | ||||
void cancel(); | ||||
/** | /** | |||
* Suspends the exection of the calling thread until this thread | * Suspends the exection of the calling thread until this thread | |||
* terminates. | * terminates. | |||
*/ | */ | |||
void join(); | void join(); | |||
/** | ||||
*Retreive the current thread id. | ||||
*/ | ||||
static long current( void ); | ||||
protected: | protected: | |||
/** | /** | |||
* Destroy a thread object. | * Destroy a thread object. | |||
* This is protected so that its illegal to simply delete a thread | * This is protected so that its illegal to simply delete a thread | |||
* - it must return from its run() function. | * - it must return from its run() function. | |||
*/ | */ | |||
virtual ~SGThread(); | virtual ~SGThread(); | |||
/** | /** | |||
* Set the threads cancellation mode. | ||||
* @param mode The required cancellation mode. | ||||
*/ | ||||
void set_cancel( cancel_t mode ); | ||||
/** | ||||
* All threads execute by deriving the run() method of SGThread. | * All threads execute by deriving the run() method of SGThread. | |||
* If this function terminates then the thread also terminates. | * If this function terminates then the thread also terminates. | |||
*/ | */ | |||
virtual void run() = 0; | virtual void run() = 0; | |||
private: | private: | |||
// Disable copying. | ||||
SGThread(const SGThread&); | ||||
SGThread& operator=(const SGThread&); | ||||
/** | struct PrivateData; | |||
* Pthread thread identifier. | PrivateData* _privateData; | |||
*/ | ||||
pthread_t tid; | ||||
friend void* start_handler( void* ); | ||||
private: | friend struct PrivateData; | |||
// Disable copying. | ||||
SGThread( const SGThread& ); | ||||
SGThread& operator=( const SGThread& ); | ||||
}; | }; | |||
inline | class SGWaitCondition; | |||
SGThread::SGThread() | ||||
{ | ||||
} | ||||
inline | ||||
SGThread::~SGThread() | ||||
{ | ||||
} | ||||
inline int | ||||
SGThread::start( unsigned cpu ) | ||||
{ | ||||
int status = pthread_create( &tid, 0, start_handler, this ); | ||||
assert( status == 0 ); | ||||
#if defined( sgi ) | ||||
if ( !status && !cpu ) | ||||
pthread_setrunon_np( cpu ); | ||||
#endif | ||||
return status; | ||||
} | ||||
inline void | ||||
SGThread::join() | ||||
{ | ||||
int status = pthread_join( tid, 0 ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void | ||||
SGThread::cancel() | ||||
{ | ||||
int status = pthread_cancel( tid ); | ||||
assert( status == 0 ); | ||||
} | ||||
/** | /** | |||
* A mutex is used to protect a section of code such that at any time | * A mutex is used to protect a section of code such that at any time | |||
* only a single thread can execute the code. | * only a single thread can execute the code. | |||
*/ | */ | |||
class SGMutex | class SGMutex { | |||
{ | ||||
friend class SGPthreadCond; | ||||
public: | public: | |||
/** | /** | |||
* Create a new mutex. | * Create a new mutex. | |||
* Under Linux this is a 'fast' mutex. | * Under Linux this is a 'fast' mutex. | |||
*/ | */ | |||
SGMutex(); | SGMutex(); | |||
/** | /** | |||
* Destroy a mutex object. | * Destroy a mutex object. | |||
* Note: it is the responsibility of the caller to ensure the mutex is | * Note: it is the responsibility of the caller to ensure the mutex is | |||
* unlocked before destruction occurs. | * unlocked before destruction occurs. | |||
skipping to change at line 191 | skipping to change at line 112 | |||
~SGMutex(); | ~SGMutex(); | |||
/** | /** | |||
* Lock this mutex. | * Lock this mutex. | |||
* If the mutex is currently unlocked, it becomes locked and owned by | * If the mutex is currently unlocked, it becomes locked and owned by | |||
* the calling thread. If the mutex is already locked by another threa d, | * the calling thread. If the mutex is already locked by another threa d, | |||
* the calling thread is suspended until the mutex is unlocked. If the | * the calling thread is suspended until the mutex is unlocked. If the | |||
* mutex is already locked and owned by the calling thread, the calling | * mutex is already locked and owned by the calling thread, the calling | |||
* thread is suspended until the mutex is unlocked, effectively causing | * thread is suspended until the mutex is unlocked, effectively causing | |||
* the calling thread to deadlock. | * the calling thread to deadlock. | |||
* | ||||
* @see SGMutex::trylock | ||||
*/ | */ | |||
void lock(); | void lock(); | |||
/** | /** | |||
* Try to lock the mutex for the current thread. Behaves like lock exc | ||||
ept | ||||
* that it doesn't block the calling thread. | ||||
* @return true if mutex was successfully locked, otherwise false. | ||||
* @see SGMutex::lock | ||||
*/ | ||||
bool trylock(); | ||||
/** | ||||
* Unlock this mutex. | * Unlock this mutex. | |||
* It is assumed that the mutex is locked and owned by the calling thre ad. | * It is assumed that the mutex is locked and owned by the calling thre ad. | |||
*/ | */ | |||
void unlock(); | void unlock(); | |||
protected: | private: | |||
struct PrivateData; | ||||
PrivateData* _privateData; | ||||
/** | friend class SGWaitCondition; | |||
* Pthread mutex. | ||||
*/ | ||||
pthread_mutex_t mutex; | ||||
}; | }; | |||
inline SGMutex::SGMutex() | ||||
{ | ||||
int status = pthread_mutex_init( &mutex, 0 ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline SGMutex::~SGMutex() | ||||
{ | ||||
int status = pthread_mutex_destroy( &mutex ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void SGMutex::lock() | ||||
{ | ||||
int status = pthread_mutex_lock( &mutex ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void SGMutex::unlock() | ||||
{ | ||||
int status = pthread_mutex_unlock( &mutex ); | ||||
assert( status == 0 ); | ||||
} | ||||
/** | /** | |||
* A condition variable is a synchronization device that allows threads to | * A condition variable is a synchronization device that allows threads to | |||
* suspend execution until some predicate on shared data is satisfied. | * suspend execution until some predicate on shared data is satisfied. | |||
* A condition variable is always associated with a mutex to avoid race | * A condition variable is always associated with a mutex to avoid race | |||
* conditions. | * conditions. | |||
*/ | */ | |||
class SGPthreadCond | class SGWaitCondition { | |||
{ | ||||
public: | public: | |||
/** | /** | |||
* Create a new condition variable. | * Create a new condition variable. | |||
*/ | */ | |||
SGPthreadCond(); | SGWaitCondition(); | |||
/** | /** | |||
* Destroy the condition object. | * Destroy the condition object. | |||
*/ | */ | |||
~SGPthreadCond(); | ~SGWaitCondition(); | |||
/** | /** | |||
* Wait for this condition variable to be signaled. | * Wait for this condition variable to be signaled. | |||
* | * | |||
* @param SGMutex& reference to a locked mutex. | * @param SGMutex& reference to a locked mutex. | |||
*/ | */ | |||
void wait( SGMutex& ); | void wait(SGMutex&); | |||
/** | /** | |||
* Wait for this condition variable to be signaled for at most | * Wait for this condition variable to be signaled for at most | |||
* 'ms' milliseconds. | * 'ms' milliseconds. | |||
* | * | |||
* @param mutex reference to a locked mutex. | * @param mutex reference to a locked mutex. | |||
* @param ms milliseconds to wait for a signal. | * @param ms milliseconds to wait for a signal. | |||
* | * | |||
* @return | * @return | |||
*/ | */ | |||
bool wait( SGMutex& mutex, unsigned long ms ); | bool wait(SGMutex& mutex, unsigned msec); | |||
/** | /** | |||
* Wake one thread waiting on this condition variable. | * Wake one thread waiting on this condition variable. | |||
* Nothing happens if no threads are waiting. | * Nothing happens if no threads are waiting. | |||
* If several threads are waiting exactly one thread is restarted. It | * If several threads are waiting exactly one thread is restarted. It | |||
* is not specified which. | * is not specified which. | |||
*/ | */ | |||
void signal(); | void signal(); | |||
/** | /** | |||
* Wake all threads waiting on this condition variable. | * Wake all threads waiting on this condition variable. | |||
* Nothing happens if no threads are waiting. | * Nothing happens if no threads are waiting. | |||
*/ | */ | |||
void broadcast(); | void broadcast(); | |||
private: | private: | |||
// Disable copying. | // Disable copying. | |||
SGPthreadCond(const SGPthreadCond& ); | SGWaitCondition(const SGWaitCondition&); | |||
SGPthreadCond& operator=(const SGPthreadCond& ); | SGWaitCondition& operator=(const SGWaitCondition&); | |||
private: | struct PrivateData; | |||
PrivateData* _privateData; | ||||
/** | ||||
* The Pthread conditon variable. | ||||
*/ | ||||
pthread_cond_t cond; | ||||
}; | }; | |||
inline SGPthreadCond::SGPthreadCond() | ||||
{ | ||||
int status = pthread_cond_init( &cond, 0 ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline SGPthreadCond::~SGPthreadCond() | ||||
{ | ||||
int status = pthread_cond_destroy( &cond ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void SGPthreadCond::signal() | ||||
{ | ||||
int status = pthread_cond_signal( &cond ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void SGPthreadCond::broadcast() | ||||
{ | ||||
int status = pthread_cond_broadcast( &cond ); | ||||
assert( status == 0 ); | ||||
} | ||||
inline void SGPthreadCond::wait( SGMutex& mutex ) | ||||
{ | ||||
int status = pthread_cond_wait( &cond, &mutex.mutex ); | ||||
assert( status == 0 ); | ||||
} | ||||
#endif /* SGTHREAD_HXX_INCLUDED */ | #endif /* SGTHREAD_HXX_INCLUDED */ | |||
End of changes. 28 change blocks. | ||||
179 lines changed or deleted | 29 lines changed or added | |||
SGVec3.hxx | SGVec3.hxx | |||
---|---|---|---|---|
// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de | // Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de | |||
// | // | |||
// This library is free software; you can redistribute it and/or | // This library is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU Library General Public | // modify it under the terms of the GNU Library General Public | |||
// License as published by the Free Software Foundation; either | // License as published by the Free Software Foundation; either | |||
// version 2 of the License, or (at your option) any later version. | // version 2 of the License, or (at your option) any later version. | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
#ifndef SGVec3_H | #ifndef SGVec3_H | |||
#define SGVec3_H | #define SGVec3_H | |||
#include <iosfwd> | ||||
/// 3D Vector Class | /// 3D Vector Class | |||
template<typename T> | template<typename T> | |||
class SGVec3 { | class SGVec3 { | |||
public: | public: | |||
typedef T value_type; | typedef T value_type; | |||
#ifdef __GNUC__ | ||||
// Avoid "_data not initialized" warnings (see comment below). | ||||
# pragma GCC diagnostic ignored "-Wuninitialized" | ||||
#endif | ||||
/// Default constructor. Does not initialize at all. | /// Default constructor. Does not initialize at all. | |||
/// If you need them zero initialized, use SGVec3::zeros() | /// If you need them zero initialized, use SGVec3::zeros() | |||
SGVec3(void) | SGVec3(void) | |||
{ | { | |||
/// Initialize with nans in the debug build, that will guarantee to hav e | /// Initialize with nans in the debug build, that will guarantee to hav e | |||
/// a fast uninitialized default constructor in the release but shows u p | /// a fast uninitialized default constructor in the release but shows u p | |||
/// uninitialized values in the debug build very fast ... | /// uninitialized values in the debug build very fast ... | |||
#ifndef NDEBUG | #ifndef NDEBUG | |||
for (unsigned i = 0; i < 3; ++i) | for (unsigned i = 0; i < 3; ++i) | |||
_data[i] = SGLimits<T>::quiet_NaN(); | data()[i] = SGLimits<T>::quiet_NaN(); | |||
#endif | #endif | |||
} | } | |||
#ifdef __GNUC__ | ||||
// Restore warning settings. | ||||
# pragma GCC diagnostic warning "-Wuninitialized" | ||||
#endif | ||||
/// Constructor. Initialize by the given values | /// Constructor. Initialize by the given values | |||
SGVec3(T x, T y, T z) | SGVec3(T x, T y, T z) | |||
{ _data[0] = x; _data[1] = y; _data[2] = z; } | { data()[0] = x; data()[1] = y; data()[2] = z; } | |||
/// Constructor. Initialize by the content of a plain array, | /// Constructor. Initialize by the content of a plain array, | |||
/// make sure it has at least 3 elements | /// make sure it has at least 3 elements | |||
explicit SGVec3(const T* data) | explicit SGVec3(const T* d) | |||
{ _data[0] = data[0]; _data[1] = data[1]; _data[2] = data[2]; } | { data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; } | |||
template<typename S> | ||||
explicit SGVec3(const SGVec3<S>& d) | ||||
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; } | ||||
explicit SGVec3(const SGVec2<T>& v2, const T& v3 = 0) | ||||
{ data()[0] = v2[0]; data()[1] = v2[1]; data()[2] = v3; } | ||||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
const T& operator()(unsigned i) const | const T& operator()(unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
T& operator()(unsigned i) | T& operator()(unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
const T& operator[](unsigned i) const | const T& operator[](unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
T& operator[](unsigned i) | T& operator[](unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access the x component | /// Access the x component | |||
const T& x(void) const | const T& x(void) const | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the x component | /// Access the x component | |||
T& x(void) | T& x(void) | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the y component | /// Access the y component | |||
const T& y(void) const | const T& y(void) const | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the y component | /// Access the y component | |||
T& y(void) | T& y(void) | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the z component | /// Access the z component | |||
const T& z(void) const | const T& z(void) const | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Access the z component | /// Access the z component | |||
T& z(void) | T& z(void) | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Get the data pointer | /// Readonly raw storage interface | |||
const T* data(void) const | const T (&data(void) const)[3] | |||
{ return _data; } | { return _data; } | |||
/// Get the data pointer | /// Readonly raw storage interface | |||
T* data(void) | T (&data(void))[3] | |||
{ return _data; } | ||||
/// Readonly interface function to ssg's sgVec3/sgdVec3 | ||||
const T (&sg(void) const)[3] | ||||
{ return _data; } | ||||
/// Interface function to ssg's sgVec3/sgdVec3 | ||||
T (&sg(void))[3] | ||||
{ return _data; } | { return _data; } | |||
/// Inplace addition | /// Inplace addition | |||
SGVec3& operator+=(const SGVec3& v) | SGVec3& operator+=(const SGVec3& v) | |||
{ _data[0] += v(0); _data[1] += v(1); _data[2] += v(2); return *this; } | { data()[0] += v(0); data()[1] += v(1); data()[2] += v(2); return *this; } | |||
/// Inplace subtraction | /// Inplace subtraction | |||
SGVec3& operator-=(const SGVec3& v) | SGVec3& operator-=(const SGVec3& v) | |||
{ _data[0] -= v(0); _data[1] -= v(1); _data[2] -= v(2); return *this; } | { data()[0] -= v(0); data()[1] -= v(1); data()[2] -= v(2); return *this; } | |||
/// Inplace scalar multiplication | /// Inplace scalar multiplication | |||
template<typename S> | template<typename S> | |||
SGVec3& operator*=(S s) | SGVec3& operator*=(S s) | |||
{ _data[0] *= s; _data[1] *= s; _data[2] *= s; return *this; } | { data()[0] *= s; data()[1] *= s; data()[2] *= s; return *this; } | |||
/// Inplace scalar multiplication by 1/s | /// Inplace scalar multiplication by 1/s | |||
template<typename S> | template<typename S> | |||
SGVec3& operator/=(S s) | SGVec3& operator/=(S s) | |||
{ return operator*=(1/T(s)); } | { return operator*=(1/T(s)); } | |||
/// Return an all zero vector | /// Return an all zero vector | |||
static SGVec3 zeros(void) | static SGVec3 zeros(void) | |||
{ return SGVec3(0, 0, 0); } | { return SGVec3(0, 0, 0); } | |||
/// Return unit vectors | /// Return unit vectors | |||
static SGVec3 e1(void) | static SGVec3 e1(void) | |||
skipping to change at line 128 | skipping to change at line 139 | |||
{ return SGVec3(0, 0, 1); } | { return SGVec3(0, 0, 1); } | |||
/// Constructor. Initialize by a geodetic coordinate | /// Constructor. Initialize by a geodetic coordinate | |||
/// Note that this conversion is relatively expensive to compute | /// Note that this conversion is relatively expensive to compute | |||
static SGVec3 fromGeod(const SGGeod& geod); | static SGVec3 fromGeod(const SGGeod& geod); | |||
/// Constructor. Initialize by a geocentric coordinate | /// Constructor. Initialize by a geocentric coordinate | |||
/// Note that this conversion is relatively expensive to compute | /// Note that this conversion is relatively expensive to compute | |||
static SGVec3 fromGeoc(const SGGeoc& geoc); | static SGVec3 fromGeoc(const SGGeoc& geoc); | |||
private: | private: | |||
/// The actual data | ||||
T _data[3]; | T _data[3]; | |||
}; | }; | |||
template<> | template<> | |||
inline | inline | |||
SGVec3<double> | SGVec3<double> | |||
SGVec3<double>::fromGeod(const SGGeod& geod) | SGVec3<double>::fromGeod(const SGGeod& geod) | |||
{ | { | |||
SGVec3<double> cart; | SGVec3<double> cart; | |||
SGGeodesy::SGGeodToCart(geod, cart); | SGGeodesy::SGGeodToCart(geod, cart); | |||
skipping to change at line 214 | skipping to change at line 224 | |||
operator*(S s, const SGVec3<T>& v) | operator*(S s, const SGVec3<T>& v) | |||
{ return SGVec3<T>(s*v(0), s*v(1), s*v(2)); } | { return SGVec3<T>(s*v(0), s*v(1), s*v(2)); } | |||
/// Scalar multiplication | /// Scalar multiplication | |||
template<typename S, typename T> | template<typename S, typename T> | |||
inline | inline | |||
SGVec3<T> | SGVec3<T> | |||
operator*(const SGVec3<T>& v, S s) | operator*(const SGVec3<T>& v, S s) | |||
{ return SGVec3<T>(s*v(0), s*v(1), s*v(2)); } | { return SGVec3<T>(s*v(0), s*v(1), s*v(2)); } | |||
/// multiplication as a multiplicator, that is assume that the first vector | ||||
/// represents a 3x3 diagonal matrix with the diagonal elements in the vect | ||||
or. | ||||
/// Then the result is the product of that matrix times the second vector. | ||||
template<typename T> | ||||
inline | ||||
SGVec3<T> | ||||
mult(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ return SGVec3<T>(v1(0)*v2(0), v1(1)*v2(1), v1(2)*v2(2)); } | ||||
/// component wise min | ||||
template<typename T> | ||||
inline | ||||
SGVec3<T> | ||||
min(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::min(v1(0), v2(0)), | ||||
SGMisc<T>::min(v1(1), v2(1)), | ||||
SGMisc<T>::min(v1(2), v2(2))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec3<T> | ||||
min(const SGVec3<T>& v, S s) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::min(s, v(0)), | ||||
SGMisc<T>::min(s, v(1)), | ||||
SGMisc<T>::min(s, v(2))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec3<T> | ||||
min(S s, const SGVec3<T>& v) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::min(s, v(0)), | ||||
SGMisc<T>::min(s, v(1)), | ||||
SGMisc<T>::min(s, v(2))); | ||||
} | ||||
/// component wise max | ||||
template<typename T> | ||||
inline | ||||
SGVec3<T> | ||||
max(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::max(v1(0), v2(0)), | ||||
SGMisc<T>::max(v1(1), v2(1)), | ||||
SGMisc<T>::max(v1(2), v2(2))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec3<T> | ||||
max(const SGVec3<T>& v, S s) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::max(s, v(0)), | ||||
SGMisc<T>::max(s, v(1)), | ||||
SGMisc<T>::max(s, v(2))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec3<T> | ||||
max(S s, const SGVec3<T>& v) | ||||
{ | ||||
return SGVec3<T>(SGMisc<T>::max(s, v(0)), | ||||
SGMisc<T>::max(s, v(1)), | ||||
SGMisc<T>::max(s, v(2))); | ||||
} | ||||
/// Scalar dot product | /// Scalar dot product | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
dot(const SGVec3<T>& v1, const SGVec3<T>& v2) | dot(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ return v1(0)*v2(0) + v1(1)*v2(1) + v1(2)*v2(2); } | { return v1(0)*v2(0) + v1(1)*v2(1) + v1(2)*v2(2); } | |||
/// The euclidean norm of the vector, that is what most people call length | /// The euclidean norm of the vector, that is what most people call length | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
skipping to change at line 243 | skipping to change at line 320 | |||
{ return sqrt(dot(v, v)); } | { return sqrt(dot(v, v)); } | |||
/// The 1-norm of the vector, this one is the fastest length function we | /// The 1-norm of the vector, this one is the fastest length function we | |||
/// can implement on modern cpu's | /// can implement on modern cpu's | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
norm1(const SGVec3<T>& v) | norm1(const SGVec3<T>& v) | |||
{ return fabs(v(0)) + fabs(v(1)) + fabs(v(2)); } | { return fabs(v(0)) + fabs(v(1)) + fabs(v(2)); } | |||
/// The inf-norm of the vector | ||||
template<typename T> | ||||
inline | ||||
T | ||||
normI(const SGVec3<T>& v) | ||||
{ return SGMisc<T>::max(fabs(v(0)), fabs(v(1)), fabs(v(2))); } | ||||
/// Vector cross product | /// Vector cross product | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
SGVec3<T> | SGVec3<T> | |||
cross(const SGVec3<T>& v1, const SGVec3<T>& v2) | cross(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ | { | |||
return SGVec3<T>(v1(1)*v2(2) - v1(2)*v2(1), | return SGVec3<T>(v1(1)*v2(2) - v1(2)*v2(1), | |||
v1(2)*v2(0) - v1(0)*v2(2), | v1(2)*v2(0) - v1(0)*v2(2), | |||
v1(0)*v2(1) - v1(1)*v2(0)); | v1(0)*v2(1) - v1(1)*v2(0)); | |||
} | } | |||
/// The euclidean norm of the vector, that is what most people call length | /// return any normalized vector perpendicular to v | |||
template<typename T> | ||||
inline | ||||
SGVec3<T> | ||||
perpendicular(const SGVec3<T>& v) | ||||
{ | ||||
T absv1 = fabs(v(0)); | ||||
T absv2 = fabs(v(1)); | ||||
T absv3 = fabs(v(2)); | ||||
if (absv2 < absv1 && absv3 < absv1) { | ||||
T quot = v(1)/v(0); | ||||
return (1/sqrt(1+quot*quot))*SGVec3<T>(quot, -1, 0); | ||||
} else if (absv3 < absv2) { | ||||
T quot = v(2)/v(1); | ||||
return (1/sqrt(1+quot*quot))*SGVec3<T>(0, quot, -1); | ||||
} else if (SGLimits<T>::min() < absv3) { | ||||
T quot = v(0)/v(2); | ||||
return (1/sqrt(1+quot*quot))*SGVec3<T>(-1, 0, quot); | ||||
} else { | ||||
// the all zero case ... | ||||
return SGVec3<T>(0, 0, 0); | ||||
} | ||||
} | ||||
/// Construct a unit vector in the given direction. | ||||
/// or the zero vector if the input vector is zero. | ||||
template<typename T> | template<typename T> | |||
inline | inline | |||
SGVec3<T> | SGVec3<T> | |||
normalize(const SGVec3<T>& v) | normalize(const SGVec3<T>& v) | |||
{ return (1/norm(v))*v; } | { | |||
T normv = norm(v); | ||||
if (normv <= SGLimits<T>::min()) | ||||
return SGVec3<T>::zeros(); | ||||
return (1/normv)*v; | ||||
} | ||||
/// Return true if exactly the same | /// Return true if exactly the same | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
operator==(const SGVec3<T>& v1, const SGVec3<T>& v2) | operator==(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ return v1(0) == v2(0) && v1(1) == v2(1) && v1(2) == v2(2); } | { return v1(0) == v2(0) && v1(1) == v2(1) && v1(2) == v2(2); } | |||
/// Return true if not exactly the same | /// Return true if not exactly the same | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
operator!=(const SGVec3<T>& v1, const SGVec3<T>& v2) | operator!=(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ return ! (v1 == v2); } | { return ! (v1 == v2); } | |||
/// Return true if smaller, good for putting that into a std::map | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator<(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ | ||||
if (v1(0) < v2(0)) return true; | ||||
else if (v2(0) < v1(0)) return false; | ||||
else if (v1(1) < v2(1)) return true; | ||||
else if (v2(1) < v1(1)) return false; | ||||
else return (v1(2) < v2(2)); | ||||
} | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator<=(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ | ||||
if (v1(0) < v2(0)) return true; | ||||
else if (v2(0) < v1(0)) return false; | ||||
else if (v1(1) < v2(1)) return true; | ||||
else if (v2(1) < v1(1)) return false; | ||||
else return (v1(2) <= v2(2)); | ||||
} | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator>(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ return operator<(v2, v1); } | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator>=(const SGVec3<T>& v1, const SGVec3<T>& v2) | ||||
{ return operator<=(v2, v1); } | ||||
/// Return true if equal to the relative tolerance tol | /// Return true if equal to the relative tolerance tol | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
equivalent(const SGVec3<T>& v1, const SGVec3<T>& v2, T rtol, T atol) | equivalent(const SGVec3<T>& v1, const SGVec3<T>& v2, T rtol, T atol) | |||
{ return norm1(v1 - v2) < rtol*(norm1(v1) + norm1(v2)) + atol; } | { return norm1(v1 - v2) < rtol*(norm1(v1) + norm1(v2)) + atol; } | |||
/// Return true if equal to the relative tolerance tol | /// Return true if equal to the relative tolerance tol | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
skipping to change at line 313 | skipping to change at line 465 | |||
dist(const SGVec3<T>& v1, const SGVec3<T>& v2) | dist(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ return norm(v1 - v2); } | { return norm(v1 - v2); } | |||
/// The squared euclidean distance of the two vectors | /// The squared euclidean distance of the two vectors | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
distSqr(const SGVec3<T>& v1, const SGVec3<T>& v2) | distSqr(const SGVec3<T>& v1, const SGVec3<T>& v2) | |||
{ SGVec3<T> tmp = v1 - v2; return dot(tmp, tmp); } | { SGVec3<T> tmp = v1 - v2; return dot(tmp, tmp); } | |||
// calculate the projection of u along the direction of d. | ||||
template<typename T> | ||||
inline | ||||
SGVec3<T> | ||||
projection(const SGVec3<T>& u, const SGVec3<T>& d) | ||||
{ | ||||
T denom = dot(d, d); | ||||
T ud = dot(u, d); | ||||
if (SGLimits<T>::min() < denom) return u; | ||||
else return d * (dot(u, d) / denom); | ||||
} | ||||
#ifndef NDEBUG | #ifndef NDEBUG | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
isNaN(const SGVec3<T>& v) | isNaN(const SGVec3<T>& v) | |||
{ | { | |||
return SGMisc<T>::isNaN(v(0)) || | return SGMisc<T>::isNaN(v(0)) || | |||
SGMisc<T>::isNaN(v(1)) || SGMisc<T>::isNaN(v(2)); | SGMisc<T>::isNaN(v(1)) || SGMisc<T>::isNaN(v(2)); | |||
} | } | |||
#endif | #endif | |||
End of changes. 29 change blocks. | ||||
32 lines changed or deleted | 197 lines changed or added | |||
SGVec4.hxx | SGVec4.hxx | |||
---|---|---|---|---|
// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de | // Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de | |||
// | // | |||
// This library is free software; you can redistribute it and/or | // This library is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU Library General Public | // modify it under the terms of the GNU Library General Public | |||
// License as published by the Free Software Foundation; either | // License as published by the Free Software Foundation; either | |||
// version 2 of the License, or (at your option) any later version. | // version 2 of the License, or (at your option) any later version. | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
#ifndef SGVec4_H | #ifndef SGVec4_H | |||
#define SGVec4_H | #define SGVec4_H | |||
#include <iosfwd> | ||||
/// 4D Vector Class | /// 4D Vector Class | |||
template<typename T> | template<typename T> | |||
class SGVec4 { | class SGVec4 { | |||
public: | public: | |||
typedef T value_type; | typedef T value_type; | |||
/// Default constructor. Does not initialize at all. | /// Default constructor. Does not initialize at all. | |||
/// If you need them zero initialized, use SGVec4::zeros() | /// If you need them zero initialized, use SGVec4::zeros() | |||
SGVec4(void) | SGVec4(void) | |||
{ | { | |||
/// Initialize with nans in the debug build, that will guarantee to hav e | /// Initialize with nans in the debug build, that will guarantee to hav e | |||
/// a fast uninitialized default constructor in the release but shows u p | /// a fast uninitialized default constructor in the release but shows u p | |||
/// uninitialized values in the debug build very fast ... | /// uninitialized values in the debug build very fast ... | |||
#ifndef NDEBUG | #ifndef NDEBUG | |||
for (unsigned i = 0; i < 4; ++i) | for (unsigned i = 0; i < 4; ++i) | |||
_data[i] = SGLimits<T>::quiet_NaN(); | data()[i] = SGLimits<T>::quiet_NaN(); | |||
#endif | #endif | |||
} | } | |||
/// Constructor. Initialize by the given values | /// Constructor. Initialize by the given values | |||
SGVec4(T x, T y, T z, T w) | SGVec4(T x, T y, T z, T w) | |||
{ _data[0] = x; _data[1] = y; _data[2] = z; _data[3] = w; } | { data()[0] = x; data()[1] = y; data()[2] = z; data()[3] = w; } | |||
/// Constructor. Initialize by the content of a plain array, | /// Constructor. Initialize by the content of a plain array, | |||
/// make sure it has at least 3 elements | /// make sure it has at least 3 elements | |||
explicit SGVec4(const T* d) | explicit SGVec4(const T* d) | |||
{ _data[0] = d[0]; _data[1] = d[1]; _data[2] = d[2]; _data[3] = d[3]; } | { data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; | |||
} | ||||
template<typename S> | ||||
explicit SGVec4(const SGVec4<S>& d) | ||||
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; | ||||
} | ||||
explicit SGVec4(const SGVec3<T>& v3, const T& v4 = 0) | ||||
{ data()[0] = v3[0]; data()[1] = v3[1]; data()[2] = v3[2]; data()[3] = v4 | ||||
; } | ||||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
const T& operator()(unsigned i) const | const T& operator()(unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access by index, the index is unchecked | /// Access by index, the index is unchecked | |||
T& operator()(unsigned i) | T& operator()(unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
const T& operator[](unsigned i) const | const T& operator[](unsigned i) const | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access raw data by index, the index is unchecked | /// Access raw data by index, the index is unchecked | |||
T& operator[](unsigned i) | T& operator[](unsigned i) | |||
{ return _data[i]; } | { return data()[i]; } | |||
/// Access the x component | /// Access the x component | |||
const T& x(void) const | const T& x(void) const | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the x component | /// Access the x component | |||
T& x(void) | T& x(void) | |||
{ return _data[0]; } | { return data()[0]; } | |||
/// Access the y component | /// Access the y component | |||
const T& y(void) const | const T& y(void) const | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the y component | /// Access the y component | |||
T& y(void) | T& y(void) | |||
{ return _data[1]; } | { return data()[1]; } | |||
/// Access the z component | /// Access the z component | |||
const T& z(void) const | const T& z(void) const | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Access the z component | /// Access the z component | |||
T& z(void) | T& z(void) | |||
{ return _data[2]; } | { return data()[2]; } | |||
/// Access the x component | /// Access the x component | |||
const T& w(void) const | const T& w(void) const | |||
{ return _data[3]; } | { return data()[3]; } | |||
/// Access the x component | /// Access the x component | |||
T& w(void) | T& w(void) | |||
{ return _data[3]; } | { return data()[3]; } | |||
/// Get the data pointer, usefull for interfacing with plib's sg*Vec | ||||
const T* data(void) const | ||||
{ return _data; } | ||||
/// Get the data pointer, usefull for interfacing with plib's sg*Vec | ||||
T* data(void) | ||||
{ return _data; } | ||||
/// Readonly interface function to ssg's sgVec3/sgdVec3 | /// Readonly raw storage interface | |||
const T (&sg(void) const)[4] | const T (&data(void) const)[4] | |||
{ return _data; } | { return _data; } | |||
/// Interface function to ssg's sgVec3/sgdVec3 | /// Readonly raw storage interface | |||
T (&sg(void))[4] | T (&data(void))[4] | |||
{ return _data; } | { return _data; } | |||
/// Inplace addition | /// Inplace addition | |||
SGVec4& operator+=(const SGVec4& v) | SGVec4& operator+=(const SGVec4& v) | |||
{ _data[0]+=v(0);_data[1]+=v(1);_data[2]+=v(2);_data[3]+=v(3);return *thi s; } | { data()[0]+=v(0);data()[1]+=v(1);data()[2]+=v(2);data()[3]+=v(3);return *this; } | |||
/// Inplace subtraction | /// Inplace subtraction | |||
SGVec4& operator-=(const SGVec4& v) | SGVec4& operator-=(const SGVec4& v) | |||
{ _data[0]-=v(0);_data[1]-=v(1);_data[2]-=v(2);_data[3]-=v(3);return *thi s; } | { data()[0]-=v(0);data()[1]-=v(1);data()[2]-=v(2);data()[3]-=v(3);return *this; } | |||
/// Inplace scalar multiplication | /// Inplace scalar multiplication | |||
template<typename S> | template<typename S> | |||
SGVec4& operator*=(S s) | SGVec4& operator*=(S s) | |||
{ _data[0] *= s; _data[1] *= s; _data[2] *= s; _data[3] *= s; return *thi s; } | { data()[0] *= s; data()[1] *= s; data()[2] *= s; data()[3] *= s; return *this; } | |||
/// Inplace scalar multiplication by 1/s | /// Inplace scalar multiplication by 1/s | |||
template<typename S> | template<typename S> | |||
SGVec4& operator/=(S s) | SGVec4& operator/=(S s) | |||
{ return operator*=(1/T(s)); } | { return operator*=(1/T(s)); } | |||
/// Return an all zero vector | /// Return an all zero vector | |||
static SGVec4 zeros(void) | static SGVec4 zeros(void) | |||
{ return SGVec4(0, 0, 0, 0); } | { return SGVec4(0, 0, 0, 0); } | |||
/// Return unit vectors | /// Return unit vectors | |||
static SGVec4 e1(void) | static SGVec4 e1(void) | |||
{ return SGVec4(1, 0, 0, 0); } | { return SGVec4(1, 0, 0, 0); } | |||
static SGVec4 e2(void) | static SGVec4 e2(void) | |||
{ return SGVec4(0, 1, 0, 0); } | { return SGVec4(0, 1, 0, 0); } | |||
static SGVec4 e3(void) | static SGVec4 e3(void) | |||
{ return SGVec4(0, 0, 1, 0); } | { return SGVec4(0, 0, 1, 0); } | |||
static SGVec4 e4(void) | static SGVec4 e4(void) | |||
{ return SGVec4(0, 0, 0, 1); } | { return SGVec4(0, 0, 0, 1); } | |||
private: | private: | |||
/// The actual data | ||||
T _data[4]; | T _data[4]; | |||
}; | }; | |||
/// Unary +, do nothing ... | /// Unary +, do nothing ... | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
const SGVec4<T>& | const SGVec4<T>& | |||
operator+(const SGVec4<T>& v) | operator+(const SGVec4<T>& v) | |||
{ return v; } | { return v; } | |||
skipping to change at line 175 | skipping to change at line 174 | |||
operator*(S s, const SGVec4<T>& v) | operator*(S s, const SGVec4<T>& v) | |||
{ return SGVec4<T>(s*v(0), s*v(1), s*v(2), s*v(3)); } | { return SGVec4<T>(s*v(0), s*v(1), s*v(2), s*v(3)); } | |||
/// Scalar multiplication | /// Scalar multiplication | |||
template<typename S, typename T> | template<typename S, typename T> | |||
inline | inline | |||
SGVec4<T> | SGVec4<T> | |||
operator*(const SGVec4<T>& v, S s) | operator*(const SGVec4<T>& v, S s) | |||
{ return SGVec4<T>(s*v(0), s*v(1), s*v(2), s*v(3)); } | { return SGVec4<T>(s*v(0), s*v(1), s*v(2), s*v(3)); } | |||
/// multiplication as a multiplicator, that is assume that the first vector | ||||
/// represents a 4x4 diagonal matrix with the diagonal elements in the vect | ||||
or. | ||||
/// Then the result is the product of that matrix times the second vector. | ||||
template<typename T> | ||||
inline | ||||
SGVec4<T> | ||||
mult(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ return SGVec4<T>(v1(0)*v2(0), v1(1)*v2(1), v1(2)*v2(2), v1(3)*v2(3)); } | ||||
/// component wise min | ||||
template<typename T> | ||||
inline | ||||
SGVec4<T> | ||||
min(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::min(v1(0), v2(0)), | ||||
SGMisc<T>::min(v1(1), v2(1)), | ||||
SGMisc<T>::min(v1(2), v2(2)), | ||||
SGMisc<T>::min(v1(3), v2(3))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec4<T> | ||||
min(const SGVec4<T>& v, S s) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::min(s, v(0)), | ||||
SGMisc<T>::min(s, v(1)), | ||||
SGMisc<T>::min(s, v(2)), | ||||
SGMisc<T>::min(s, v(3))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec4<T> | ||||
min(S s, const SGVec4<T>& v) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::min(s, v(0)), | ||||
SGMisc<T>::min(s, v(1)), | ||||
SGMisc<T>::min(s, v(2)), | ||||
SGMisc<T>::min(s, v(3))); | ||||
} | ||||
/// component wise max | ||||
template<typename T> | ||||
inline | ||||
SGVec4<T> | ||||
max(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::max(v1(0), v2(0)), | ||||
SGMisc<T>::max(v1(1), v2(1)), | ||||
SGMisc<T>::max(v1(2), v2(2)), | ||||
SGMisc<T>::max(v1(3), v2(3))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec4<T> | ||||
max(const SGVec4<T>& v, S s) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::max(s, v(0)), | ||||
SGMisc<T>::max(s, v(1)), | ||||
SGMisc<T>::max(s, v(2)), | ||||
SGMisc<T>::max(s, v(3))); | ||||
} | ||||
template<typename S, typename T> | ||||
inline | ||||
SGVec4<T> | ||||
max(S s, const SGVec4<T>& v) | ||||
{ | ||||
return SGVec4<T>(SGMisc<T>::max(s, v(0)), | ||||
SGMisc<T>::max(s, v(1)), | ||||
SGMisc<T>::max(s, v(2)), | ||||
SGMisc<T>::max(s, v(3))); | ||||
} | ||||
/// Scalar dot product | /// Scalar dot product | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
dot(const SGVec4<T>& v1, const SGVec4<T>& v2) | dot(const SGVec4<T>& v1, const SGVec4<T>& v2) | |||
{ return v1(0)*v2(0) + v1(1)*v2(1) + v1(2)*v2(2) + v1(3)*v2(3); } | { return v1(0)*v2(0) + v1(1)*v2(1) + v1(2)*v2(2) + v1(3)*v2(3); } | |||
/// The euclidean norm of the vector, that is what most people call length | /// The euclidean norm of the vector, that is what most people call length | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
skipping to change at line 204 | skipping to change at line 276 | |||
{ return sqrt(dot(v, v)); } | { return sqrt(dot(v, v)); } | |||
/// The 1-norm of the vector, this one is the fastest length function we | /// The 1-norm of the vector, this one is the fastest length function we | |||
/// can implement on modern cpu's | /// can implement on modern cpu's | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
norm1(const SGVec4<T>& v) | norm1(const SGVec4<T>& v) | |||
{ return fabs(v(0)) + fabs(v(1)) + fabs(v(2)) + fabs(v(3)); } | { return fabs(v(0)) + fabs(v(1)) + fabs(v(2)) + fabs(v(3)); } | |||
/// The inf-norm of the vector | ||||
template<typename T> | ||||
inline | ||||
T | ||||
normI(const SGVec4<T>& v) | ||||
{ return SGMisc<T>::max(fabs(v(0)), fabs(v(1)), fabs(v(2)), fabs(v(2))); } | ||||
/// The euclidean norm of the vector, that is what most people call length | /// The euclidean norm of the vector, that is what most people call length | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
SGVec4<T> | SGVec4<T> | |||
normalize(const SGVec4<T>& v) | normalize(const SGVec4<T>& v) | |||
{ return (1/norm(v))*v; } | { | |||
T normv = norm(v); | ||||
if (normv <= SGLimits<T>::min()) | ||||
return SGVec4<T>::zeros(); | ||||
return (1/normv)*v; | ||||
} | ||||
/// Return true if exactly the same | /// Return true if exactly the same | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
operator==(const SGVec4<T>& v1, const SGVec4<T>& v2) | operator==(const SGVec4<T>& v1, const SGVec4<T>& v2) | |||
{ return v1(0)==v2(0) && v1(1)==v2(1) && v1(2)==v2(2) && v1(3)==v2(3); } | { return v1(0)==v2(0) && v1(1)==v2(1) && v1(2)==v2(2) && v1(3)==v2(3); } | |||
/// Return true if not exactly the same | /// Return true if not exactly the same | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
operator!=(const SGVec4<T>& v1, const SGVec4<T>& v2) | operator!=(const SGVec4<T>& v1, const SGVec4<T>& v2) | |||
{ return ! (v1 == v2); } | { return ! (v1 == v2); } | |||
/// Return true if smaller, good for putting that into a std::map | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator<(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ | ||||
if (v1(0) < v2(0)) return true; | ||||
else if (v2(0) < v1(0)) return false; | ||||
else if (v1(1) < v2(1)) return true; | ||||
else if (v2(1) < v1(1)) return false; | ||||
else if (v1(2) < v2(2)) return true; | ||||
else if (v2(2) < v1(2)) return false; | ||||
else return (v1(3) < v2(3)); | ||||
} | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator<=(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ | ||||
if (v1(0) < v2(0)) return true; | ||||
else if (v2(0) < v1(0)) return false; | ||||
else if (v1(1) < v2(1)) return true; | ||||
else if (v2(1) < v1(1)) return false; | ||||
else if (v1(2) < v2(2)) return true; | ||||
else if (v2(2) < v1(2)) return false; | ||||
else return (v1(3) <= v2(3)); | ||||
} | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator>(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ return operator<(v2, v1); } | ||||
template<typename T> | ||||
inline | ||||
bool | ||||
operator>=(const SGVec4<T>& v1, const SGVec4<T>& v2) | ||||
{ return operator<=(v2, v1); } | ||||
/// Return true if equal to the relative tolerance tol | /// Return true if equal to the relative tolerance tol | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
equivalent(const SGVec4<T>& v1, const SGVec4<T>& v2, T rtol, T atol) | equivalent(const SGVec4<T>& v1, const SGVec4<T>& v2, T rtol, T atol) | |||
{ return norm1(v1 - v2) < rtol*(norm1(v1) + norm1(v2)) + atol; } | { return norm1(v1 - v2) < rtol*(norm1(v1) + norm1(v2)) + atol; } | |||
/// Return true if equal to the relative tolerance tol | /// Return true if equal to the relative tolerance tol | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
skipping to change at line 263 | skipping to change at line 388 | |||
dist(const SGVec4<T>& v1, const SGVec4<T>& v2) | dist(const SGVec4<T>& v1, const SGVec4<T>& v2) | |||
{ return norm(v1 - v2); } | { return norm(v1 - v2); } | |||
/// The squared euclidean distance of the two vectors | /// The squared euclidean distance of the two vectors | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
T | T | |||
distSqr(const SGVec4<T>& v1, const SGVec4<T>& v2) | distSqr(const SGVec4<T>& v1, const SGVec4<T>& v2) | |||
{ SGVec4<T> tmp = v1 - v2; return dot(tmp, tmp); } | { SGVec4<T> tmp = v1 - v2; return dot(tmp, tmp); } | |||
// calculate the projection of u along the direction of d. | ||||
template<typename T> | ||||
inline | ||||
SGVec4<T> | ||||
projection(const SGVec4<T>& u, const SGVec4<T>& d) | ||||
{ | ||||
T denom = dot(d, d); | ||||
T ud = dot(u, d); | ||||
if (SGLimits<T>::min() < denom) return u; | ||||
else return d * (dot(u, d) / denom); | ||||
} | ||||
#ifndef NDEBUG | #ifndef NDEBUG | |||
template<typename T> | template<typename T> | |||
inline | inline | |||
bool | bool | |||
isNaN(const SGVec4<T>& v) | isNaN(const SGVec4<T>& v) | |||
{ | { | |||
return SGMisc<T>::isNaN(v(0)) || SGMisc<T>::isNaN(v(1)) | return SGMisc<T>::isNaN(v(0)) || SGMisc<T>::isNaN(v(1)) | |||
|| SGMisc<T>::isNaN(v(2)) || SGMisc<T>::isNaN(v(3)); | || SGMisc<T>::isNaN(v(2)) || SGMisc<T>::isNaN(v(3)); | |||
} | } | |||
#endif | #endif | |||
End of changes. 28 change blocks. | ||||
32 lines changed or deleted | 173 lines changed or added | |||
animation.hxx | animation.hxx | |||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
// | // | |||
// This file is in the Public Domain, and comes with no warranty. | // This file is in the Public Domain, and comes with no warranty. | |||
#ifndef _SG_ANIMATION_HXX | #ifndef _SG_ANIMATION_HXX | |||
#define _SG_ANIMATION_HXX 1 | #define _SG_ANIMATION_HXX 1 | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <vector> | #include <osg/ref_ptr> | |||
#include <map> | #include <osg/Group> | |||
#include <osg/Node> | ||||
#include <osg/NodeVisitor> | ||||
#include <osg/Texture2D> | ||||
#include <osgDB/ReaderWriter> | ||||
#include <plib/sg.h> | #include <simgear/scene/util/SGNodeMasks.hxx> | |||
#include <plib/ssg.h> | ||||
#include <simgear/math/point3d.hxx> | ||||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <simgear/misc/sg_path.hxx> | #include <simgear/props/condition.hxx> | |||
#include <simgear/structure/ssgSharedPtr.hxx> | #include <simgear/structure/SGExpression.hxx> | |||
#include <simgear/scene/model/persparam.hxx> | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(map); | ||||
// Don't pull in the headers, since we don't need them here. | ||||
class SGInterpTable; | ||||
class SGCondition; | ||||
class SGPersonalityBranch; | ||||
// Has anyone done anything *really* stupid, like making min and max macros ? | // Has anyone done anything *really* stupid, like making min and max macros ? | |||
#ifdef min | #ifdef min | |||
#undef min | #undef min | |||
#endif | #endif | |||
#ifdef max | #ifdef max | |||
#undef max | #undef max | |||
#endif | #endif | |||
////////////////////////////////////////////////////////////////////// | ||||
// Animation classes | SGExpressiond* | |||
////////////////////////////////////////////////////////////////////// | read_value(const SGPropertyNode* configNode, SGPropertyNode* modelRoot, | |||
const char* unit, double defMin, double defMax); | ||||
SGVec3d readTranslateAxis(const SGPropertyNode* configNode); | ||||
/** | /** | |||
* Abstract base class for all animations. | * Base class for animation installers | |||
*/ | */ | |||
class SGAnimation : public ssgBase | class SGAnimation : protected osg::NodeVisitor { | |||
{ | ||||
public: | public: | |||
enum PersonalityVar { INIT_SPIN, LAST_TIME_SEC_SPIN, FACTOR_SPIN, | SGAnimation(const SGPropertyNode* configNode, SGPropertyNode* modelRoot); | |||
POSITION_DEG_SPIN, | virtual ~SGAnimation(); | |||
INIT_TIMED, LAST_TIME_SEC_TIMED, TOTAL_DURATION_SEC | ||||
_TIMED, | ||||
BRANCH_DURATION_SEC_TIMED, STEP_TIMED, | ||||
INIT_TRANSLATE, FACTOR_TRANSLATE, OFFSET_TRANSLATE, | ||||
INIT_BLEND, FACTOR_BLEND, OFFSET_BLEND, | ||||
INIT_SCALE, X_FACTOR_SCALE, Y_FACTOR_SCALE, Z_FACTO | ||||
R_SCALE, | ||||
X_OFFSET_SCALE, Y_OFFSET_SCALE, Z_OFFSET_SCALE | ||||
}; | ||||
SGAnimation (SGPropertyNode_ptr props, ssgBranch * branch); | static bool animate(osg::Node* node, const SGPropertyNode* configNode, | |||
SGPropertyNode* modelRoot, | ||||
const osgDB::Options* options, | ||||
const std::string &path, int i); | ||||
virtual ~SGAnimation (); | protected: | |||
void apply(osg::Node* node); | ||||
/** | ||||
* Get the SSG branch holding the animation. | ||||
*/ | ||||
virtual ssgBranch * getBranch () { return _branch; } | ||||
/** | ||||
* Initialize the animation, after children have been added. | ||||
*/ | ||||
virtual void init (); | ||||
/** | ||||
* Update the animation. | ||||
*/ | ||||
virtual int update(); | ||||
/** | virtual void install(osg::Node& node); | |||
* Restore the state after the animation. | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
*/ | ||||
virtual void restore(); | ||||
/** | virtual void apply(osg::Group& group); | |||
* Set the value of sim_time_sec. This needs to be called every | ||||
* frame in order for the time based animations to work correctly. | ||||
*/ | ||||
static void set_sim_time_sec( double val ) { sim_time_sec = val; } | ||||
/** | /** | |||
* Current personality branch : enable animation to behave differently | * Read a 3d vector from the configuration property node. | |||
* for similar objects | * | |||
* Reads values from @a name/[xyz]@a prefix and defaults to the according | ||||
* value of @a def for each value which is not set. | ||||
* | ||||
* @param name Name of the root node containing all coordinates | ||||
* @param suffix Suffix appended to each child node (x,y,z) | ||||
* @param def Vector containing default values | ||||
*/ | */ | |||
static SGPersonalityBranch *current_object; | SGVec3d readVec3( const std::string& name, | |||
const std::string& suffix = "", | ||||
const SGVec3d& def = SGVec3d::zeros() ) const; | ||||
void readRotationCenterAndAxis(SGVec3d& center, SGVec3d& axis) const; | ||||
SGExpressiond* readOffsetValue(const char* tag_name) const; | ||||
void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode); | ||||
void removeAttribute(osg::Node& node, osg::StateAttribute::Type type); | ||||
void removeTextureMode(osg::Node& node, unsigned unit, | ||||
osg::StateAttribute::GLMode mode); | ||||
void removeTextureAttribute(osg::Node& node, unsigned unit, | ||||
osg::StateAttribute::Type type); | ||||
void setRenderBinToInherit(osg::Node& node); | ||||
void cloneDrawables(osg::Node& node); | ||||
std::string getType() const | ||||
{ return std::string(_configNode->getStringValue("type", "")); } | ||||
const SGPropertyNode* getConfig() const | ||||
{ return _configNode; } | ||||
SGPropertyNode* getModelRoot() const | ||||
{ return _modelRoot; } | ||||
const SGCondition* getCondition() const; | ||||
std::list<std::string> _objectNames; | ||||
private: | ||||
void installInGroup(const std::string& name, osg::Group& group, | ||||
osg::ref_ptr<osg::Group>& animationGroup); | ||||
class RemoveModeVisitor; | ||||
class RemoveAttributeVisitor; | ||||
class RemoveTextureModeVisitor; | ||||
class RemoveTextureAttributeVisitor; | ||||
class BinToInheritVisitor; | ||||
class DrawableCloneVisitor; | ||||
bool _found; | ||||
std::string _name; | ||||
SGSharedPtr<SGPropertyNode const> _configNode; | ||||
SGPropertyNode* _modelRoot; | ||||
int get_animation_type(void) { return animation_type; } | std::list<osg::ref_ptr<osg::Node> > _installedAnimations; | |||
bool _enableHOT; | ||||
protected: | ||||
static double sim_time_sec; | ||||
ssgBranch * _branch; | ||||
int animation_type; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* A no-op animation. | // Null animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGNullAnimation : public SGAnimation | ||||
{ | ||||
public: | ||||
SGNullAnimation (SGPropertyNode_ptr props); | ||||
virtual ~SGNullAnimation (); | ||||
}; | ||||
/** | class SGGroupAnimation : public SGAnimation { | |||
* A range, or level-of-detail (LOD) animation. | ||||
*/ | ||||
class SGRangeAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGRangeAnimation (SGPropertyNode *prop_root, | SGGroupAnimation(const SGPropertyNode*, SGPropertyNode*); | |||
SGPropertyNode_ptr props); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual ~SGRangeAnimation (); | ||||
virtual int update(); | ||||
private: | ||||
SGPropertyNode_ptr _min_prop; | ||||
SGPropertyNode_ptr _max_prop; | ||||
float _min; | ||||
float _max; | ||||
float _min_factor; | ||||
float _max_factor; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to turn and face the screen. | // Translate animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGBillboardAnimation : public SGAnimation | ||||
{ | ||||
public: | ||||
SGBillboardAnimation (SGPropertyNode_ptr props); | ||||
virtual ~SGBillboardAnimation (); | ||||
}; | ||||
/** | class SGTranslateAnimation : public SGAnimation { | |||
* Animation to select alternative versions of the same object. | ||||
*/ | ||||
class SGSelectAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGSelectAnimation( SGPropertyNode *prop_root, | SGTranslateAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot); | |||
virtual ~SGSelectAnimation (); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | private: | |||
private: | class UpdateCallback; | |||
SGCondition * _condition; | SGSharedPtr<const SGCondition> _condition; | |||
SGSharedPtr<const SGExpressiond> _animationValue; | ||||
SGVec3d _axis; | ||||
double _initialValue; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to spin an object around a center point. | // Rotate/Spin animation installer | |||
* | ////////////////////////////////////////////////////////////////////// | |||
* This animation rotates at a specific velocity. | ||||
*/ | class SGRotateAnimation : public SGAnimation { | |||
class SGSpinAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGSpinAnimation( SGPropertyNode *prop_root, | SGRotateAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props, | SGPropertyNode* modelRoot); | |||
double sim_time_sec ); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual ~SGSpinAnimation (); | private: | |||
virtual int update(); | SGSharedPtr<const SGCondition> _condition; | |||
private: | SGSharedPtr<const SGExpressiond> _animationValue; | |||
bool _use_personality; | SGVec3d _axis; | |||
SGPropertyNode_ptr _prop; | SGVec3d _center; | |||
SGPersonalityParameter<double> _factor; | double _initialValue; | |||
SGPersonalityParameter<double> _position_deg; | bool _isSpin; | |||
double _last_time_sec; | ||||
sgMat4 _matrix; | ||||
sgVec3 _center; | ||||
sgVec3 _axis; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to draw objects for a specific amount of time each. | // Scale animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGTimedAnimation : public SGAnimation | ||||
{ | class SGScaleAnimation : public SGAnimation { | |||
public: | public: | |||
SGTimedAnimation (SGPropertyNode_ptr props); | SGScaleAnimation(const SGPropertyNode* configNode, | |||
virtual ~SGTimedAnimation (); | SGPropertyNode* modelRoot); | |||
virtual void init(); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | private: | |||
private: | class UpdateCallback; | |||
bool _use_personality; | SGSharedPtr<const SGCondition> _condition; | |||
double _duration_sec; | SGSharedPtr<const SGExpressiond> _animationValue[3]; | |||
double _last_time_sec; | SGVec3d _initialValue; | |||
double _total_duration_sec; | SGVec3d _center; | |||
int _step; | ||||
struct DurationSpec { | ||||
DurationSpec( double m = 0.0 ) : _min(m), _max(m) {} | ||||
DurationSpec( double m1, double m2 ) : _min(m1), _max(m2) {} | ||||
double _min, _max; | ||||
}; | ||||
vector<DurationSpec> _branch_duration_specs; | ||||
vector<double> _branch_duration_sec; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to rotate an object around a center point. | // dist scale animation installer | |||
* | ////////////////////////////////////////////////////////////////////// | |||
* This animation rotates to a specific position. | ||||
*/ | class SGDistScaleAnimation : public SGAnimation { | |||
class SGRotateAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); | SGDistScaleAnimation(const SGPropertyNode* configNode, | |||
virtual ~SGRotateAnimation (); | SGPropertyNode* modelRoot); | |||
virtual int update(); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
private: | class Transform; | |||
SGPropertyNode_ptr _prop; | ||||
double _offset_deg; | ||||
double _factor; | ||||
SGInterpTable * _table; | ||||
bool _has_min; | ||||
double _min_deg; | ||||
bool _has_max; | ||||
double _max_deg; | ||||
double _position_deg; | ||||
sgMat4 _matrix; | ||||
sgVec3 _center; | ||||
sgVec3 _axis; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to slide along an axis. | // dist scale animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGTranslateAnimation : public SGAnimation | ||||
{ | class SGFlashAnimation : public SGAnimation { | |||
public: | ||||
SGFlashAnimation(const SGPropertyNode* configNode, | ||||
SGPropertyNode* modelRoot); | ||||
virtual osg::Group* createAnimationGroup(osg::Group& parent); | ||||
public: | public: | |||
SGTranslateAnimation( SGPropertyNode *prop_root, | class Transform; | |||
SGPropertyNode_ptr props ); | ||||
virtual ~SGTranslateAnimation (); | ||||
virtual int update(); | ||||
private: | ||||
bool _use_personality; | ||||
SGPropertyNode_ptr _prop; | ||||
SGPersonalityParameter<double> _offset_m; | ||||
SGPersonalityParameter<double> _factor; | ||||
SGInterpTable * _table; | ||||
bool _has_min; | ||||
double _min_m; | ||||
bool _has_max; | ||||
double _max_m; | ||||
double _position_m; | ||||
sgMat4 _matrix; | ||||
sgVec3 _axis; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to blend an object. | // dist scale animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGBlendAnimation : public SGAnimation | ||||
{ | class SGBillboardAnimation : public SGAnimation { | |||
public: | public: | |||
SGBlendAnimation( SGPropertyNode *prop_root, | SGBillboardAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot); | |||
virtual ~SGBlendAnimation (); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | class Transform; | |||
private: | ||||
bool _use_personality; | ||||
SGPropertyNode_ptr _prop; | ||||
SGInterpTable * _table; | ||||
double _prev_value; | ||||
SGPersonalityParameter<double> _offset; | ||||
SGPersonalityParameter<double> _factor; | ||||
bool _has_min; | ||||
double _min; | ||||
bool _has_max; | ||||
double _max; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to scale an object. | // Range animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGScaleAnimation : public SGAnimation | ||||
{ | class SGRangeAnimation : public SGAnimation { | |||
public: | public: | |||
SGScaleAnimation( SGPropertyNode *prop_root, | SGRangeAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot); | |||
virtual ~SGScaleAnimation (); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | private: | |||
private: | class UpdateCallback; | |||
bool _use_personality; | SGSharedPtr<const SGCondition> _condition; | |||
SGPropertyNode_ptr _prop; | SGSharedPtr<const SGExpressiond> _minAnimationValue; | |||
SGPersonalityParameter<double> _x_factor; | SGSharedPtr<const SGExpressiond> _maxAnimationValue; | |||
SGPersonalityParameter<double> _y_factor; | SGVec2d _initialValue; | |||
SGPersonalityParameter<double> _z_factor; | ||||
SGPersonalityParameter<double> _x_offset; | ||||
SGPersonalityParameter<double> _y_offset; | ||||
SGPersonalityParameter<double> _z_offset; | ||||
SGInterpTable * _table; | ||||
bool _has_min_x; | ||||
bool _has_min_y; | ||||
bool _has_min_z; | ||||
double _min_x; | ||||
double _min_y; | ||||
double _min_z; | ||||
bool _has_max_x; | ||||
bool _has_max_y; | ||||
bool _has_max_z; | ||||
double _max_x; | ||||
double _max_y; | ||||
double _max_z; | ||||
double _x_scale; | ||||
double _y_scale; | ||||
double _z_scale; | ||||
sgMat4 _matrix; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to rotate texture mappings around a center point. | // Select animation installer | |||
* | ////////////////////////////////////////////////////////////////////// | |||
* This animation rotates to a specific position. | ||||
*/ | class SGSelectAnimation : public SGAnimation { | |||
class SGTexRotateAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props | SGSelectAnimation(const SGPropertyNode* configNode, | |||
); | SGPropertyNode* modelRoot); | |||
virtual ~SGTexRotateAnimation (); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | ||||
private: | ||||
SGPropertyNode_ptr _prop; | ||||
double _offset_deg; | ||||
double _factor; | ||||
SGInterpTable * _table; | ||||
bool _has_min; | ||||
double _min_deg; | ||||
bool _has_max; | ||||
double _max_deg; | ||||
double _position_deg; | ||||
sgMat4 _matrix; | ||||
sgVec3 _center; | ||||
sgVec3 _axis; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Animation to slide texture mappings along an axis. | // Alpha test animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGTexTranslateAnimation : public SGAnimation | ||||
{ | class SGAlphaTestAnimation : public SGAnimation { | |||
public: | public: | |||
SGTexTranslateAnimation( SGPropertyNode *prop_root, | SGAlphaTestAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot); | |||
virtual ~SGTexTranslateAnimation (); | virtual void install(osg::Node& node); | |||
virtual int update(); | ||||
private: | ||||
SGPropertyNode_ptr _prop; | ||||
double _offset; | ||||
double _factor; | ||||
double _step; | ||||
double _scroll; | ||||
SGInterpTable * _table; | ||||
bool _has_min; | ||||
double _min; | ||||
bool _has_max; | ||||
double _max; | ||||
double _position; | ||||
sgMat4 _matrix; | ||||
sgVec3 _axis; | ||||
SGCondition * _condition; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* Classes for handling multiple types of Texture translations on one objec | // Blend animation installer | |||
t | ////////////////////////////////////////////////////////////////////// | |||
*/ | ||||
class SGTexMultipleAnimation : public SGAnimation | class SGBlendAnimation : public SGAnimation { | |||
{ | ||||
public: | public: | |||
SGTexMultipleAnimation( SGPropertyNode *prop_root, | SGBlendAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot); | |||
virtual ~SGTexMultipleAnimation (); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
virtual int update(); | virtual void install(osg::Node& node); | |||
private: | private: | |||
class TexTransform | class BlendVisitor; | |||
{ | class UpdateCallback; | |||
public: | SGSharedPtr<SGExpressiond> _animationValue; | |||
SGPropertyNode_ptr prop; | ||||
int subtype; // 0=translation, 1=rotation | ||||
double offset; | ||||
double factor; | ||||
double step; | ||||
double scroll; | ||||
SGInterpTable * table; | ||||
bool has_min; | ||||
double min; | ||||
bool has_max; | ||||
double max; | ||||
double position; | ||||
sgMat4 matrix; | ||||
sgVec3 center; | ||||
sgVec3 axis; | ||||
}; | ||||
SGPropertyNode_ptr _prop; | ||||
TexTransform* _transform; | ||||
int _num_transforms; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* An "animation" to enable the alpha test | // Timed animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGAlphaTestAnimation : public SGAnimation | ||||
{ | class SGTimedAnimation : public SGAnimation { | |||
public: | public: | |||
SGAlphaTestAnimation(SGPropertyNode_ptr props); | SGTimedAnimation(const SGPropertyNode* configNode, | |||
virtual ~SGAlphaTestAnimation (); | SGPropertyNode* modelRoot); | |||
virtual void init(); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
private: | private: | |||
void setAlphaClampToBranch(ssgBranch *b, float clamp); | class UpdateCallback; | |||
float _alpha_clamp; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* An "animation" to modify material properties | // Shadow animation installer | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGMaterialAnimation : public SGAnimation | ||||
{ | ||||
public: | ||||
SGMaterialAnimation(SGPropertyNode *prop_root, SGPropertyNode_ptr props | ||||
, | ||||
const SGPath &texpath); | ||||
virtual ~SGMaterialAnimation(); | ||||
virtual void init(); | ||||
virtual int update(); | ||||
private: | ||||
enum { | ||||
DIFFUSE = 1, | ||||
AMBIENT = 2, | ||||
SPECULAR = 4, | ||||
EMISSION = 8, | ||||
SHININESS = 16, | ||||
TRANSPARENCY = 32, | ||||
THRESHOLD = 64, | ||||
TEXTURE = 128, | ||||
}; | ||||
struct ColorSpec { | ||||
float red, green, blue; | ||||
float factor; | ||||
float offset; | ||||
SGPropertyNode_ptr red_prop; | ||||
SGPropertyNode_ptr green_prop; | ||||
SGPropertyNode_ptr blue_prop; | ||||
SGPropertyNode_ptr factor_prop; | ||||
SGPropertyNode_ptr offset_prop; | ||||
sgVec4 v; | ||||
inline bool dirty() { | ||||
return red >= 0.0 || green >= 0.0 || blue >= 0.0; | ||||
} | ||||
inline bool live() { | ||||
return red_prop || green_prop || blue_prop | ||||
|| factor_prop || offset_prop; | ||||
} | ||||
inline bool operator!=(ColorSpec& a) { | ||||
return red != a.red || green != a.green || blue != a.blue | ||||
|| factor != a.factor || offset != a.offset; | ||||
} | ||||
sgVec4 &rgba() { | ||||
v[0] = clamp(red * factor + offset); | ||||
v[1] = clamp(green * factor + offset); | ||||
v[2] = clamp(blue * factor + offset); | ||||
v[3] = 1.0; | ||||
return v; | ||||
} | ||||
inline float clamp(float val) { | ||||
return val < 0.0 ? 0.0 : val > 1.0 ? 1.0 : val; | ||||
} | ||||
}; | ||||
struct PropSpec { | ||||
float value; | ||||
float factor; | ||||
float offset; | ||||
float min; | ||||
float max; | ||||
SGPropertyNode_ptr value_prop; | ||||
SGPropertyNode_ptr factor_prop; | ||||
SGPropertyNode_ptr offset_prop; | ||||
inline bool dirty() { return value >= 0.0; } | ||||
inline bool live() { return value_prop || factor_prop || offset_pro | ||||
p; } | ||||
inline bool operator!=(PropSpec& a) { | ||||
return value != a.value || factor != a.factor || offset != a.of | ||||
fset; | ||||
} | ||||
}; | ||||
SGCondition *_condition; | ||||
bool _last_condition; | ||||
SGPropertyNode_ptr _prop_root; | ||||
string _prop_base; | ||||
SGPath _texture_base; | ||||
SGPath _texture; | ||||
string _texture_str; | ||||
ssgSimpleState* _cached_material; | ||||
ssgSimpleState* _cloned_material; | ||||
unsigned _read; | ||||
unsigned _update; | ||||
unsigned _static_update; | ||||
bool _global; | ||||
ColorSpec _diff; | ||||
ColorSpec _amb; | ||||
ColorSpec _emis; | ||||
ColorSpec _spec; | ||||
float _shi; | ||||
PropSpec _trans; | ||||
float _thresh; // alpha_clamp (see man glAlphaFunc) | ||||
string _tex; | ||||
string _tmpstr; | ||||
SGPropertyNode_ptr _shi_prop; | ||||
SGPropertyNode_ptr _thresh_prop; | ||||
SGPropertyNode_ptr _tex_prop; | ||||
void cloneMaterials(ssgBranch *b); | ||||
void setMaterialBranch(ssgBranch *b); | ||||
void initColorGroup(SGPropertyNode_ptr, ColorSpec *, int flag); | ||||
void updateColorGroup(ColorSpec *, int flag); | ||||
inline float clamp(float val, float min = 0.0, float max = 1.0) { | ||||
return val < min ? min : val > max ? max : val; | ||||
} | ||||
const char *path(const char *rel) { | ||||
return (_tmpstr = _prop_base + rel).c_str(); | ||||
} | ||||
}; | ||||
/** | class SGShadowAnimation : public SGAnimation { | |||
* An "animation" that compute a scale according to | ||||
* the angle between an axis and the view direction | ||||
*/ | ||||
class SGFlashAnimation : public SGAnimation | ||||
{ | ||||
public: | public: | |||
SGFlashAnimation(SGPropertyNode_ptr props); | SGShadowAnimation(const SGPropertyNode* configNode, | |||
virtual ~SGFlashAnimation (); | SGPropertyNode* modelRoot); | |||
virtual osg::Group* createAnimationGroup(osg::Group& parent); | ||||
static void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d ); | ||||
void flashCallback( sgMat4 r, sgFrustum *f, sgMat4 m ); | ||||
private: | private: | |||
sgVec3 _axis, _center; | class UpdateCallback; | |||
float _power, _factor, _offset, _min_v, _max_v; | ||||
bool _two_sides; | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* An animation that compute a scale according to | // TextureTransform animation | |||
* the distance from a point and the viewer | ////////////////////////////////////////////////////////////////////// | |||
*/ | ||||
class SGDistScaleAnimation : public SGAnimation | ||||
{ | ||||
public: | ||||
SGDistScaleAnimation(SGPropertyNode_ptr props); | ||||
virtual ~SGDistScaleAnimation (); | ||||
static void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m, void *d | ||||
); | ||||
void distScaleCallback( sgMat4 r, sgFrustum *f, sgMat4 m ); | ||||
private: | class SGTexTransformAnimation : public SGAnimation { | |||
sgVec3 _center; | public: | |||
float _factor, _offset, _min_v, _max_v; | SGTexTransformAnimation(const SGPropertyNode* configNode, | |||
bool _has_min, _has_max; | SGPropertyNode* modelRoot); | |||
SGInterpTable * _table; | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
private: | ||||
class Transform; | ||||
class Translation; | ||||
class Rotation; | ||||
class UpdateCallback; | ||||
void appendTexTranslate(const SGPropertyNode* config, | ||||
UpdateCallback* updateCallback); | ||||
void appendTexRotate(const SGPropertyNode* config, | ||||
UpdateCallback* updateCallback); | ||||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
* An animation to tell wich objects don't cast shadows. | // Shader animation | |||
*/ | ////////////////////////////////////////////////////////////////////// | |||
class SGShadowAnimation : public SGAnimation | ||||
{ | class SGShaderAnimation : public SGAnimation { | |||
public: | public: | |||
SGShadowAnimation ( SGPropertyNode *prop_root, | SGShaderAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot, | |||
virtual ~SGShadowAnimation (); | const osgDB::Options* options); | |||
virtual int update(); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
bool get_condition_value(void); | ||||
private: | private: | |||
SGCondition * _condition; | class UpdateCallback; | |||
bool _condition_value; | osg::ref_ptr<osg::Texture2D> _effect_texture; | |||
}; | }; | |||
/** | ////////////////////////////////////////////////////////////////////// | |||
+ * An "animation" that replace fixed opengl pipeline by shaders | // Light animation | |||
+ */ | ////////////////////////////////////////////////////////////////////// | |||
class SGShaderAnimation : public SGAnimation | ||||
{ | class SGLightAnimation : public SGAnimation { | |||
public: | public: | |||
SGShaderAnimation ( SGPropertyNode *prop_root, | SGLightAnimation(const SGPropertyNode* configNode, | |||
SGPropertyNode_ptr props ); | SGPropertyNode* modelRoot, | |||
virtual ~SGShaderAnimation (); | const osgDB::Options* options, | |||
virtual void init(); | const std::string &path, int i); | |||
virtual int update(); | virtual osg::Group* createAnimationGroup(osg::Group& parent); | |||
bool get_condition_value(void); | virtual void install(osg::Node& node); | |||
private: | private: | |||
SGCondition * _condition; | std::string _light_type; | |||
bool _condition_value; | SGVec3d _position; | |||
int _shader_type; | SGVec3d _direction; | |||
float _param_1; | SGVec4d _ambient; | |||
sgVec4 _param_color; | SGVec4d _diffuse; | |||
public: | SGVec4d _specular; | |||
bool _depth_test; | SGVec3d _attenuation; | |||
float _factor; | double _exponent; | |||
SGPropertyNode_ptr _factor_prop; | double _cutoff; | |||
float _speed; | double _near; | |||
SGPropertyNode_ptr _speed_prop; | double _far; | |||
ssgSharedPtr<ssgTexture> _effectTexture; | std::string _key; | |||
unsigned char *_textureData; | class UpdateCallback; | |||
GLint _texWidth, _texHeight; | friend class UpdateCallback; | |||
sgVec4 _envColor; | SGSharedPtr<SGExpressiond> _animationValue; | |||
osg::ref_ptr<const osgDB::Options> _options; | ||||
}; | }; | |||
#endif // _SG_ANIMATION_HXX | #endif // _SG_ANIMATION_HXX | |||
End of changes. 52 change blocks. | ||||
539 lines changed or deleted | 272 lines changed or added | |||
apt_signs.hxx | apt_signs.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: apt_signs.hxx,v 1.6 2006-04-14 14:50:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_APT_SIGNS_HXX | #ifndef _SG_APT_SIGNS_HXX | |||
#define _SG_APT_SIGNS_HXX | #define _SG_APT_SIGNS_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <memory> // for auto-ptr | ||||
#include <plib/ssg.h> // plib include | #include <osg/Node> | |||
class SGMaterialLib; // forward declaration | class SGMaterialLib; // forward declaration | |||
class SGGeod; | ||||
SG_USING_STD(string); | ||||
// Generate a generic sign | // Generate a generic sign | |||
ssgBranch *sgMakeSign( SGMaterialLib *matlib, | osg::Node* SGMakeSign( SGMaterialLib *matlib, const std::string& content ); | |||
const string path, const string content ); | ||||
namespace simgear | ||||
{ | ||||
class AirportSignBuilder | ||||
{ | ||||
public: | ||||
AirportSignBuilder(SGMaterialLib* mats, const SGGeod& center); | ||||
~AirportSignBuilder(); | ||||
void addSign(const SGGeod& pos, double heading, const std::string& cont | ||||
ent, int size); | ||||
osg::Node* getSignsGroup(); | ||||
private: | ||||
class AirportSignBuilderPrivate; | ||||
std::auto_ptr<AirportSignBuilderPrivate> d; | ||||
}; | ||||
// Generate a runway sign | } // of namespace simgear | |||
ssgBranch *sgMakeRunwaySign( SGMaterialLib *matlib, | ||||
const string path, const string name ); | ||||
#endif // _SG_APT_SIGNS_HXX | #endif // _SG_APT_SIGNS_HXX | |||
End of changes. 7 change blocks. | ||||
14 lines changed or deleted | 25 lines changed or added | |||
callback.hxx | callback.hxx | |||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
* | * | |||
* This program is distributed in the hope that it will be useful, but | * This program is distributed in the hope that it will be useful, but | |||
* WITHOUT ANY WARRANTY; without even the implied warranty of | * WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* General Public License for more details. | * General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: callback.hxx,v 1.2 2006-03-08 18:16:09 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _SG_CALLBACK_HXX | #ifndef _SG_CALLBACK_HXX | |||
#define _SG_CALLBACK_HXX | #define _SG_CALLBACK_HXX | |||
/** | /** | |||
* Abstract base class for all callbacks. | * Abstract base class for all callbacks. | |||
*/ | */ | |||
class SGCallback | class SGCallback | |||
{ | { | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
celestialBody.hxx | celestialBody.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: celestialBody.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _CELESTIALBODY_H_ | #ifndef _CELESTIALBODY_H_ | |||
#define _CELESTIALBODY_H_ | #define _CELESTIALBODY_H_ | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/constants.h> | #include <simgear/constants.h> | |||
skipping to change at line 82 | skipping to change at line 82 | |||
double If, double Is, | double If, double Is, | |||
double wf, double ws, | double wf, double ws, | |||
double af, double as, | double af, double as, | |||
double ef, double es, | double ef, double es, | |||
double Mf, double Ms); | double Mf, double Ms); | |||
void getPos(double *ra, double *dec); | void getPos(double *ra, double *dec); | |||
void getPos(double *ra, double *dec, double *magnitude); | void getPos(double *ra, double *dec, double *magnitude); | |||
double getRightAscension(); | double getRightAscension(); | |||
double getDeclination(); | double getDeclination(); | |||
double getMagnitude(); | double getMagnitude(); | |||
double getLon(); | double getLon() const; | |||
double getLat(); | double getLat() const; | |||
void updatePosition(double mjd, Star *ourSun); | void updatePosition(double mjd, Star *ourSun); | |||
}; | }; | |||
inline double CelestialBody::getRightAscension() { return rightAscension; } | inline double CelestialBody::getRightAscension() { return rightAscension; } | |||
inline double CelestialBody::getDeclination() { return declination; } | inline double CelestialBody::getDeclination() { return declination; } | |||
inline double CelestialBody::getMagnitude() { return magnitude; } | inline double CelestialBody::getMagnitude() { return magnitude; } | |||
inline double CelestialBody::getLon() | inline double CelestialBody::getLon() const | |||
{ | { | |||
return lonEcl; | return lonEcl; | |||
} | } | |||
inline double CelestialBody::getLat() | inline double CelestialBody::getLat() const | |||
{ | { | |||
return latEcl; | return latEcl; | |||
} | } | |||
#endif // _CELESTIALBODY_H_ | #endif // _CELESTIALBODY_H_ | |||
End of changes. 4 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added | |||
cloud.hxx | cloud.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: cloud.hxx,v 1.17.2.2 2007-12-12 17:38:19 timoore Exp $ | // $Id$ | |||
#ifndef _SG_CLOUD_HXX_ | #ifndef _SG_CLOUD_HXX_ | |||
#define _SG_CLOUD_HXX_ | #define _SG_CLOUD_HXX_ | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/misc/sg_path.hxx> | #include <simgear/misc/sg_path.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
#include <simgear/structure/SGReferenced.hxx> | ||||
#include <plib/ssg.h> | #include <string> | |||
using std::string; | ||||
#include STL_STRING | #include <osg/ref_ptr> | |||
SG_USING_STD(string); | #include <osg/Array> | |||
#include <osg/Geode> | ||||
// #include <iostream> | #include <osg/Group> | |||
// SG_USING_STD(cout); | #include <osg/MatrixTransform> | |||
// SG_USING_STD(endl); | #include <osg/Switch> | |||
class SGCloudField; | class SGCloudField; | |||
/** | /** | |||
* A class layer to model a single cloud layer | * A class layer to model a single cloud layer | |||
*/ | */ | |||
class SGCloudLayer { | class SGCloudLayer : public SGReferenced { | |||
public: | public: | |||
/** | /** | |||
* This is the list of available cloud coverages/textures | * This is the list of available cloud coverages/textures | |||
*/ | */ | |||
enum Coverage { | enum Coverage { | |||
SG_CLOUD_OVERCAST = 0, | SG_CLOUD_OVERCAST = 0, | |||
SG_CLOUD_BROKEN, | SG_CLOUD_BROKEN, | |||
SG_CLOUD_SCATTERED, | SG_CLOUD_SCATTERED, | |||
SG_CLOUD_FEW, | SG_CLOUD_FEW, | |||
SG_CLOUD_CIRRUS, | SG_CLOUD_CIRRUS, | |||
SG_CLOUD_CLEAR, | SG_CLOUD_CLEAR, | |||
SG_MAX_CLOUD_COVERAGES | SG_MAX_CLOUD_COVERAGES | |||
}; | }; | |||
static const std::string SG_CLOUD_OVERCAST_STRING; // "overcast" | ||||
static const std::string SG_CLOUD_BROKEN_STRING; // "broken" | ||||
static const std::string SG_CLOUD_SCATTERED_STRING; // "scattered" | ||||
static const std::string SG_CLOUD_FEW_STRING; // "few" | ||||
static const std::string SG_CLOUD_CIRRUS_STRING; // "cirrus" | ||||
static const std::string SG_CLOUD_CLEAR_STRING; // "clear" | ||||
/** | /** | |||
* Constructor | * Constructor | |||
* @param tex_path the path to the set of cloud textures | * @param tex_path the path to the set of cloud textures | |||
*/ | */ | |||
SGCloudLayer( const string &tex_path ); | SGCloudLayer( const string &tex_path ); | |||
/** | /** | |||
* Destructor | * Destructor | |||
*/ | */ | |||
~SGCloudLayer( void ); | ~SGCloudLayer( void ); | |||
skipping to change at line 100 | skipping to change at line 110 | |||
void setElevation_m (float elevation_m, bool set_span = true); | void setElevation_m (float elevation_m, bool set_span = true); | |||
/** get the layer thickness */ | /** get the layer thickness */ | |||
float getThickness_m () const; | float getThickness_m () const; | |||
/** | /** | |||
* set the layer thickness. | * set the layer thickness. | |||
* @param thickness_m the layer thickness in meters. | * @param thickness_m the layer thickness in meters. | |||
*/ | */ | |||
void setThickness_m (float thickness_m); | void setThickness_m (float thickness_m); | |||
/** get the layer visibility */ | ||||
float getVisibility_m() const; | ||||
/** | ||||
* set the layer visibility | ||||
* @param visibility_m the layer minimum visibility in meters. | ||||
*/ | ||||
void setVisibility_m(float visibility_m); | ||||
/** | /** | |||
* get the transition/boundary layer depth in meters. This | * get the transition/boundary layer depth in meters. This | |||
* allows gradual entry/exit from the cloud layer via adjusting | * allows gradual entry/exit from the cloud layer via adjusting | |||
* 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 | |||
skipping to change at line 122 | skipping to change at line 140 | |||
/** 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); | |||
/** get coverage as string */ | ||||
const string & getCoverageString() const; | ||||
/** get coverage as string */ | ||||
static const string & getCoverageString( Coverage coverage ); | ||||
/** get coverage type from string */ | ||||
static Coverage getCoverageType( const std::string & coverage ); | ||||
/** set coverage as string */ | ||||
void setCoverageString( const string & coverage ); | ||||
/** | /** | |||
* set the cloud movement direction | * set the cloud movement direction | |||
* @param dir the cloud movement direction | * @param dir the cloud movement direction | |||
*/ | */ | |||
inline void setDirection(float dir) { | inline void setDirection(float dir) { | |||
// cout << "cloud dir = " << dir << endl; | // cout << "cloud dir = " << dir << endl; | |||
direction = dir; | direction = dir; | |||
} | } | |||
/** get the cloud movement direction */ | /** get the cloud movement direction */ | |||
skipping to change at line 154 | skipping to change at line 184 | |||
inline float getSpeed() { return speed; } | inline float getSpeed() { return speed; } | |||
/** | /** | |||
* set the alpha component of the cloud base color. Normally this | * set the alpha component of the cloud base color. Normally this | |||
* should be 1.0, but you can set it anywhere in the range of 0.0 | * should be 1.0, but you can set it anywhere in the range of 0.0 | |||
* to 1.0 to fade a cloud layer in or out. | * to 1.0 to fade a cloud layer in or out. | |||
* @param alpha cloud alpha value (0.0 to 1.0) | * @param alpha cloud alpha value (0.0 to 1.0) | |||
*/ | */ | |||
inline void setAlpha( float alpha ) { | inline void setAlpha( float alpha ) { | |||
if ( alpha < 0.0 ) { alpha = 0.0; } | if ( alpha < 0.0 ) { alpha = 0.0; } | |||
if ( alpha > 1.0 ) { alpha = 1.0; } | if ( alpha > max_alpha ) { alpha = max_alpha; } | |||
cloud_alpha = alpha; | cloud_alpha = alpha; | |||
} | } | |||
inline void setMaxAlpha( float alpha ) { | ||||
if ( alpha < 0.0 ) { alpha = 0.0; } | ||||
if ( alpha > 1.0 ) { alpha = 1.0; } | ||||
max_alpha = alpha; | ||||
} | ||||
inline float getMaxAlpha() const { | ||||
return max_alpha; | ||||
} | ||||
/** build the cloud object */ | /** build the cloud object */ | |||
void rebuild(); | void rebuild(); | |||
/** Enable/disable 3D clouds in this layer */ | ||||
void set_enable3dClouds(bool enable); | ||||
/** | /** | |||
* repaint the cloud colors based on the specified fog_color | * repaint the cloud colors based on the specified fog_color | |||
* @param fog_color the fog color | * @param fog_color the fog color | |||
*/ | */ | |||
bool repaint( sgVec3 fog_color ); | bool repaint( const SGVec3f& fog_color ); | |||
/** | /** | |||
* reposition the cloud layer at the specified origin and | * reposition the cloud layer at the specified origin and | |||
* orientation. | * orientation. | |||
* @param p position vector | * @param p position vector | |||
* @param up the local up vector | * @param up the local up vector | |||
* @param lon specifies a rotation about the Z axis | * @param lon specifies a rotation about the Z axis | |||
* @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 | * @param dt the time elapsed since the last call | |||
*/ | */ | |||
bool reposition( sgVec3 p, sgVec3 up, double lon, double lat, double al | bool reposition( const SGVec3f& p, const SGVec3f& up, | |||
t, | double lon, double lat, double alt, | |||
double dt = 0.0 ); | double dt = 0.0 ); | |||
/** draw the cloud layer */ | osg::Switch* getNode() { return cloud_root.get(); } | |||
void draw( bool top, float *sun_color ); | ||||
static bool enable_bump_mapping; | ||||
/** return the 3D layer cloud associated with this 2D layer */ | /** return the 3D layer cloud associated with this 2D layer */ | |||
SGCloudField *get_layer3D(void) { return layer3D; } | SGCloudField *get_layer3D(void) { return layer3D; } | |||
protected: | ||||
void setTextureOffset(const osg::Vec2& offset); | ||||
private: | private: | |||
struct CloudVertex { | osg::ref_ptr<osg::Switch> cloud_root; | |||
sgVec3 position; | osg::ref_ptr<osg::Switch> layer_root; | |||
sgVec2 texCoord; | osg::ref_ptr<osg::Group> group_top, group_bottom; | |||
sgVec3 tangentSpLight; | osg::ref_ptr<osg::MatrixTransform> layer_transform; | |||
sgVec3 sTangent; | osg::ref_ptr<osg::Geode> layer[4]; | |||
sgVec3 tTangent; | ||||
sgVec3 normal; | ||||
sgVec4 color; | ||||
}; | ||||
CloudVertex *vertices; | ||||
unsigned int *indices; | ||||
ssgRoot *layer_root; | ||||
ssgTransform *layer_transform; | ||||
ssgLeaf *layer[4]; | ||||
ssgStateSelector *state_sel; | ||||
float cloud_alpha; // 1.0 = drawn fully, 0.0 faded out complet ely | float cloud_alpha; // 1.0 = drawn fully, 0.0 faded out complet ely | |||
ssgColourArray *cl[4]; | osg::ref_ptr<osg::Vec4Array> cl[4]; | |||
ssgVertexArray *vl[4]; | osg::ref_ptr<osg::Vec3Array> vl[4]; | |||
ssgTexCoordArray *tl[4]; | osg::ref_ptr<osg::Vec2Array> tl[4]; | |||
osg::ref_ptr<osg::Vec3Array> tl2[4]; | ||||
// height above sea level (meters) | // height above sea level (meters) | |||
SGPath texture_path; | SGPath texture_path; | |||
float layer_span; | float layer_span; | |||
float layer_asl; | float layer_asl; | |||
float layer_thickness; | float layer_thickness; | |||
float layer_transition; | float layer_transition; | |||
float layer_visibility; | ||||
Coverage layer_coverage; | Coverage layer_coverage; | |||
float scale; | float scale; | |||
float speed; | float speed; | |||
float direction; | 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 | |||
// position, not view position | // position, not view position | |||
// double xoff, yoff; | // double xoff, yoff; | |||
double last_lon, last_lat, last_course; | SGGeod last_pos; | |||
double last_course; | ||||
double max_alpha; | ||||
osg::Vec2 base; | ||||
SGCloudField *layer3D; | SGCloudField *layer3D; | |||
// random offset of cloud texture | ||||
sgVec2 base; | ||||
}; | ||||
// make an ssgSimpleState for a cloud layer given the named texture | }; | |||
ssgSimpleState *sgCloudMakeState( const string &path ); | ||||
#endif // _SG_CLOUD_HXX_ | #endif // _SG_CLOUD_HXX_ | |||
End of changes. 22 change blocks. | ||||
45 lines changed or deleted | 77 lines changed or added | |||
cloudfield.hxx | cloudfield.hxx | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// | // | |||
#ifndef _CLOUDFIELD_HXX | #ifndef _CLOUDFIELD_HXX | |||
#define _CLOUDFIELD_HXX | #define _CLOUDFIELD_HXX | |||
#include <plib/sg.h> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <vector> | #include <vector> | |||
#include <map> | ||||
SG_USING_STD(vector); | #include <osgDB/ReaderWriter> | |||
#include <osg/ref_ptr> | ||||
#include <osg/Array> | ||||
#include <osg/Geometry> | ||||
#include <osg/Group> | ||||
#include <osg/Switch> | ||||
namespace osg | ||||
{ | ||||
class Fog; | ||||
class StateSet; | ||||
class Vec4f; | ||||
} | ||||
#include <simgear/misc/sg_path.hxx> | ||||
#include <simgear/structure/Singleton.hxx> | ||||
#include <simgear/math/SGMath.hxx> | ||||
using std::vector; | ||||
class SGNewCloud; | class SGNewCloud; | |||
class culledCloud { | namespace simgear | |||
public: | { | |||
SGNewCloud *aCloud; | class EffectGeode; | |||
sgVec3 eyePos; | } | |||
float dist; | ||||
float heading; | typedef std::map<int, osg::ref_ptr<osg::PositionAttitudeTransform> > CloudH | |||
float alt; | ash; | |||
bool operator<(const culledCloud &b) const { | ||||
return (this->dist < b.dist); | ||||
} | ||||
}; | ||||
typedef vector<culledCloud> list_of_culledCloud; | ||||
/** | /** | |||
* A layer of 3D clouds. | * A layer of 3D clouds, defined by lat/long/alt. | |||
*/ | */ | |||
class SGCloudField { | class SGCloudField { | |||
private: | private: | |||
class Cloud { | class Cloud { | |||
public: | public: | |||
SGNewCloud *aCloud; | SGNewCloud *aCloud; | |||
sgVec3 pos; | SGVec3f pos; | |||
bool visible; | bool visible; | |||
}; | }; | |||
typedef vector<Cloud> list_of_Cloud; | float Rnd(float); | |||
// cull all clouds of a tiled field | ||||
void cullClouds(sgVec3 eyePos, sgMat4 mat); | ||||
void applyDensity(void); | // Theoretical maximum cloud depth, used for fudging the LoD | |||
// ranges to ensure that clouds become visible at maximum range | ||||
list_of_Cloud theField; | static float MAX_CLOUD_DEPTH; | |||
// this is a relative position only, with that we can move all cloud | ||||
s at once | // this is a relative position only, with that we can move all clouds at | |||
sgVec3 relative_position; | once | |||
// double lon, lat; | SGVec3f relative_position; | |||
sgFrustum frustum; | osg::ref_ptr<osg::Group> field_root; | |||
osg::ref_ptr<osg::Group> placed_root; | ||||
sgMat4 transform; | osg::ref_ptr<osg::PositionAttitudeTransform> field_transform; | |||
double deltax, deltay, alt; | osg::ref_ptr<osg::PositionAttitudeTransform> altitude_transform; | |||
double last_lon, last_lat, last_course; | osg::ref_ptr<osg::LOD> field_lod; | |||
sgSphere field_sphere; | ||||
float last_density; | osg::Vec3f old_pos; | |||
bool draw_in_3d; | CloudHash cloud_hash; | |||
struct CloudFog : public simgear::Singleton<CloudFog> | ||||
{ | ||||
CloudFog(); | ||||
osg::ref_ptr<osg::Fog> fog; | ||||
}; | ||||
void removeCloudFromTree(osg::ref_ptr<osg::PositionAttitudeTransform> tra | ||||
nsform); | ||||
void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transfor | ||||
m, float lon, float lat, float alt, float x, float y); | ||||
void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transfor | ||||
m, SGGeod loc, float x, float y); | ||||
void addCloudToTree(osg::ref_ptr<osg::PositionAttitudeTransform> transfor | ||||
m, SGGeod loc); | ||||
void applyVisRangeAndCoverage(void); | ||||
public: | public: | |||
SGCloudField(); | SGCloudField(); | |||
~SGCloudField(); | ~SGCloudField(); | |||
void clear(void); | void clear(void); | |||
bool isDefined3D(void); | ||||
// add one cloud, data is not copied, ownership given | // add one cloud, data is not copied, ownership given | |||
void addCloud( sgVec3 pos, SGNewCloud *cloud); | void addCloud( SGVec3f& pos, osg::ref_ptr<simgear::EffectGeode> clou | |||
d); | ||||
// for debug only | ||||
void buildTestLayer(void); | ||||
// Render a cloud field ( param ex. thesky->get_sun_color() ) | ||||
void Render( float *sun_color ); | ||||
// reposition the cloud layer at the specified origin and orientatio | ||||
n | ||||
void reposition( sgVec3 p, sgVec3 up, double lon, double lat, double | ||||
alt, double dt, float direction, float speed); | ||||
bool is3D(void) { return draw_in_3d; } | ||||
// visibility distance for clouds in meters | ||||
static float CloudVis; | ||||
static sgVec3 view_vec, view_X, view_Y; | ||||
static float density; | ||||
static double timer_dt; | ||||
static double fieldSize; | ||||
static bool enable3D; | ||||
// return the size of the memory pool used by texture impostors | ||||
static int get_CacheSize(void); | ||||
static int get_CacheResolution(void); | ||||
static float get_CloudVis(void) { return CloudVis; } | ||||
static float get_density(void) { return density; } | ||||
static bool get_enable3dClouds(void) { return enable3D; } | ||||
static void set_CacheSize(int sizeKb); | /** | |||
static void set_CacheResolution(int resolutionPixels); | * Add a new cloud with a given index at a specific point defined by | |||
static void set_CloudVis(float distance); | lon/lat and an x/y offset | |||
static void set_density(float density); | */ | |||
static void set_enable3dClouds(bool enable); | bool addCloud(float lon, float lat, float alt, int index, osg::ref_p | |||
tr<simgear::EffectGeode> geode); | ||||
bool addCloud(float lon, float lat, float alt, float x, float y, int | ||||
index, osg::ref_ptr<simgear::EffectGeode> geode); | ||||
// Cloud handling functions. | ||||
bool deleteCloud(int identifier); | ||||
bool repositionCloud(int identifier, float lon, float lat, float alt); | ||||
bool repositionCloud(int identifier, float lon, float lat, float alt, flo | ||||
at x, float y); | ||||
/** | ||||
* reposition the cloud layer at the specified origin and | ||||
* orientation. | ||||
* @param p position vector | ||||
* @param up the local up vector | ||||
* @param lon specifies a rotation about the Z axis | ||||
* @param lat specifies a rotation about the new Y axis | ||||
* @param dt the time elapsed since the last call | ||||
* @param asl altitude of the layer | ||||
* @param speed of cloud layer movement (due to wind) | ||||
* @param direction of cloud layer movement (due to wind) | ||||
*/ | ||||
bool reposition( const SGVec3f& p, const SGVec3f& up, | ||||
double lon, double lat, double dt, int asl, float speed, float | ||||
direction); | ||||
osg::Group* getNode() { return field_root.get(); } | ||||
// visibility distance for clouds in meters | ||||
static float CloudVis; | ||||
static SGVec3f view_vec, view_X, view_Y; | ||||
static float view_distance; | ||||
static float impostor_distance; | ||||
static float lod1_range; | ||||
static float lod2_range; | ||||
static bool use_impostors; | ||||
static double timer_dt; | ||||
static float fieldSize; | ||||
static bool wrap; | ||||
static bool getWrap(void) { return wrap; } | ||||
static void setWrap(bool w) { wrap = w; } | ||||
static float getImpostorDistance(void) { return impostor_distance; } | ||||
static void setImpostorDistance(float d) { impostor_distance = d; } | ||||
static float getLoD1Range(void) { return lod1_range; } | ||||
static void setLoD1Range(int d) { lod1_range = d; } | ||||
static float getLoD2Range(void) { return lod2_range; } | ||||
static void setLoD2Range(int d) { lod2_range = d; } | ||||
static void setUseImpostors(bool b) { use_impostors = b; } | ||||
static bool getUseImpostors(void) { return use_impostors; } | ||||
static float getVisRange(void) { return view_distance; } | ||||
static void setVisRange(float d) { view_distance = d; } | ||||
void applyVisAndLoDRange(void); | ||||
static osg::Fog* getFog() | ||||
{ | ||||
return CloudFog::instance()->fog.get(); | ||||
} | ||||
static void updateFog(double visibility, const osg::Vec4f& color); | ||||
}; | }; | |||
#endif // _CLOUDFIELD_HXX | #endif // _CLOUDFIELD_HXX | |||
End of changes. 11 change blocks. | ||||
72 lines changed or deleted | 134 lines changed or added | |||
colors.hxx | colors.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: colors.hxx,v 1.7 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_COLORS_HXX | #ifndef _SG_COLORS_HXX | |||
#define _SG_COLORS_HXX 1 | #define _SG_COLORS_HXX 1 | |||
#include <math.h> | #include <math.h> | |||
#if defined( macintosh ) | #if defined (sgi) | |||
const float system_gamma = 1.4; | ||||
#elif defined (sgi) | ||||
const float system_gamma = 2.0/1.7; | const float system_gamma = 2.0/1.7; | |||
#else // others | #else // others | |||
const float system_gamma = 2.5; | const float system_gamma = 2.5; | |||
#endif | #endif | |||
// simple architecture independant gamma correction function. | // simple architecture independant gamma correction function. | |||
inline void gamma_correct_rgb(float *color, | inline void gamma_correct_rgb(float *color, | |||
float reff = 2.5, float system = system_gamma ) | float reff = 2.5, float system = system_gamma ) | |||
{ | { | |||
if (reff == system) | if (reff == system) | |||
return; | return; | |||
float tmp = reff/system; | float tmp = reff/system; | |||
color[0] = pow(color[0], tmp); | color[0] = pow(color[0], tmp); | |||
color[1] = pow(color[1], tmp); | color[1] = pow(color[1], tmp); | |||
color[2] = pow(color[2], tmp); | color[2] = pow(color[2], tmp); | |||
}; | } | |||
inline void gamma_correct_c(float *color, | inline void gamma_correct_c(float *color, | |||
float reff = 2.5, float system = system_gamma) | float reff = 2.5, float system = system_gamma) | |||
{ | { | |||
if (reff == system) | if (reff == system) | |||
return; | return; | |||
*color = pow(*color, reff/system); | *color = pow(*color, reff/system); | |||
}; | } | |||
inline void gamma_restore_rgb(float *color, | inline void gamma_restore_rgb(float *color, | |||
float reff = 2.5, float system = system_gamma ) | float reff = 2.5, float system = system_gamma ) | |||
{ | { | |||
if (reff == system) | if (reff == system) | |||
return; | return; | |||
float tmp = system/reff; | float tmp = system/reff; | |||
color[0] = pow(color[0], tmp); | color[0] = pow(color[0], tmp); | |||
color[1] = pow(color[1], tmp); | color[1] = pow(color[1], tmp); | |||
color[2] = pow(color[2], tmp); | color[2] = pow(color[2], tmp); | |||
}; | } | |||
inline void gamma_restore_c(float *color, | inline void gamma_restore_c(float *color, | |||
float reff = 2.5, float system = system_gamma) | float reff = 2.5, float system = system_gamma) | |||
{ | { | |||
if (reff == system) | if (reff == system) | |||
return; | return; | |||
*color = pow(*color, system/reff); | *color = pow(*color, system/reff); | |||
}; | } | |||
#endif // _SG_COLORS_HXX | #endif // _SG_COLORS_HXX | |||
End of changes. 6 change blocks. | ||||
9 lines changed or deleted | 6 lines changed or added | |||
commands.hxx | commands.hxx | |||
---|---|---|---|---|
/** | /** | |||
* \file commands.hxx | * \file commands.hxx | |||
* Interface definition for encapsulated commands. | * Interface definition for encapsulated commands. | |||
* Started Spring 2001 by David Megginson, david@megginson.com | * Started Spring 2001 by David Megginson, david@megginson.com | |||
* This code is released into the Public Domain. | * This code is released into the Public Domain. | |||
* | * | |||
* $Id: commands.hxx,v 1.1 2003-09-24 17:19:23 ehofman Exp $ | * $Id$ | |||
*/ | */ | |||
#ifndef __COMMANDS_HXX | #ifndef __COMMANDS_HXX | |||
#define __COMMANDS_HXX | #define __COMMANDS_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <map> | #include <map> | |||
#include <vector> | ||||
#include <simgear/props/props.hxx> | #include <simgear/threads/SGThread.hxx> | |||
#include <simgear/math/sg_types.hxx> | ||||
SG_USING_STD(string); | // forward decls | |||
SG_USING_STD(map); | class SGPropertyNode; | |||
SG_USING_STD(vector); | ||||
/** | /** | |||
* Manage commands. | * Manage commands. | |||
* | * | |||
* <p>This class allows the application to register and unregister | * <p>This class allows the application to register and unregister | |||
* commands, and provides shortcuts for executing them. Commands are | * commands, and provides shortcuts for executing them. Commands are | |||
* simple functions that take a const pointer to an SGPropertyNode: | * simple functions that take a const pointer to an SGPropertyNode: | |||
* the function may use the nodes children as parameters.</p> | * the function may use the nodes children as parameters.</p> | |||
* | * | |||
* @author David Megginson, david@megginson.com | * @author David Megginson, david@megginson.com | |||
*/ | */ | |||
class SGCommandMgr | class SGCommandMgr | |||
{ | { | |||
public: | public: | |||
/** | ||||
* Command functor object | ||||
*/ | ||||
class Command | ||||
{ | ||||
public: | ||||
virtual ~Command() { } | ||||
virtual bool operator()(const SGPropertyNode * arg) = 0; | ||||
}; | ||||
/** | typedef bool (*command_t) (const SGPropertyNode * arg); | |||
* Type for a command function. | ||||
*/ | ||||
typedef bool (*command_t) (const SGPropertyNode * arg); | ||||
/** | private: | |||
* Default constructor. | class FunctionCommand : public Command | |||
*/ | { | |||
SGCommandMgr (); | public: | |||
FunctionCommand( command_t fun ) | ||||
: f_(fun) {} | ||||
virtual bool operator()(const SGPropertyNode * arg) { return (*f_)( | ||||
arg); } | ||||
private: | ||||
command_t f_; | ||||
}; | ||||
template< class ObjPtr, typename MemFn > | ||||
class MethodCommand : public Command | ||||
{ | ||||
public: | ||||
MethodCommand( const ObjPtr& pObj, MemFn pMemFn ) : | ||||
pObj_(pObj), pMemFn_(pMemFn) {} | ||||
virtual bool operator()(const SGPropertyNode * arg) | ||||
{ | ||||
return ((*pObj_).*pMemFn_)(arg); | ||||
} | ||||
private: | ||||
ObjPtr pObj_; | ||||
MemFn pMemFn_; | ||||
}; | ||||
/** | ||||
* Helper template functions. | ||||
*/ | ||||
template< class ObjPtr, typename MemFn > | ||||
Command* make_functor( const ObjPtr& pObj, MemFn pMemFn ) | ||||
{ | ||||
return new MethodCommand<ObjPtr,MemFn>(pObj, pMemFn ); | ||||
} | ||||
public: | ||||
/** | /** | |||
* Destructor. | * Destructor. | |||
*/ | */ | |||
virtual ~SGCommandMgr (); | virtual ~SGCommandMgr (); | |||
/** | /** | |||
* Implement the classical singleton. | ||||
*/ | ||||
static SGCommandMgr* instance(); | ||||
/** | ||||
* Register a new command with the manager. | * Register a new command with the manager. | |||
* | * | |||
* @param name The command name. Any existing command with | * @param name The command name. Any existing command with | |||
* the same name will silently be overwritten. | * the same name will silently be overwritten. | |||
* @param command A pointer to a one-arg function returning | * @param command A pointer to a one-arg function returning | |||
* a bool result. The argument is always a const pointer to | * a bool result. The argument is always a const pointer to | |||
* an SGPropertyNode (which may contain multiple values). | * an SGPropertyNode (which may contain multiple values). | |||
*/ | */ | |||
virtual void addCommand (const string &name, command_t command); | void addCommand(const std::string& name, command_t f) | |||
{ addCommandObject(name, new FunctionCommand(f)); } | ||||
void addCommandObject (const std::string &name, Command* command); | ||||
template<class OBJ, typename METHOD> | ||||
void addCommand(const std::string& name, const OBJ& o, METHOD m) | ||||
{ | ||||
addCommandObject(name, make_functor(o,m)); | ||||
} | ||||
/** | /** | |||
* Look up an existing command. | * Look up an existing command. | |||
* | * | |||
* @param name The command name. | * @param name The command name. | |||
* @return A pointer to the command, or 0 if there is no registered | * @return A pointer to the command, or 0 if there is no registered | |||
* command with the name specified. | * command with the name specified. | |||
*/ | */ | |||
virtual command_t getCommand (const string &name) const; | virtual Command* getCommand (const std::string &name) const; | |||
/** | /** | |||
* Get a list of all existing command names. | * Get a list of all existing command names. | |||
* | * | |||
* @return A (possibly empty) vector of the names of all registered | * @return A (possibly empty) vector of the names of all registered | |||
* commands. | * commands. | |||
*/ | */ | |||
virtual vector<string> getCommandNames () const; | virtual string_list getCommandNames () const; | |||
/** | /** | |||
* Execute a command. | * Execute a command. | |||
* | * | |||
* @param name The name of the command. | * @param name The name of the command. | |||
* @param arg A const pointer to an SGPropertyNode. The node | * @param arg A const pointer to an SGPropertyNode. The node | |||
* may have a value and/or children, etc., so that it is possible | * may have a value and/or children, etc., so that it is possible | |||
* to pass an arbitrarily complex data structure to a command. | * to pass an arbitrarily complex data structure to a command. | |||
* @return true if the command is present and executes successfully, | * @return true if the command is present and executes successfully, | |||
* false otherwise. | * false otherwise. | |||
*/ | */ | |||
virtual bool execute (const string &name, const SGPropertyNode * arg) con | virtual bool execute (const std::string &name, const SGPropertyNode * arg | |||
st; | ) const; | |||
protected: | ||||
/** | ||||
* Default constructor. | ||||
*/ | ||||
SGCommandMgr (); | ||||
private: | private: | |||
typedef map<string,command_t> command_map; | typedef std::map<std::string,Command*> command_map; | |||
command_map _commands; | command_map _commands; | |||
static SGMutex _instanceMutex; | ||||
}; | }; | |||
#endif // __COMMANDS_HXX | #endif // __COMMANDS_HXX | |||
// end of commands.hxx | // end of commands.hxx | |||
End of changes. 15 change blocks. | ||||
21 lines changed or deleted | 84 lines changed or added | |||
compiler.h | compiler.h | |||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: compiler.h,v 1.24 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
* | * | |||
************************************************************************** / | ************************************************************************** / | |||
/** \file compiler.h | /** \file compiler.h | |||
* A set of defines to encapsulate compiler and platform differences. | * A set of defines to encapsulate compiler and platform differences. | |||
* Please refer to the source code for full documentation on this file. | * Please refer to the source code for full documentation on this file. | |||
* | * | |||
* Here is a summary of what this file does. | * This file is useful to set compiler-specific options in every file - for | |||
* example, disabling warnings. | ||||
* | * | |||
* (1) Defines macros for some STL includes which may be affected | ||||
* by file name length limitations. | ||||
* | ||||
* (2) Defines macros for some features not supported by all C++ compiler | ||||
s. | ||||
* | ||||
* (3) Defines 'explicit' as a null macro if the compiler doesn't support | ||||
* the explicit keyword. | ||||
* | ||||
* (4) Defines 'typename' as a null macro if the compiler doesn't support | ||||
* the typename keyword. | ||||
* | ||||
* (5) Defines bool, true and false if the compiler doesn't do so. | ||||
* | ||||
* (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler | ||||
* supports calling a function template by providing its template | ||||
* arguments explicitly. | ||||
* | ||||
* (7) Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>. | ||||
* | ||||
* (8) Defines SG_NO_ARROW_OPERATOR if the compiler is unable | ||||
* to support operator->() for iterators. | ||||
* | ||||
* (9) Defines SG_USE_EXCEPTIONS if the compiler supports exceptions. | ||||
* Note: no FlightGear code uses exceptions. | ||||
* | ||||
* (10) Define SG_NAMESPACES if the compiler supports namespaces. | ||||
* | ||||
* (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used?? | ||||
* | ||||
* (12) Define SG_HAVE_STD if std namespace is supported. | ||||
* | ||||
* (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler | ||||
* supports partial specialization of class templates. | ||||
* | ||||
* (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers. | ||||
* | ||||
* (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are pres | ||||
ent. | ||||
* | ||||
* (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception clas | ||||
s | ||||
* that clashes with the one defined in <stdexcept>. | ||||
*/ | */ | |||
#ifndef _SG_COMPILER_H | #ifndef _SG_COMPILER_H | |||
#define _SG_COMPILER_H | #define _SG_COMPILER_H | |||
/* | /* | |||
* Helper macro SG_STRINGIZE: | * Helper macro SG_STRINGIZE: | |||
* Converts the parameter X to a string after macro replacement | * Converts the parameter X to a string after macro replacement | |||
* on X has been performed. | * on X has been performed. | |||
*/ | */ | |||
#define SG_STRINGIZE(X) SG_DO_STRINGIZE(X) | #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X) | |||
#define SG_DO_STRINGIZE(X) #X | #define SG_DO_STRINGIZE(X) #X | |||
#ifdef __GNUC__ | #ifdef __GNUC__ | |||
# if __GNUC__ == 2 | # if __GNUC__ < 3 | |||
# if __GNUC_MINOR__ < 8 | # error Time to upgrade. GNU compilers < 3.0 not supported | |||
# elif (__GNUC__ == 3) && (__GNUC_MINOR__ < 4) | ||||
// g++-2.7.x | # warning GCC compilers prior to 3.4 are suspect | |||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip.h> | ||||
# define STL_IOSTREAM <iostream.h> | ||||
# define STL_ITERATOR <iterator.h> | ||||
# define STL_FSTREAM <fstream.h> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream.h> | ||||
# define SG_NEED_AUTO_PTR | ||||
# define SG_NO_DEFAULT_TEMPLATE_ARGS | ||||
# define SG_INCOMPLETE_FUNCTIONAL | ||||
# define SG_NO_ARROW_OPERATOR | ||||
# elif __GNUC_MINOR__ >= 8 | ||||
// g++-2.8.x and egcs-1.x | ||||
# define SG_EXPLICIT_FUNCTION_TMPL_ARGS | ||||
# define SG_NEED_AUTO_PTR | ||||
# define SG_MEMBER_TEMPLATES | ||||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STREAMBUF | ||||
# define SG_CLASS_PARTIAL_SPECIALIZATION | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream> | ||||
# endif | ||||
# elif __GNUC__ >= 3 | ||||
// g++-3.0.x | ||||
# define SG_EXPLICIT_FUNCTION_TMPL_ARGS | ||||
# define SG_NEED_AUTO_PTR | ||||
# define SG_MEMBER_TEMPLATES | ||||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STREAMBUF | ||||
# define SG_CLASS_PARTIAL_SPECIALIZATION | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream> | ||||
# else | ||||
# error Time to upgrade. GNU compilers < 2.7 not supported | ||||
# endif | # endif | |||
# define SG_GCC_VERSION (__GNUC__ * 10000 \ | ||||
+ __GNUC_MINOR__ * 100 \ | ||||
+ __GNUC_PATCHLEVEL__) | ||||
# define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_ STRINGIZE(__GNUC_MINOR__) | # define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_ STRINGIZE(__GNUC_MINOR__) | |||
#endif // __GNUC__ | #endif // __GNUC__ | |||
/* KAI C++ */ | /* KAI C++ */ | |||
#if defined(__KCC) | #if defined(__KCC) | |||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STREAMBUF | ||||
# define SG_HAVE_TRAITS | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream> | ||||
# define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION) | # define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION) | |||
#endif // __KCC | #endif // __KCC | |||
// | // | |||
// Metrowerks | ||||
// | ||||
#if defined(__MWERKS__) | ||||
/* | ||||
CodeWarrior compiler from Metrowerks, Inc. | ||||
*/ | ||||
# define SG_HAVE_TRAITS | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define SG_HAVE_STD | ||||
# define SG_NAMESPACES | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
// Temp: | ||||
# define bcopy(from, to, n) memcpy(to, from, n) | ||||
// -rp- please use FG_MEM_COPY everywhere ! | ||||
// #define FG_MEM_COPY(to,from,n) memcpy(to, from, n) | ||||
// -dw- currently used glut has no game mode stuff | ||||
# define GLUT_WRONG_VERSION | ||||
# define SG_COMPILER_STR "Metrowerks CodeWarrior C++ version " SG_STRINGIZ | ||||
E(__MWERKS__) | ||||
#endif // __MWERKS__ | ||||
// | ||||
// Microsoft compilers. | // Microsoft compilers. | |||
// | // | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
# define bcopy(from, to, n) memcpy(to, from, n) | # define bcopy(from, to, n) memcpy(to, from, n) | |||
# define FG_MEM_COPY(to,from,n) memcpy(to, from, n) | ||||
# if _MSC_VER >= 1200 // msvc++ 6.0 or greater | # if _MSC_VER >= 1200 // msvc++ 6.0 or greater | |||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define SG_HAVE_STREAMBUF | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream> | ||||
# define isnan _isnan | # define isnan _isnan | |||
# define snprintf _snprintf | # define snprintf _snprintf | |||
# if _MSC_VER < 1500 | ||||
# define vsnprintf _vsnprintf | ||||
# endif | ||||
# define copysign _copysign | ||||
# define strcasecmp stricmp | ||||
# undef min | ||||
# undef max | ||||
# pragma warning(disable: 4786) // identifier was truncated to '255' cha racters | # pragma warning(disable: 4786) // identifier was truncated to '255' cha racters | |||
# pragma warning(disable: 4244) // conversion from double to float | # pragma warning(disable: 4244) // conversion from double to float | |||
# pragma warning(disable: 4305) // | # pragma warning(disable: 4305) // | |||
# else | # else | |||
# error What version of MSVC++ is this? | # error What version of MSVC++ is this? | |||
# endif | # endif | |||
# define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_M SC_VER) | # define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_M SC_VER) | |||
#endif // _MSC_VER | #endif // _MSC_VER | |||
#ifdef __BORLANDC__ | ||||
# if defined(HAVE_SGI_STL_PORT) | ||||
// Use quotes around long file names to get around Borland's include hacker | ||||
y | ||||
# define STL_ALGORITHM "algorithm" | ||||
# define STL_FUNCTIONAL "functional" | ||||
# define SG_MATH_EXCEPTION_CLASH | ||||
# else | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRSTREAM <strstream> | ||||
# define SG_INCOMPLETE_FUNCTIONAL | ||||
# endif // HAVE_SGI_STL_PORT | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STRING <string> | ||||
# define SG_NO_DEFAULT_TEMPLATE_ARGS | ||||
# define SG_NAMESPACES | ||||
// # define SG_HAVE_STD | ||||
# define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__) | ||||
#endif // __BORLANDC__ | ||||
// | // | |||
// Native SGI compilers | // Native SGI compilers | |||
// | // | |||
#if defined ( sgi ) && !defined( __GNUC__ ) | #if defined ( sgi ) && !defined( __GNUC__ ) | |||
# define SG_HAVE_NATIVE_SGI_COMPILERS | # if (_COMPILER_VERSION < 740) | |||
# error Need MipsPro 7.4.0 or higher now | ||||
# endif | ||||
# define SG_EXPLICIT_FUNCTION_TMPL_ARGS | #define SG_HAVE_NATIVE_SGI_COMPILERS | |||
# define SG_CLASS_PARTIAL_SPECIALIZATION | ||||
# define SG_NEED_AUTO_PTR | ||||
# define SG_MEMBER_TEMPLATES | ||||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STREAMBUF | ||||
# define SG_HAVE_TRAITS | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
#if (_COMPILER_VERSION < 740) | ||||
# define STL_STRING <irix_string> | ||||
#else | ||||
# define STL_STRING <string> | ||||
#endif | ||||
# define STL_STRSTREAM <strstream> | ||||
#pragma set woff 1001,1012,1014,1116,1155,1172,1174 | #pragma set woff 1001,1012,1014,1116,1155,1172,1174 | |||
#pragma set woff 1401,1460,1551,1552,1681 | #pragma set woff 1401,1460,1551,1552,1681 | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
#pragma set woff 1682,3303 | # pragma set woff 1682,3303 | |||
#if (_COMPILER_VERSION >= 740) | # pragma set woff 3624 | |||
# pragma set woff 3624 | ||||
#endif | ||||
#endif | #endif | |||
# define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COM PILER_VERSION) | # define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COM PILER_VERSION) | |||
#endif // Native SGI compilers | #endif // Native SGI compilers | |||
#if defined (__sun) | #if defined (__sun) | |||
# define SG_UNIX | ||||
# include <strings.h> | # include <strings.h> | |||
# include <memory.h> | # include <memory.h> | |||
# if defined ( __cplusplus ) | # if defined ( __cplusplus ) | |||
// typedef unsigned int size_t; | // typedef unsigned int size_t; | |||
extern "C" { | extern "C" { | |||
extern void *memmove(void *, const void *, size_t); | extern void *memmove(void *, const void *, size_t); | |||
} | } | |||
# else | # else | |||
extern void *memmove(void *, const void *, size_t); | extern void *memmove(void *, const void *, size_t); | |||
# endif // __cplusplus | # endif // __cplusplus | |||
skipping to change at line 347 | skipping to change at line 136 | |||
# if !defined( __GNUC__ ) | # if !defined( __GNUC__ ) | |||
# define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC ) | # define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC ) | |||
# endif | # endif | |||
#endif // sun | #endif // sun | |||
// | // | |||
// Intel C++ Compiler | // Intel C++ Compiler | |||
// | // | |||
#if defined(__ICC) || defined (__ECC) | #if defined(__ICC) || defined (__ECC) | |||
# define SG_NAMESPACES | ||||
# define SG_HAVE_STD | ||||
# define SG_HAVE_STREAMBUF | ||||
# define SG_HAVE_TRAITS | ||||
# define SG_HAVE_STD_INCLUDES | ||||
# define STL_ALGORITHM <algorithm> | ||||
# define STL_FUNCTIONAL <functional> | ||||
# define STL_IOMANIP <iomanip> | ||||
# define STL_IOSTREAM <iostream> | ||||
# define STL_ITERATOR <iterator> | ||||
# define STL_FSTREAM <fstream> | ||||
# define STL_STDEXCEPT <stdexcept> | ||||
# define STL_STRING <string> | ||||
# define STL_STRSTREAM <strstream> | ||||
# define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC) | # define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC) | |||
#endif // __ICC | #endif // __ICC | |||
// | // | |||
// Platform dependent gl.h and glut.h definitions | // Platform dependent gl.h and glut.h definitions | |||
// | // | |||
#ifdef __APPLE__ | #ifdef __APPLE__ | |||
# define SG_GL_H <OpenGL/gl.h> | # define SG_MAC | |||
# define SG_GLX_H <AGL/agl.h> | # define SG_UNIX | |||
# define SG_GLU_H <OpenGL/glu.h> | # ifdef __GNUC__ | |||
# define SG_GLEXT_H <OpenGL/glext.h> | # if ( __GNUC__ > 3 ) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 3 ) | |||
# define SG_GLUT_H <GLUT/glut.h> | ||||
inline int (isnan)(double r) { return !(r <= 0 || r >= 0); } | inline int (isnan)(double r) { return !(r <= 0 || r >= 0); } | |||
#else | # else | |||
# define SG_GL_H <GL/gl.h> | // any C++ header file undefines isinf and isnan | |||
# define SG_GLX_H <GL/glx.h> | // so this should be included before <iostream> | |||
# define SG_GLU_H <GL/glu.h> | // the functions are STILL in libm (libSystem on mac os x) | |||
# define SG_GLEXT_H <GL/glext.h> | extern "C" int (isnan)(double); | |||
# define SG_GLUT_H <GL/glut.h> | extern "C" int (isinf)(double); | |||
#endif | # endif | |||
# else | ||||
// | inline int (isnan)(double r) { return !(r <= 0 || r >= 0); } | |||
// No user modifiable definitions beyond here. | # endif | |||
// | ||||
#ifdef SG_NEED_EXPLICIT | ||||
# define explicit | ||||
#endif | #endif | |||
#ifdef SG_NEED_TYPENAME | #if defined (__FreeBSD__) | |||
# define typename | # define SG_UNIX | |||
#include <sys/param.h> | ||||
# if __FreeBSD_version < 500000 | ||||
extern "C" { | ||||
inline int isnan(double r) { return !(r <= 0 || r >= 0); } | ||||
} | ||||
# endif | ||||
#endif | #endif | |||
#ifdef SG_NEED_MUTABLE | #if defined (__CYGWIN__) | |||
# define mutable | # define SG_WINDOWS | |||
# define SG_UNIX | ||||
# include <ieeefp.h> // isnan | ||||
#endif | #endif | |||
#ifdef SG_NEED_BOOL | // includes both MSVC and mingw compilers | |||
typedef int bool; | #if defined(_WIN32) || defined(__WIN32__) | |||
# define true 1 | # define SG_WINDOWS | |||
# define false 0 | ||||
#endif | #endif | |||
#ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS | #if defined(__linux__) || defined(_AIX) || defined ( sgi ) | |||
# define SG_NULL_TMPL_ARGS <> | # define SG_UNIX | |||
#else | ||||
# define SG_NULL_TMPL_ARGS | ||||
#endif | #endif | |||
#ifdef SG_CLASS_PARTIAL_SPECIALIZATION | #if defined( __GNUC__ ) | |||
# define SG_TEMPLATE_NULL template<> | # define DEPRECATED __attribute__ ((deprecated)) | |||
#else | #else | |||
# define SG_TEMPLATE_NULL | # define DEPRECATED | |||
#endif | #endif | |||
// SG_NO_NAMESPACES is a hook so that users can disable namespaces | // | |||
// without having to edit library headers. | // No user modifiable definitions beyond here. | |||
#if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES) | // | |||
# define SG_NAMESPACE(X) namespace X { | ||||
# define SG_NAMESPACE_END } | ||||
# define SG_USING_NAMESPACE(X) using namespace X | ||||
# else | ||||
# define SG_NAMESPACE(X) | ||||
# define SG_NAMESPACE_END | ||||
# define SG_USING_NAMESPACE(X) | ||||
#endif | ||||
/** \def SG_USING_STD(x) | ||||
* Expands to using std::x if SG_HAVE_STD is defined | ||||
*/ | ||||
# ifdef SG_HAVE_STD | ||||
# define SG_USING_STD(X) using std::X | ||||
# define STD std | ||||
# else | ||||
# define SG_USING_STD(X) | ||||
# define STD | ||||
# endif | ||||
// Additional <functional> implementation from SGI STL 3.11 | ||||
// Adapter function objects: pointers to member functions | ||||
#ifdef SG_INCOMPLETE_FUNCTIONAL | ||||
template <class _Ret, class _Tp> | ||||
class const_mem_fun_ref_t | ||||
#ifndef __BORLANDC__ | ||||
: public unary_function<_Tp,_Ret> | ||||
#endif // __BORLANDC__ | ||||
{ | ||||
public: | ||||
explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {} | ||||
_Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); } | ||||
private: | ||||
_Ret (_Tp::*_M_f)() const; | ||||
}; | ||||
template <class _Ret, class _Tp> | ||||
inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const) | ||||
{ return const_mem_fun_ref_t<_Ret,_Tp>(__f); } | ||||
#endif // SG_INCOMPLETE_FUNCTIONAL | ||||
#endif // _SG_COMPILER_H | #endif // _SG_COMPILER_H | |||
End of changes. 28 change blocks. | ||||
338 lines changed or deleted | 62 lines changed or added | |||
condition.hxx | condition.hxx | |||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
* Declarations and inline methods for property conditions. | * Declarations and inline methods for property conditions. | |||
* Written by David Megginson, started 2000. | * Written by David Megginson, started 2000. | |||
* CLO May 2003 - Split out condition specific code. | * CLO May 2003 - Split out condition specific code. | |||
* | * | |||
* This file is in the Public Domain, and comes with no warranty. | * This file is in the Public Domain, and comes with no warranty. | |||
*/ | */ | |||
#ifndef __SG_CONDITION_HXX | #ifndef __SG_CONDITION_HXX | |||
#define __SG_CONDITION_HXX | #define __SG_CONDITION_HXX | |||
#include <simgear/debug/logstream.hxx> | #include <set> | |||
#include <simgear/props/props.hxx> | #include <simgear/structure/SGReferenced.hxx> | |||
#include <simgear/props/props_io.hxx> | #include <simgear/structure/SGSharedPtr.hxx> | |||
class SGPropertyNode; | ||||
//////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////// | |||
// Conditions. | // Conditions. | |||
//////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////// | |||
/** | /** | |||
* An encoded condition. | * An encoded condition. | |||
* | * | |||
* This class encodes a single condition of some sort, possibly | * This class encodes a single condition of some sort, possibly | |||
* connected with properties. | * connected with properties. | |||
* | * | |||
* This class should migrate to somewhere more general. | * This class should migrate to somewhere more general. | |||
*/ | */ | |||
class SGCondition | class SGCondition : public SGReferenced | |||
{ | { | |||
public: | public: | |||
SGCondition (); | SGCondition (); | |||
virtual ~SGCondition (); | virtual ~SGCondition (); | |||
virtual bool test () const = 0; | virtual bool test () const = 0; | |||
}; | virtual void collectDependentProperties(std::set<const SGPropertyNode*>& | |||
props) const { } | ||||
/** | ||||
* Condition for a single property. | ||||
* | ||||
* This condition is true only if the property returns a boolean | ||||
* true value. | ||||
*/ | ||||
class SGPropertyCondition : public SGCondition | ||||
{ | ||||
public: | ||||
SGPropertyCondition ( SGPropertyNode *prop_root, | ||||
const char * propname ); | ||||
virtual ~SGPropertyCondition (); | ||||
virtual bool test () const { return _node->getBoolValue(); } | ||||
private: | ||||
SGConstPropertyNode_ptr _node; | ||||
}; | ||||
/** | ||||
* Condition for a 'not' operator. | ||||
* | ||||
* This condition is true only if the child condition is false. | ||||
*/ | ||||
class SGNotCondition : public SGCondition | ||||
{ | ||||
public: | ||||
// transfer pointer ownership | ||||
SGNotCondition (SGCondition * condition); | ||||
virtual ~SGNotCondition (); | ||||
virtual bool test () const; | ||||
private: | ||||
SGCondition * _condition; | ||||
}; | ||||
/** | ||||
* Condition for an 'and' group. | ||||
* | ||||
* This condition is true only if all of the conditions | ||||
* in the group are true. | ||||
*/ | ||||
class SGAndCondition : public SGCondition | ||||
{ | ||||
public: | ||||
SGAndCondition (); | ||||
virtual ~SGAndCondition (); | ||||
virtual bool test () const; | ||||
// transfer pointer ownership | ||||
virtual void addCondition (SGCondition * condition); | ||||
private: | ||||
vector<SGCondition *> _conditions; | ||||
}; | ||||
/** | ||||
* Condition for an 'or' group. | ||||
* | ||||
* This condition is true if at least one of the conditions in the | ||||
* group is true. | ||||
*/ | ||||
class SGOrCondition : public SGCondition | ||||
{ | ||||
public: | ||||
SGOrCondition (); | ||||
virtual ~SGOrCondition (); | ||||
virtual bool test () const; | ||||
// transfer pointer ownership | ||||
virtual void addCondition (SGCondition * condition); | ||||
private: | ||||
vector<SGCondition *> _conditions; | ||||
}; | ||||
/** | ||||
* Abstract base class for property comparison conditions. | ||||
*/ | ||||
class SGComparisonCondition : public SGCondition | ||||
{ | ||||
public: | ||||
enum Type { | ||||
LESS_THAN, | ||||
GREATER_THAN, | ||||
EQUALS | ||||
}; | ||||
SGComparisonCondition (Type type, bool reverse = false); | ||||
virtual ~SGComparisonCondition (); | ||||
virtual bool test () const; | ||||
virtual void setLeftProperty( SGPropertyNode *prop_root, | ||||
const char * propname ); | ||||
virtual void setRightProperty( SGPropertyNode *prop_root, | ||||
const char * propname ); | ||||
// will make a local copy | ||||
virtual void setRightValue (const SGPropertyNode * value); | ||||
private: | ||||
Type _type; | ||||
bool _reverse; | ||||
SGConstPropertyNode_ptr _left_property; | ||||
SGConstPropertyNode_ptr _right_property; | ||||
SGConstPropertyNode_ptr _right_value; | ||||
}; | }; | |||
/** | /** | |||
* Base class for a conditional components. | * Base class for a conditional components. | |||
* | * | |||
* This class manages the conditions and tests; the component should | * This class manages the conditions and tests; the component should | |||
* invoke the test() method whenever it needs to decide whether to | * invoke the test() method whenever it needs to decide whether to | |||
* active itself, draw itself, and so on. | * active itself, draw itself, and so on. | |||
*/ | */ | |||
class SGConditional | class SGConditional : public SGReferenced | |||
{ | { | |||
public: | public: | |||
SGConditional (); | SGConditional (); | |||
virtual ~SGConditional (); | virtual ~SGConditional (); | |||
// transfer pointer ownership | // transfer pointer ownership | |||
virtual void setCondition (SGCondition * condition); | virtual void setCondition (SGCondition * condition); | |||
virtual const SGCondition * getCondition () const { return _condition; } | virtual const SGCondition * getCondition () const { return _condition; } | |||
virtual bool test () const; | virtual bool test () const; | |||
private: | private: | |||
SGCondition * _condition; | SGSharedPtr<SGCondition> _condition; | |||
}; | }; | |||
/** | /** | |||
* Global function to make a condition out of properties. | * Global function to make a condition out of properties. | |||
* | * | |||
* The top-level is always an implicit 'and' group, whatever the | * The top-level is always an implicit 'and' group, whatever the | |||
* node's name (it should usually be "condition"). | * node's name (it should usually be "condition"). | |||
* | * | |||
* @param node The top-level condition node (usually named "condition"). | * @param node The top-level condition node (usually named "condition"). | |||
* @return A pointer to a newly-allocated condition; it is the | * @return A pointer to a newly-allocated condition; it is the | |||
End of changes. 5 change blocks. | ||||
103 lines changed or deleted | 11 lines changed or added | |||
constants.h | constants.h | |||
---|---|---|---|---|
// constants.h -- various constant definitions | // constants.h -- various constant definitions | |||
// | // | |||
// Written by Curtis Olson, started February 2000. | // Written by Curtis Olson, started February 2000. | |||
// Last change by Eric van den Berg, Feb 2013 | ||||
// | // | |||
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt/ | // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt/ | |||
// | // | |||
// This library is free software; you can redistribute it and/or | // This library is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU Library General Public | // modify it under the terms of the GNU Library General Public | |||
// License as published by the Free Software Foundation; either | // License as published by the Free Software Foundation; either | |||
// version 2 of the License, or (at your option) any later version. | // version 2 of the License, or (at your option) any later version. | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: constants.h,v 1.10 2006-06-25 11:55:56 mfranz Exp $ | // $Id$ | |||
/** \file constants.h | /** \file constants.h | |||
* Various constant definitions. | * Various constant definitions. | |||
*/ | */ | |||
#ifndef _SG_CONSTANTS_H | #ifndef _SG_CONSTANTS_H | |||
#define _SG_CONSTANTS_H | #define _SG_CONSTANTS_H | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#ifdef SG_HAVE_STD_INCLUDES | #include <cmath> | |||
# include <cmath> | ||||
#else | ||||
# ifdef SG_MATH_EXCEPTION_CLASH | ||||
# define exception C_exception | ||||
# endif | ||||
# include <math.h> | ||||
#endif | ||||
#include <plib/sg.h> | ||||
// Make sure PI is defined in its various forms | // Make sure PI is defined in its various forms | |||
// SG_PI and SGD_PI (float and double) come from plib/sg.h | #ifndef SGD_PI // remove me once FlightGear no longer uses PLIB | |||
#ifdef M_PI | ||||
const double SGD_PI = M_PI; | ||||
const float SG_PI = M_PI; | ||||
#else | ||||
const float SG_PI = 3.1415926535f; | ||||
const double SGD_PI = 3.1415926535; | ||||
#endif | ||||
#endif // of PLIB-SG guard | ||||
/** 2 * PI */ | /** 2 * PI */ | |||
#define SGD_2PI 6.28318530717958647692 | const double SGD_2PI = SGD_PI * 2.0; | |||
/** PI / 2 */ | /** PI / 2 */ | |||
#ifdef M_PI_2 | #ifdef M_PI_2 | |||
# define SGD_PI_2 M_PI_2 | # define SGD_PI_2 M_PI_2 | |||
#else | #else | |||
# define SGD_PI_2 1.57079632679489661923 | # define SGD_PI_2 1.57079632679489661923 | |||
#endif | #endif | |||
/** PI / 4 */ | /** PI / 4 */ | |||
#define SGD_PI_4 0.78539816339744830961 | const double SGD_PI_4 = 0.78539816339744830961; | |||
#ifndef SGD_DEGREES_TO_RADIANS // // remove me once FlightGear no longer us | ||||
es PLIB | ||||
const double SGD_DEGREES_TO_RADIANS = SGD_PI / 180.0; | ||||
const double SGD_RADIANS_TO_DEGREES = 180.0 / SGD_PI; | ||||
const float SG_DEGREES_TO_RADIANS = SG_PI / 180.0f; | ||||
const float SG_RADIANS_TO_DEGREES = 180.0f / SG_PI; | ||||
#endif // of PLIB-SG guard | ||||
/** \def SG_E "e" */ | /** \def SG_E "e" */ | |||
#ifdef M_E | #ifdef M_E | |||
# define SG_E M_E | # define SG_E M_E | |||
#else | #else | |||
# define SG_E 2.7182818284590452354 | # define SG_E 2.7182818284590452354 | |||
#endif | #endif | |||
/** pi/180/60/60, or about 100 feet at earths' equator */ | /** pi/180/60/60, or about 100 feet at earths' equator */ | |||
#define SG_ONE_SECOND 4.848136811E-6 | #define SG_ONE_SECOND 4.848136811E-6 | |||
/** Radius of Earth in kilometers at the equator. Another source had | /** Radius of Earth in kilometers at the equator. Another source had | |||
* 6378.165 but this is probably close enough */ | * 6378.165 but this is probably close enough */ | |||
#define SG_EARTH_RAD 6378.155 | #define SG_EARTH_RAD 6378.155 | |||
// Maximum terrain elevation from sea level | ||||
#define SG_MAX_ELEVATION_M 9000.0 | ||||
// Earth parameters for WGS 84, taken from LaRCsim/ls_constants.h | // Earth parameters for WGS 84, taken from LaRCsim/ls_constants.h | |||
/** Value of earth radius from LaRCsim (ft) */ | /** Value of earth radius from LaRCsim (ft) */ | |||
#define SG_EQUATORIAL_RADIUS_FT 20925650. | #define SG_EQUATORIAL_RADIUS_FT 20925650. | |||
/** Value of earth radius from LaRCsim (meter) */ | /** Value of earth radius from LaRCsim (meter) */ | |||
#define SG_EQUATORIAL_RADIUS_M 6378138.12 | #define SG_EQUATORIAL_RADIUS_M 6378138.12 | |||
/** Radius squared (ft) */ | /** Radius squared (ft) */ | |||
#define SG_EQ_RAD_SQUARE_FT 437882827922500. | #define SG_EQ_RAD_SQUARE_FT 437882827922500. | |||
/** Radius squared (meter) */ | /** Radius squared (meter) */ | |||
#define SG_EQ_RAD_SQUARE_M 40680645877797.1344 | #define SG_EQ_RAD_SQUARE_M 40680645877797.1344 | |||
// Physical Constants, SI | ||||
/**mean gravity on earth */ | ||||
#define SG_g0_m_p_s2 9.80665 // m/s2 | ||||
/**standard pressure at SL */ | ||||
#define SG_p0_Pa 101325.0 // Pa | ||||
/**standard density at SL */ | ||||
#define SG_rho0_kg_p_m3 1.225 // kg/m3 | ||||
/**standard temperature at SL */ | ||||
#define SG_T0_K 288.15 // K (=15degC) | ||||
/**specific gas constant of air*/ | ||||
#define SG_R_m2_p_s2_p_K 287.05 // m2/s2/K | ||||
/**specific heat constant at constant pressure*/ | ||||
#define SG_cp_m2_p_s2_p_K 1004.68 // m2/s2/K | ||||
/**ratio of specific heats of air*/ | ||||
#define SG_gamma 1.4 // =cp/cv (cp = 1004.68 m2/s2 K , | ||||
cv = 717.63 m2/s2 K) | ||||
/**constant beta used to calculate dynamic viscosity */ | ||||
#define SG_beta_kg_p_sm_sqrK 1.458e-06 // kg/s/m/SQRT(K) | ||||
/** Sutherland constant */ | ||||
#define SG_S_K 110.4 // K | ||||
// Conversions | // Conversions | |||
/** Arc seconds to radians. (arcsec*pi)/(3600*180) = rad */ | /** Arc seconds to radians. (arcsec*pi)/(3600*180) = rad */ | |||
#define SG_ARCSEC_TO_RAD 4.84813681109535993589e-06 | #define SG_ARCSEC_TO_RAD 4.84813681109535993589e-06 | |||
/** Radians to arc seconds. (rad*3600*180)/pi = arcsec */ | /** Radians to arc seconds. (rad*3600*180)/pi = arcsec */ | |||
#define SG_RAD_TO_ARCSEC 206264.806247096355156 | #define SG_RAD_TO_ARCSEC 206264.806247096355156 | |||
/** Feet to Meters */ | /** Feet to Meters */ | |||
#define SG_FEET_TO_METER 0.3048 | #define SG_FEET_TO_METER 0.3048 | |||
skipping to change at line 120 | skipping to change at line 164 | |||
/** Statute Miles to Meters. */ | /** Statute Miles to Meters. */ | |||
#define SG_SM_TO_METER 1609.3412196 | #define SG_SM_TO_METER 1609.3412196 | |||
/** Radians to Nautical Miles. 1 nm = 1/60 of a degree */ | /** Radians to Nautical Miles. 1 nm = 1/60 of a degree */ | |||
#define SG_NM_TO_RAD 0.00029088820866572159 | #define SG_NM_TO_RAD 0.00029088820866572159 | |||
/** Nautical Miles to Radians */ | /** Nautical Miles to Radians */ | |||
#define SG_RAD_TO_NM 3437.7467707849392526 | #define SG_RAD_TO_NM 3437.7467707849392526 | |||
/** Miles per second to Knots */ | /** meters per second to Knots */ | |||
#define SG_MPS_TO_KT 1.9438444924406046432 | #define SG_MPS_TO_KT 1.9438444924406046432 | |||
/** Knots to Miles per second */ | /** Knots to meters per second */ | |||
#define SG_KT_TO_MPS 0.5144444444444444444 | #define SG_KT_TO_MPS 0.5144444444444444444 | |||
/** Feet per second to Knots */ | /** Feet per second to Knots */ | |||
#define SG_FPS_TO_KT 0.5924838012958962841 | #define SG_FPS_TO_KT 0.5924838012958962841 | |||
/** Knots to Feet per second */ | /** Knots to Feet per second */ | |||
#define SG_KT_TO_FPS 1.6878098571011956874 | #define SG_KT_TO_FPS 1.6878098571011956874 | |||
/** Miles per second to Miles per hour */ | /** meters per second to Miles per hour */ | |||
#define SG_MPS_TO_MPH 2.2369362920544020312 | #define SG_MPS_TO_MPH 2.2369362920544020312 | |||
/** Miles per hour to Miles per second */ | /** meetrs per hour to Miles per second */ | |||
#define SG_MPH_TO_MPS 0.44704 | #define SG_MPH_TO_MPS 0.44704 | |||
/** Meters per second to Kilometers per hour */ | /** Meters per second to Kilometers per hour */ | |||
#define SG_MPS_TO_KMH 3.6 | #define SG_MPS_TO_KMH 3.6 | |||
/** Kilometers per hour to Miles per second */ | /** Kilometers per hour to meters per second */ | |||
#define SG_KMH_TO_MPS 0.2777777777777777778 | #define SG_KMH_TO_MPS 0.2777777777777777778 | |||
/** Pascal to Inch Mercury */ | /** Pascal to Inch Mercury */ | |||
#define SG_PA_TO_INHG 0.0002952998330101010 | #define SG_PA_TO_INHG 0.0002952998330101010 | |||
/** Inch Mercury to Pascal */ | /** Inch Mercury to Pascal */ | |||
#define SG_INHG_TO_PA 3386.388640341 | #define SG_INHG_TO_PA 3386.388640341 | |||
/** slug/ft3 to kg/m3 */ | ||||
#define SG_SLUGFT3_TO_KGPM3 515.379 | ||||
/** For divide by zero avoidance, this will be close enough to zero */ | /** For divide by zero avoidance, this will be close enough to zero */ | |||
#define SG_EPSILON 0.0000001 | #define SG_EPSILON 0.0000001 | |||
/** Highest binobj format version we know how to read/write. This starts a t | /** Highest binobj format version we know how to read/write. This starts a t | |||
* 0 and can go up to 65535 */ | * 0 and can go up to 65535 */ | |||
#define SG_BINOBJ_VERSION 6 | #define SG_BINOBJ_VERSION 6 | |||
/** for backwards compatibility */ | /** for backwards compatibility */ | |||
#define SG_SCENERY_FILE_FORMAT "0.4" | #define SG_SCENERY_FILE_FORMAT "0.4" | |||
End of changes. 14 change blocks. | ||||
19 lines changed or deleted | 68 lines changed or added | |||
debug_types.h | debug_types.h | |||
---|---|---|---|---|
/** \file debug_types.h | /** \file debug_types.h | |||
* Define the various logging classes and prioritiess | * Define the various logging classes and priorities | |||
*/ | */ | |||
/** | /** | |||
* Define the possible classes/categories of logging messages | * Define the possible classes/categories of logging messages | |||
*/ | */ | |||
typedef enum { | typedef enum { | |||
SG_NONE = 0x00000000, | SG_NONE = 0x00000000, | |||
SG_TERRAIN = 0x00000001, | SG_TERRAIN = 0x00000001, | |||
SG_ASTRO = 0x00000002, | SG_ASTRO = 0x00000002, | |||
SG_FLIGHT = 0x00000004, | SG_FLIGHT = 0x00000004, | |||
SG_INPUT = 0x00000008, | SG_INPUT = 0x00000008, | |||
SG_GL = 0x00000010, | SG_GL = 0x00000010, | |||
SG_VIEW = 0x00000020, | SG_VIEW = 0x00000020, | |||
SG_COCKPIT = 0x00000040, | SG_COCKPIT = 0x00000040, | |||
SG_GENERAL = 0x00000080, | SG_GENERAL = 0x00000080, | |||
SG_MATH = 0x00000100, | SG_MATH = 0x00000100, | |||
SG_EVENT = 0x00000200, | SG_EVENT = 0x00000200, | |||
SG_AIRCRAFT = 0x00000400, | SG_AIRCRAFT = 0x00000400, | |||
SG_AUTOPILOT = 0x00000800, | SG_AUTOPILOT = 0x00000800, | |||
SG_IO = 0x00001000, | SG_IO = 0x00001000, | |||
SG_CLIPPER = 0x00002000, | SG_CLIPPER = 0x00002000, | |||
SG_NETWORK = 0x00004000, | SG_NETWORK = 0x00004000, | |||
SG_ATC = 0x00008000, | SG_ATC = 0x00008000, | |||
SG_NASAL = 0x00010000, | SG_NASAL = 0x00010000, | |||
SG_INSTR = 0x00020000, | SG_INSTR = 0x00020000, | |||
SG_SYSTEMS = 0x00040000, | SG_SYSTEMS = 0x00040000, | |||
SG_UNDEFD = 0x00080000, // For range checking | SG_AI = 0x00080000, | |||
SG_ENVIRONMENT = 0x00100000, | ||||
SG_SOUND = 0x00200000, | ||||
SG_NAVAID = 0x00400000, | ||||
SG_UNDEFD = 0x00800000, // For range checking | ||||
SG_ALL = 0xFFFFFFFF | SG_ALL = 0xFFFFFFFF | |||
} sgDebugClass; | } sgDebugClass; | |||
/** | /** | |||
* Define the possible logging priorities (and their order). | * Define the possible logging priorities (and their order). | |||
*/ | */ | |||
typedef enum { | typedef enum { | |||
SG_BULK = 1, // For frequent messages | SG_BULK = 1, // For frequent messages | |||
SG_DEBUG, // Less frequent debug type messages | SG_DEBUG, // Less frequent debug type messages | |||
SG_INFO, // Informatory messages | SG_INFO, // Informatory messages | |||
SG_WARN, // Possible impending problem | SG_WARN, // Possible impending problem | |||
End of changes. 4 change blocks. | ||||
23 lines changed or deleted | 27 lines changed or added | |||
dome.hxx | dome.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// version 2 of the License, or (at your option) any later version. | // version 2 of the License, or (at your option) any later version. | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | ||||
// $Id: dome.hxx,v 1.6 2006-03-08 18:16:09 mfranz Exp $ | ||||
#ifndef _SKYDOME_HXX | #ifndef _SKYDOME_HXX | |||
#define _SKYDOME_HXX | #define _SKYDOME_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <plib/ssg.h> // plib include | #include <osg/ref_ptr> | |||
#include <osg/Array> | ||||
class SGSkyDome { | #include <osg/MatrixTransform> | |||
ssgTransform *dome_transform; | ||||
ssgSimpleState *dome_state; | #include <simgear/structure/SGReferenced.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
ssgVertexArray *center_disk_vl; | ||||
ssgColourArray *center_disk_cl; | namespace osg | |||
{ | ||||
ssgVertexArray *upper_ring_vl; | class DrawElementsUShort; | |||
ssgColourArray *upper_ring_cl; | } | |||
ssgVertexArray *middle_ring_vl; | namespace simgear { | |||
ssgColourArray *middle_ring_cl; | class SGReaderWriterOptions; | |||
} | ||||
ssgVertexArray *lower_ring_vl; | ||||
ssgColourArray *lower_ring_cl; | class SGSkyDome : public SGReferenced { | |||
osg::ref_ptr<osg::MatrixTransform> dome_transform; | ||||
float asl; | double asl; | |||
osg::ref_ptr<osg::Vec3Array> dome_vl; | ||||
osg::ref_ptr<osg::Vec3Array> dome_cl; | ||||
public: | public: | |||
// Constructor | // Constructor | |||
SGSkyDome( void ); | SGSkyDome( void ); | |||
// Destructor | // Destructor | |||
~SGSkyDome( void ); | ~SGSkyDome( void ); | |||
// initialize the sky object and connect it into our scene graph | // initialize the sky object and connect it into our scene graph | |||
// root | // root | |||
ssgBranch *build( double hscale = 80000.0, double vscale = 80000.0 ); | osg::Node *build( double hscale = 80000.0, double vscale = 80000.0, sim gear::SGReaderWriterOptions *options = 0 ); | |||
// repaint the sky colors based on current value of sun_angle, | // repaint the sky colors based on current value of sun_angle, | |||
// sky, and fog colors. This updates the color arrays for | // sky, and fog colors. This updates the color arrays for | |||
// ssgVtxTable. | // ssgVtxTable. | |||
// sun angle in degrees relative to verticle | // sun angle in degrees relative to verticle | |||
// 0 degrees = high noon | // 0 degrees = high noon | |||
// 90 degrees = sun rise/set | // 90 degrees = sun rise/set | |||
// 180 degrees = darkest midnight | // 180 degrees = darkest midnight | |||
bool repaint( sgVec3 sky_color, sgVec3 fog_color, double sun_angle, | bool repaint( const SGVec3f& sun_color, const SGVec3f& sky_color, | |||
double vis ); | const SGVec3f& fog_color, double sun_angle, double vis ); | |||
// reposition the sky at the specified origin and orientation | // reposition the sky at the specified origin and orientation | |||
// lon specifies a rotation about the Z axis | // lon specifies a rotation about the Z axis | |||
// lat specifies a rotation about the new Y axis | // lat specifies a rotation about the new Y axis | |||
// 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 reposition( sgVec3 p, double lon, double lat, double spin ); | bool reposition( const SGVec3f& p, double asl, | |||
double lon, double lat, double spin ); | ||||
private: | ||||
void makeDome(int rings, int bands, osg::DrawElementsUShort& elements); | ||||
}; | }; | |||
#endif // _SKYDOME_HXX | #endif // _SKYDOME_HXX | |||
End of changes. 6 change blocks. | ||||
25 lines changed or deleted | 28 lines changed or added | |||
easyxml.hxx | easyxml.hxx | |||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
* Written by David Megginson, 2000-2001 | * Written by David Megginson, 2000-2001 | |||
* This file is in the Public Domain, and comes with NO WARRANTY of any kin d. | * This file is in the Public Domain, and comes with NO WARRANTY of any kin d. | |||
*/ | */ | |||
#ifndef __EASYXML_HXX | #ifndef __EASYXML_HXX | |||
#define __EASYXML_HXX | #define __EASYXML_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/structure/exception.hxx> | #include <simgear/structure/exception.hxx> | |||
#include STL_IOSTREAM | #include <iostream> | |||
#include STL_STRING | #include <string> | |||
#include <vector> | #include <vector> | |||
SG_USING_STD(istream); | using std::istream; | |||
SG_USING_STD(string); | using std::string; | |||
SG_USING_STD(vector); | using std::vector; | |||
/** | /** | |||
* Interface for XML attributes. | * Interface for XML attributes. | |||
* | * | |||
* This interface is used to provide a list of attributes to the | * This interface is used to provide a list of attributes to the | |||
* application. The interface is a pure abstract class so that | * application. The interface is a pure abstract class so that | |||
* different implementations can be substituted for the sake of | * different implementations can be substituted for the sake of | |||
* efficiency. | * efficiency. | |||
* | * | |||
* @see XMLAttributesDefault | * @see XMLAttributesDefault | |||
skipping to change at line 208 | skipping to change at line 208 | |||
* @param name The name of the attribute that will have the new | * @param name The name of the attribute that will have the new | |||
* value. | * value. | |||
* @param value The new value. | * @param value The new value. | |||
*/ | */ | |||
virtual void setValue (const char * name, const char * value); | virtual void setValue (const char * name, const char * value); | |||
private: | private: | |||
vector<string> _atts; | vector<string> _atts; | |||
}; | }; | |||
//////////////////////////////////////////////////////////////////////// | ||||
// Attribute list wrapper for Expat. | ||||
//////////////////////////////////////////////////////////////////////// | ||||
class ExpatAtts : public XMLAttributes | ||||
{ | ||||
public: | ||||
ExpatAtts (const char ** atts) : _atts(atts) {} | ||||
virtual int size () const; | ||||
virtual const char * getName (int i) const; | ||||
virtual const char * getValue (int i) const; | ||||
virtual const char * getValue (const char * name) const; | ||||
private: | ||||
const char ** _atts; | ||||
}; | ||||
/** | /** | |||
* Visitor class for an XML document. | * Visitor class for an XML document. | |||
* | * | |||
* This interface uses the Visitor pattern. The XML parser walks | * This interface uses the Visitor pattern. The XML parser walks | |||
* through the XML document and invokes the appropriate method in | * through the XML document and invokes the appropriate method in | |||
* this visitor for each piece of markup it finds. By default, | * this visitor for each piece of markup it finds. By default, | |||
* the methods do nothing; the application must subclass the visitor | * the methods do nothing; the application must subclass the visitor | |||
* and override the methods for the events it's interested in. | * and override the methods for the events it's interested in. | |||
* All applications are required to provide an implementation | * All applications are required to provide an implementation | |||
* for the {@link #error} callback. | * for the {@link #error} callback. | |||
End of changes. 3 change blocks. | ||||
5 lines changed or deleted | 23 lines changed or added | |||
ephemeris.hxx | ephemeris.hxx | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: ephemeris.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _EPHEMERIS_HXX | #ifndef _EPHEMERIS_HXX | |||
#define _EPHEMERIS_HXX | #define _EPHEMERIS_HXX | |||
#include <plib/sg.h> | #include <string> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
#include <simgear/ephemeris/moonpos.hxx> | #include <simgear/ephemeris/moonpos.hxx> | |||
#include <simgear/ephemeris/mercury.hxx> | #include <simgear/ephemeris/mercury.hxx> | |||
#include <simgear/ephemeris/venus.hxx> | #include <simgear/ephemeris/venus.hxx> | |||
#include <simgear/ephemeris/mars.hxx> | #include <simgear/ephemeris/mars.hxx> | |||
#include <simgear/ephemeris/jupiter.hxx> | #include <simgear/ephemeris/jupiter.hxx> | |||
#include <simgear/ephemeris/saturn.hxx> | #include <simgear/ephemeris/saturn.hxx> | |||
#include <simgear/ephemeris/uranus.hxx> | #include <simgear/ephemeris/uranus.hxx> | |||
#include <simgear/ephemeris/neptune.hxx> | #include <simgear/ephemeris/neptune.hxx> | |||
#include <simgear/ephemeris/stardata.hxx> | #include <simgear/ephemeris/stardata.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
#include <simgear/misc/sg_path.hxx> | ||||
/** Ephemeris class | /** Ephemeris class | |||
* | * | |||
* Written by Durk Talsma <d.talsma@direct.a2000.nl> and Curtis Olson | * Written by Durk Talsma <d.talsma@direct.a2000.nl> and Curtis Olson | |||
* <http://www.flightgear.org/~curt> | * <http://www.flightgear.org/~curt> | |||
* | * | |||
* Introduction | * Introduction | |||
* | * | |||
* The SGEphemeris class computes and stores the positions of the Sun, | * The SGEphemeris class computes and stores the positions of the Sun, | |||
* the Moon, the planets, and the brightest stars. These positions | * the Moon, the planets, and the brightest stars. These positions | |||
* can then be used to accurately render the dominant visible items in | * can then be used to accurately render the dominant visible items in | |||
skipping to change at line 83 | skipping to change at line 86 | |||
Jupiter *jupiter; | Jupiter *jupiter; | |||
Saturn *saturn; | Saturn *saturn; | |||
Uranus *uranus; | Uranus *uranus; | |||
Neptune *neptune; | Neptune *neptune; | |||
// 9 planets, minus earth, minus pluto which we don't draw = 7 | // 9 planets, minus earth, minus pluto which we don't draw = 7 | |||
// planets[i][0] = Right Ascension | // planets[i][0] = Right Ascension | |||
// planets[i][1] = Declination | // planets[i][1] = Declination | |||
// planets[i][2] = Magnitude | // planets[i][2] = Magnitude | |||
int nplanets; | int nplanets; | |||
sgdVec3 planets[7]; | SGVec3d planets[7]; | |||
SGStarData *stars; | SGStarData *stars; | |||
public: | public: | |||
/** | /** | |||
* Constructor. | * Constructor. | |||
* This creates an instance of the SGEphemeris object. When | * This creates an instance of the SGEphemeris object. When | |||
* calling the constructor you need to provide a path pointing to | * calling the constructor you need to provide a path pointing to | |||
* your star database file. | * your star database file. | |||
* @param path path to your star database */ | * @param path path to your star database */ | |||
SGEphemeris( const string &path ); | SGEphemeris( const std::string &path ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGEphemeris( void ); | ~SGEphemeris( void ); | |||
/** | /** | |||
* Update (recalculate) the positions of all objects for the | * Update (recalculate) the positions of all objects for the | |||
* specified time. The update() method requires you to pass in | * specified time. The update() method requires you to pass in | |||
* the current modified Julian date, the current local sidereal | * the current modified Julian date, the current local sidereal | |||
* time, and the current latitude. The update() method is designed | * time, and the current latitude. The update() method is designed | |||
* to be called by the host application before every frame. | * to be called by the host application before every frame. | |||
skipping to change at line 155 | skipping to change at line 158 | |||
inline int getNumPlanets() const { return nplanets; } | inline int getNumPlanets() const { return nplanets; } | |||
/** | /** | |||
* Returns a pointer to an array of planet data in sgdVec3 | * Returns a pointer to an array of planet data in sgdVec3 | |||
* format. (See plib.sourceforge.net for information on plib and | * format. (See plib.sourceforge.net for information on plib and | |||
* the ``sg'' package.) An sgdVec3 is a 3 element double | * the ``sg'' package.) An sgdVec3 is a 3 element double | |||
* array. The first element is the right ascension of the planet, | * array. The first element is the right ascension of the planet, | |||
* the second is the declination, and the third is the magnitude. | * the second is the declination, and the third is the magnitude. | |||
* @return planets array | * @return planets array | |||
*/ | */ | |||
inline sgdVec3 *getPlanets() { return planets; } | inline SGVec3d *getPlanets() { return planets; } | |||
inline const SGVec3d *getPlanets() const { return planets; } | ||||
/** @return the numbers of defined stars. */ | /** @return the numbers of defined stars. */ | |||
inline int getNumStars() const { return stars->getNumStars(); } | inline int getNumStars() const { return stars->getNumStars(); } | |||
/** | /** | |||
* Returns a pointer to an array of star data in sgdVec3 | * Returns a pointer to an array of star data in sgdVec3 | |||
* format. An The first element of the sgdVec3 is the right | * format. An The first element of the sgdVec3 is the right | |||
* ascension of the planet, the second is the declination, and the | * ascension of the planet, the second is the declination, and the | |||
* third is the magnitude. | * third is the magnitude. | |||
* @returns star array | * @returns star array | |||
*/ | */ | |||
inline sgdVec3 *getStars() { return stars->getStars(); } | inline SGVec3d *getStars() { return stars->getStars(); } | |||
inline const SGVec3d *getStars() const { return stars->getStars(); } | ||||
}; | }; | |||
#endif // _EPHEMERIS_HXX | #endif // _EPHEMERIS_HXX | |||
End of changes. 7 change blocks. | ||||
6 lines changed or deleted | 11 lines changed or added | |||
event_mgr.hxx | event_mgr.hxx | |||
---|---|---|---|---|
#ifndef _SG_EVENT_MGR_HXX | #ifndef _SG_EVENT_MGR_HXX | |||
#define _SG_EVENT_MGR_HXX | #define _SG_EVENT_MGR_HXX | |||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <simgear/structure/subsystem_mgr.hxx> | #include <simgear/structure/subsystem_mgr.hxx> | |||
#include "callback.hxx" | #include "callback.hxx" | |||
class SGEventMgr; | class SGEventMgr; | |||
struct SGTimer { | class SGTimer { | |||
public: | ||||
~SGTimer(); | ||||
void run(); | ||||
std::string name; | ||||
double interval; | double interval; | |||
SGCallback* callback; | SGCallback* callback; | |||
SGEventMgr* mgr; | ||||
bool repeat; | bool repeat; | |||
bool simtime; | bool running; | |||
void run(); | ||||
}; | }; | |||
class SGTimerQueue { | class SGTimerQueue { | |||
public: | public: | |||
SGTimerQueue(int preSize=1); | SGTimerQueue(int preSize=1); | |||
~SGTimerQueue(); | ~SGTimerQueue(); | |||
void update(double deltaSecs); | void update(double deltaSecs); | |||
double now() { return _now; } | double now() { return _now; } | |||
void insert(SGTimer* timer, double time); | void insert(SGTimer* timer, double time); | |||
SGTimer* remove(SGTimer* timer); | SGTimer* remove(SGTimer* timer); | |||
SGTimer* remove(); | SGTimer* remove(); | |||
SGTimer* nextTimer() { return _numEntries ? _table[0].timer : 0; } | SGTimer* nextTimer() { return _numEntries ? _table[0].timer : 0; } | |||
double nextTime() { return -_table[0].pri; } | double nextTime() { return -_table[0].pri; } | |||
SGTimer* findByName(const std::string& name) const; | ||||
private: | private: | |||
// The "priority" is stored as a negative time. This allows the | // The "priority" is stored as a negative time. This allows the | |||
// implemenetation to treat the "top" of the heap as the largest | // implementation to treat the "top" of the heap as the largest | |||
// value and avoids developer mindbugs. ;) | // value and avoids developer mindbugs. ;) | |||
struct HeapEntry { double pri; SGTimer* timer; }; | struct HeapEntry { double pri; SGTimer* timer; }; | |||
int parent(int n) { return ((n+1)/2) - 1; } | int parent(int n) { return ((n+1)/2) - 1; } | |||
int lchild(int n) { return ((n+1)*2) - 1; } | int lchild(int n) { return ((n+1)*2) - 1; } | |||
int rchild(int n) { return ((n+1)*2 + 1) - 1; } | int rchild(int n) { return ((n+1)*2 + 1) - 1; } | |||
double pri(int n) { return _table[n].pri; } | double pri(int n) { return _table[n].pri; } | |||
void swap(int a, int b) { | void swap(int a, int b) { | |||
HeapEntry tmp = _table[a]; | HeapEntry tmp = _table[a]; | |||
_table[a] = _table[b]; | _table[a] = _table[b]; | |||
skipping to change at line 80 | skipping to change at line 84 | |||
virtual void init() {} | virtual void init() {} | |||
virtual void update(double delta_time_sec); | virtual void update(double delta_time_sec); | |||
void setRealtimeProperty(SGPropertyNode* node) { _rtProp = node; } | void setRealtimeProperty(SGPropertyNode* node) { _rtProp = node; } | |||
/** | /** | |||
* Add a single function callback event as a repeating task. | * Add a single function callback event as a repeating task. | |||
* ex: addTask("foo", &Function ... ) | * ex: addTask("foo", &Function ... ) | |||
*/ | */ | |||
template<typename FUNC> | template<typename FUNC> | |||
inline void addTask(const char* name, const FUNC& f, | inline void addTask(const std::string& name, const FUNC& f, | |||
double interval, double delay=0, bool sim=false) | double interval, double delay=0, bool sim=false) | |||
{ add(make_callback(f), interval, delay, true, sim); } | { add(name, make_callback(f), interval, delay, true, sim); } | |||
/** | /** | |||
* Add a single function callback event as a one-shot event. | * Add a single function callback event as a one-shot event. | |||
* ex: addEvent("foo", &Function ... ) | * ex: addEvent("foo", &Function ... ) | |||
*/ | */ | |||
template<typename FUNC> | template<typename FUNC> | |||
inline void addEvent(const char* name, const FUNC& f, | inline void addEvent(const std::string& name, const FUNC& f, | |||
double delay, bool sim=false) | double delay, bool sim=false) | |||
{ add(make_callback(f), 0, delay, false, sim); } | { add(name, make_callback(f), 0, delay, false, sim); } | |||
/** | /** | |||
* Add a object/method pair as a repeating task. | * Add a object/method pair as a repeating task. | |||
* ex: addTask("foo", &object, &ClassName::Method, ...) | * ex: addTask("foo", &object, &ClassName::Method, ...) | |||
*/ | */ | |||
template<class OBJ, typename METHOD> | template<class OBJ, typename METHOD> | |||
inline void addTask(const char* name, | inline void addTask(const std::string& name, | |||
const OBJ& o, METHOD m, | const OBJ& o, METHOD m, | |||
double interval, double delay=0, bool sim=false) | double interval, double delay=0, bool sim=false) | |||
{ add(make_callback(o,m), interval, delay, true, sim); } | { add(name, make_callback(o,m), interval, delay, true, sim); } | |||
/** | /** | |||
* Add a object/method pair as a repeating task. | * Add a object/method pair as a repeating task. | |||
* ex: addEvent("foo", &object, &ClassName::Method, ...) | * ex: addEvent("foo", &object, &ClassName::Method, ...) | |||
*/ | */ | |||
template<class OBJ, typename METHOD> | template<class OBJ, typename METHOD> | |||
inline void addEvent(const char* name, | inline void addEvent(const std::string& name, | |||
const OBJ& o, METHOD m, | const OBJ& o, METHOD m, | |||
double delay, bool sim=false) | double delay, bool sim=false) | |||
{ add(make_callback(o,m), 0, delay, false, sim); } | { add(name, make_callback(o,m), 0, delay, false, sim); } | |||
void removeTask(const std::string& name); | ||||
private: | private: | |||
friend struct SGTimer; | friend class SGTimer; | |||
void add(SGCallback* cb, | void add(const std::string& name, SGCallback* cb, | |||
double interval, double delay, | double interval, double delay, | |||
bool repeat, bool simtime); | bool repeat, bool simtime); | |||
SGPropertyNode_ptr _freezeProp; | SGPropertyNode_ptr _freezeProp; | |||
SGPropertyNode_ptr _rtProp; | SGPropertyNode_ptr _rtProp; | |||
SGTimerQueue _rtQueue; | SGTimerQueue _rtQueue; | |||
SGTimerQueue _simQueue; | SGTimerQueue _simQueue; | |||
}; | }; | |||
#endif // _SG_EVENT_MGR_HXX | #endif // _SG_EVENT_MGR_HXX | |||
End of changes. 16 change blocks. | ||||
15 lines changed or deleted | 20 lines changed or added | |||
exception.hxx | exception.hxx | |||
---|---|---|---|---|
/** | /** | |||
* \file exception.hxx | * \file exception.hxx | |||
* Interface definition for SimGear base exceptions. | * Interface definition for SimGear base exceptions. | |||
* Started Spring 2001 by David Megginson, david@megginson.com | * Started Spring 2001 by David Megginson, david@megginson.com | |||
* This code is released into the Public Domain. | * This code is released into the Public Domain. | |||
* | * | |||
* $Id: exception.hxx,v 1.1 2003-09-24 17:19:23 ehofman Exp $ | * $Id$ | |||
*/ | */ | |||
#ifndef __SIMGEAR_MISC_EXCEPTION_HXX | #ifndef __SIMGEAR_MISC_EXCEPTION_HXX | |||
#define __SIMGEAR_MISC_EXCEPTION_HXX 1 | #define __SIMGEAR_MISC_EXCEPTION_HXX 1 | |||
#include <exception> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
SG_USING_STD(string); | class SGPath; | |||
/** | /** | |||
* Information encapsulating a single location in an external resource | * Information encapsulating a single location in an external resource | |||
* | * | |||
* A position in the resource my optionally be provided, either by | * A position in the resource my optionally be provided, either by | |||
* line number, line number and column number, or byte offset from the | * line number, line number and column number, or byte offset from the | |||
* beginning of the resource. | * beginning of the resource. | |||
*/ | */ | |||
class sg_location | class sg_location | |||
{ | { | |||
public: | public: | |||
enum {max_path = 1024}; | ||||
sg_location (); | sg_location (); | |||
sg_location (const string &path, int line = -1, int column = -1); | sg_location(const std::string& path, int line = -1, int column = -1); | |||
virtual ~sg_location (); | explicit sg_location(const char* path, int line = -1, int column = -1); | |||
virtual const string &getPath () const; | virtual ~sg_location() throw (); | |||
virtual void setPath (const string &path); | virtual const char* getPath() const; | |||
virtual void setPath (const char* path); | ||||
virtual int getLine () const; | virtual int getLine () const; | |||
virtual void setLine (int line); | virtual void setLine (int line); | |||
virtual int getColumn () const; | virtual int getColumn () const; | |||
virtual void setColumn (int column); | virtual void setColumn (int column); | |||
virtual int getByte () const; | virtual int getByte () const; | |||
virtual void setByte (int byte); | virtual void setByte (int byte); | |||
virtual string asString () const; | virtual std::string asString () const; | |||
private: | private: | |||
string _path; | char _path[max_path]; | |||
int _line; | int _line; | |||
int _column; | int _column; | |||
int _byte; | int _byte; | |||
}; | }; | |||
/** | /** | |||
* Abstract base class for all throwables. | * Abstract base class for all throwables. | |||
*/ | */ | |||
class sg_throwable | class sg_throwable : public std::exception | |||
{ | { | |||
public: | public: | |||
enum {MAX_TEXT_LEN = 1024}; | ||||
sg_throwable (); | sg_throwable (); | |||
sg_throwable (const string &message, const string &origin = ""); | sg_throwable (const char* message, const char* origin = 0); | |||
virtual ~sg_throwable (); | virtual ~sg_throwable () throw (); | |||
virtual const string &getMessage () const; | virtual const char* getMessage () const; | |||
virtual const string getFormattedMessage () const; | virtual const std::string getFormattedMessage () const; | |||
virtual void setMessage (const string &message); | virtual void setMessage (const char* message); | |||
virtual const string &getOrigin () const; | virtual const char* getOrigin () const; | |||
virtual void setOrigin (const string &origin); | virtual void setOrigin (const char *origin); | |||
virtual const char* what() const throw(); | ||||
private: | private: | |||
string _message; | char _message[MAX_TEXT_LEN]; | |||
string _origin; | char _origin[MAX_TEXT_LEN]; | |||
}; | }; | |||
/** | /** | |||
* An unexpected fatal error. | * An unexpected fatal error. | |||
* | * | |||
* Methods and functions show throw this exception when something | * Methods and functions show throw this exception when something | |||
* very bad has happened (such as memory corruption or | * very bad has happened (such as memory corruption or | |||
* a totally unexpected internal value). Applications should catch | * a totally unexpected internal value). Applications should catch | |||
* this exception only at the top level if at all, and should | * this exception only at the top level if at all, and should | |||
* normally terminate execution soon afterwards. | * normally terminate execution soon afterwards. | |||
*/ | */ | |||
class sg_error : public sg_throwable | class sg_error : public sg_throwable | |||
{ | { | |||
public: | public: | |||
sg_error (); | sg_error (); | |||
sg_error (const string &message, const string &origin = ""); | sg_error (const char* message, const char* origin = 0); | |||
virtual ~sg_error (); | sg_error (const std::string& message, const std::string& origin = ""); | |||
virtual ~sg_error () throw (); | ||||
}; | }; | |||
/** | /** | |||
* Base class for all SimGear exceptions. | * Base class for all SimGear exceptions. | |||
* | * | |||
* SimGear-based code should throw this exception only when no | * SimGear-based code should throw this exception only when no | |||
* more specific exception applies. It may not be caught until | * more specific exception applies. It may not be caught until | |||
* higher up in the application, where it is not possible to | * higher up in the application, where it is not possible to | |||
* resume normal operations if desired. | * resume normal operations if desired. | |||
* | * | |||
* A caller can catch sg_exception by default to ensure that | * A caller can catch sg_exception by default to ensure that | |||
* all exceptions are caught. Every SimGear exception can contain | * all exceptions are caught. Every SimGear exception can contain | |||
* a human-readable error message and a human-readable string | * a human-readable error message and a human-readable string | |||
* indicating the part of the application causing the exception | * indicating the part of the application causing the exception | |||
* (as an aid to debugging, only). | * (as an aid to debugging, only). | |||
*/ | */ | |||
class sg_exception : public sg_throwable | class sg_exception : public sg_throwable | |||
{ | { | |||
public: | public: | |||
sg_exception (); | sg_exception (); | |||
sg_exception (const string &message, const string &origin = ""); | sg_exception (const char* message, const char* origin = 0); | |||
virtual ~sg_exception (); | sg_exception (const std::string& message, const std::string& = ""); | |||
virtual ~sg_exception () throw (); | ||||
}; | }; | |||
/** | /** | |||
* An I/O-related SimGear exception. | * An I/O-related SimGear exception. | |||
* | * | |||
* SimGear-based code should throw this exception when it fails | * SimGear-based code should throw this exception when it fails | |||
* to read from or write to an external resource, such as a file, | * to read from or write to an external resource, such as a file, | |||
* socket, URL, or database. | * socket, URL, or database. | |||
* | * | |||
* In addition to the functionality of sg_exception, an | * In addition to the functionality of sg_exception, an | |||
* sg_io_exception may contain location information, such as the name | * sg_io_exception may contain location information, such as the name | |||
* of a file or URL, and possible also a location in that file or URL. | * of a file or URL, and possible also a location in that file or URL. | |||
*/ | */ | |||
class sg_io_exception : public sg_exception | class sg_io_exception : public sg_exception | |||
{ | { | |||
public: | public: | |||
sg_io_exception (); | sg_io_exception (); | |||
sg_io_exception (const string &message, const string &origin = ""); | sg_io_exception (const char* message, const char* origin = 0); | |||
sg_io_exception (const string &message, const sg_location &location, | sg_io_exception (const char* message, const sg_location &location, | |||
const string &origin = ""); | const char* origin = 0); | |||
virtual ~sg_io_exception (); | sg_io_exception (const std::string &message, const std::string &origin = | |||
virtual const string getFormattedMessage () const; | ""); | |||
sg_io_exception (const std::string &message, const sg_location &location, | ||||
const std::string &origin = ""); | ||||
sg_io_exception (const std::string &message, const SGPath& origin); | ||||
virtual ~sg_io_exception () throw (); | ||||
virtual const std::string getFormattedMessage () const; | ||||
virtual const sg_location &getLocation () const; | virtual const sg_location &getLocation () const; | |||
virtual void setLocation (const sg_location &location); | virtual void setLocation (const sg_location &location); | |||
private: | private: | |||
sg_location _location; | sg_location _location; | |||
}; | }; | |||
/** | /** | |||
* A format-related SimGear exception. | * A format-related SimGear exception. | |||
* | * | |||
* SimGear-based code should throw this exception when a string | * SimGear-based code should throw this exception when a string | |||
skipping to change at line 146 | skipping to change at line 158 | |||
* string does not conform to ISO 8601). | * string does not conform to ISO 8601). | |||
* | * | |||
* In addition to the functionality of sg_exception, an | * In addition to the functionality of sg_exception, an | |||
* sg_format_exception can contain a copy of the original malformated | * sg_format_exception can contain a copy of the original malformated | |||
* text. | * text. | |||
*/ | */ | |||
class sg_format_exception : public sg_exception | class sg_format_exception : public sg_exception | |||
{ | { | |||
public: | public: | |||
sg_format_exception (); | sg_format_exception (); | |||
sg_format_exception (const string &message, const string &text, | sg_format_exception (const char* message, const char* text, | |||
const string &origin = ""); | const char* origin = 0); | |||
virtual ~sg_format_exception (); | sg_format_exception (const std::string& message, const std::string& text, | |||
virtual const string &getText () const; | const std::string& origin = ""); | |||
virtual void setText (const string &text); | virtual ~sg_format_exception () throw (); | |||
virtual const char* getText () const; | ||||
virtual void setText (const char* text); | ||||
private: | private: | |||
string _text; | char _text[MAX_TEXT_LEN]; | |||
}; | }; | |||
/** | /** | |||
* A range-related SimGear exception. | * A range-related SimGear exception. | |||
* | * | |||
* SimGear-based code should throw this exception when a value falls | * SimGear-based code should throw this exception when a value falls | |||
* outside the range where it can reasonably be handled; examples | * outside the range where it can reasonably be handled; examples | |||
* include longitude outside the range -180:180, unrealistically high | * include longitude outside the range -180:180, unrealistically high | |||
* forces or velocities, an illegal airport code, etc. A range | * forces or velocities, an illegal airport code, etc. A range | |||
* exception usually means that something has gone wrong internally. | * exception usually means that something has gone wrong internally. | |||
*/ | */ | |||
class sg_range_exception : public sg_exception | class sg_range_exception : public sg_exception | |||
{ | { | |||
public: | public: | |||
sg_range_exception (); | sg_range_exception (); | |||
sg_range_exception (const string &message, const string &origin = ""); | sg_range_exception (const char* message, | |||
virtual ~sg_range_exception (); | const char* origin = 0); | |||
sg_range_exception (const std::string& message, | ||||
const std::string& origin = ""); | ||||
virtual ~sg_range_exception () throw (); | ||||
}; | }; | |||
#endif | #endif | |||
// end of exception.hxx | // end of exception.hxx | |||
End of changes. 18 change blocks. | ||||
36 lines changed or deleted | 54 lines changed or added | |||
extensions.hxx | extensions.hxx | |||
---|---|---|---|---|
skipping to change at line 27 | skipping to change at line 27 | |||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
* CESAR BLECUA UDIAS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | * CESAR BLECUA UDIAS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT O F | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT O F | |||
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
* SOFTWARE. | * SOFTWARE. | |||
* | * | |||
*/ | */ | |||
#ifndef __SG_EXTENSIONS_HXX | #ifndef __SG_EXTENSIONS_HXX | |||
#define __SG_EXTENSIONS_HXX 1 | #define __SG_EXTENSIONS_HXX 1 | |||
#if defined(__CYGWIN__) && !defined(WIN32) /* && !defined(USING_X) */ | ||||
#define WIN32 | ||||
#endif | ||||
#if defined(WIN32) /* MINGW and MSC predefine WIN32 */ | ||||
# include <windows.h> | ||||
#endif | ||||
#if !defined(WIN32) | ||||
# include <dlfcn.h> | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include SG_GL_H | ||||
#if defined(__cplusplus) | ||||
extern "C" { | ||||
#endif | ||||
#ifndef APIENTRY | ||||
#define APIENTRY | ||||
#endif | ||||
bool SGSearchExtensionsString(const char *extString, const char *extName); | bool SGSearchExtensionsString(const char *extString, const char *extName); | |||
bool SGIsOpenGLExtensionSupported(char *extName); | bool SGIsOpenGLExtensionSupported(const char *extName); | |||
#ifdef __APPLE__ | ||||
// don't use an inline function for symbol lookup, since it is too big | ||||
void* macosxGetGLProcAddress(const char *func); | ||||
#elif !defined( WIN32 ) | ||||
void *SGGetGLProcAddress(const char *func); | ||||
#endif | ||||
inline void (*SGLookupFunction(const char *func))() | ||||
{ | ||||
#if defined( WIN32 ) | ||||
return (void (*)()) wglGetProcAddress(func); | ||||
#elif defined( __APPLE__ ) | ||||
return (void (*)()) macosxGetGLProcAddress(func); | ||||
#else // UNIX | ||||
return (void (*)()) SGGetGLProcAddress(func); | ||||
#endif | ||||
} | ||||
/* | ||||
* OpenGL 1.2 and 1.3 enumerants | ||||
*/ | ||||
#ifndef GL_VERSION_1_2 | ||||
#define GL_CLAMP_TO_EDGE 0x812F | ||||
#define GL_TEXTURE_WRAP_R 0x8072 | ||||
#define GL_BLEND_EQUATION 0x8009 | ||||
#define GL_MIN 0x8007 | ||||
#define GL_MAX 0x8008 | ||||
#define GL_FUNC_ADD 0x8006 | ||||
#define GL_FUNC_SUBTRACT 0x800A | ||||
#define GL_FUNC_REVERSE_SUBTRACT 0x800B | ||||
#define GL_BLEND_COLOR 0x8005 | ||||
#define GL_CONSTANT_COLOR 0x8001 | ||||
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 | ||||
#define GL_CONSTANT_ALPHA 0x8003 | ||||
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 | ||||
#endif | ||||
typedef void (APIENTRY * glBlendEquationProc) (GLenum mode ); | ||||
typedef void (APIENTRY * glBlendColorProc) (GLclampf red, GLclampf green, G | ||||
Lclampf blue, GLclampf alpha ); | ||||
/* OpenGL extension declarations */ | ||||
/* | ||||
* glPointParameterf and glPointParameterfv | ||||
*/ | ||||
#ifndef GL_EXT_point_parameters | ||||
#define GL_EXT_point_parameters 1 | ||||
#define GL_POINT_SIZE_MIN_EXT 0x8126 | ||||
#define GL_DISTANCE_ATTENUATION_EXT 0x8129 | ||||
#endif | ||||
#ifndef GL_ARB_point_parameters | ||||
#define GL_ARB_point_parameters 1 | ||||
#define GL_POINT_SIZE_MIN_ARB 0x8126 | ||||
#define GL_DISTANCE_ATTENUATION_ARB 0x8129 | ||||
#endif | ||||
typedef void (APIENTRY * glPointParameterfProc)(GLenum pname, GLfloat param | ||||
); | ||||
typedef void (APIENTRY * glPointParameterfvProc)(GLenum pname, const GLfloa | ||||
t *params); | ||||
/* | ||||
* glActiveTextureARB | ||||
*/ | ||||
#ifndef GL_ARB_multitexture | ||||
#define GL_ARB_multitexture 1 | ||||
#define GL_TEXTURE0_ARB 0x84 | ||||
C0 | ||||
#define GL_TEXTURE1_ARB 0x84 | ||||
C1 | ||||
#define GL_TEXTURE2_ARB 0x84 | ||||
C2 | ||||
#define GL_TEXTURE3_ARB 0x84 | ||||
C3 | ||||
#define GL_TEXTURE4_ARB 0x84 | ||||
C4 | ||||
#define GL_TEXTURE5_ARB 0x84 | ||||
C5 | ||||
#define GL_TEXTURE6_ARB 0x84 | ||||
C6 | ||||
#define GL_TEXTURE7_ARB 0x84 | ||||
C7 | ||||
#define GL_TEXTURE8_ARB 0x84 | ||||
C8 | ||||
#define GL_TEXTURE9_ARB 0x84 | ||||
C9 | ||||
#define GL_TEXTURE10_ARB 0x84CA | ||||
#define GL_TEXTURE11_ARB 0x84CB | ||||
#define GL_TEXTURE12_ARB 0x84CC | ||||
#define GL_TEXTURE13_ARB 0x84CD | ||||
#define GL_TEXTURE14_ARB 0x84CE | ||||
#define GL_TEXTURE15_ARB 0x84CF | ||||
#define GL_TEXTURE16_ARB 0x84D0 | ||||
#define GL_TEXTURE17_ARB 0x84D1 | ||||
#define GL_TEXTURE18_ARB 0x84D2 | ||||
#define GL_TEXTURE19_ARB 0x84D3 | ||||
#define GL_TEXTURE20_ARB 0x84D4 | ||||
#define GL_TEXTURE21_ARB 0x84D5 | ||||
#define GL_TEXTURE22_ARB 0x84D6 | ||||
#define GL_TEXTURE23_ARB 0x84D7 | ||||
#define GL_TEXTURE24_ARB 0x84D8 | ||||
#define GL_TEXTURE25_ARB 0x84D9 | ||||
#define GL_TEXTURE26_ARB 0x84DA | ||||
#define GL_TEXTURE27_ARB 0x84DB | ||||
#define GL_TEXTURE28_ARB 0x84DC | ||||
#define GL_TEXTURE29_ARB 0x84DD | ||||
#define GL_TEXTURE30_ARB 0x84DE | ||||
#define GL_TEXTURE31_ARB 0x84DF | ||||
#define GL_ACTIVE_TEXTURE_ARB 0x84E0 | ||||
#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 | ||||
#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 | ||||
#endif | ||||
typedef void (APIENTRY * glActiveTextureProc)(GLenum texture); | ||||
typedef void (APIENTRY * glClientActiveTextureProc)(GLenum texture); | ||||
/* | ||||
* GL_EXT_separate_specular_color | ||||
*/ | ||||
#ifndef GL_LIGHT_MODEL_COLOR_CONTROL | ||||
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 | ||||
#define GL_SINGLE_COLOR 0x81 | ||||
F9 | ||||
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA | ||||
#endif | ||||
/* | ||||
* GL_ARB_texture_cube_map | ||||
*/ | ||||
#ifndef GL_ARB_texture_cube_map | ||||
#define GL_ARB_texture_cube_map 1 | ||||
#define GL_NORMAL_MAP_ARB 0x8511 | ||||
#define GL_REFLECTION_MAP_ARB 0x8512 | ||||
#define GL_TEXTURE_CUBE_MAP_ARB 0x85 | ||||
13 | ||||
#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x85 | ||||
14 | ||||
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 | ||||
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 | ||||
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 | ||||
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 | ||||
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 | ||||
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A | ||||
#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B | ||||
#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C | ||||
#endif | ||||
/* | ||||
* GL_ARB_texture_env_combine | ||||
*/ | ||||
#ifndef GL_ARB_texture_env_combine | ||||
#define GL_ARB_texture_env_combine 1 | ||||
#define GL_COMBINE_ARB 0x8570 | ||||
#define GL_COMBINE_RGB_ARB 0x8571 | ||||
#define GL_COMBINE_ALPHA_ARB 0x8572 | ||||
#define GL_RGB_SCALE_ARB 0x8573 | ||||
#define GL_ADD_SIGNED_ARB 0x8574 | ||||
#define GL_INTERPOLATE_ARB 0x8575 | ||||
#define GL_SUBTRACT_ARB 0x84E7 | ||||
#define GL_CONSTANT_ARB 0x85 | ||||
76 | ||||
#define GL_PRIMARY_COLOR_ARB 0x8577 | ||||
#define GL_PREVIOUS_ARB 0x85 | ||||
78 | ||||
#define GL_SOURCE0_RGB_ARB 0x8580 | ||||
#define GL_SOURCE1_RGB_ARB 0x8581 | ||||
#define GL_SOURCE2_RGB_ARB 0x8582 | ||||
#define GL_SOURCE0_ALPHA_ARB 0x8588 | ||||
#define GL_SOURCE1_ALPHA_ARB 0x8589 | ||||
#define GL_SOURCE2_ALPHA_ARB 0x858A | ||||
#define GL_OPERAND0_RGB_ARB 0x8590 | ||||
#define GL_OPERAND1_RGB_ARB 0x8591 | ||||
#define GL_OPERAND2_RGB_ARB 0x8592 | ||||
#define GL_OPERAND0_ALPHA_ARB 0x8598 | ||||
#define GL_OPERAND1_ALPHA_ARB 0x8599 | ||||
#define GL_OPERAND2_ALPHA_ARB 0x859A | ||||
#endif | ||||
/* | ||||
* GL_ARB_texture_env_dot3 | ||||
*/ | ||||
#ifndef GL_ARB_texture_env_dot3 | ||||
#define GL_ARB_texture_env_dot3 1 | ||||
#define GL_DOT3_RGB_ARB 0x86 | ||||
AE | ||||
#define GL_DOT3_RGBA_ARB 0x86AF | ||||
#endif | ||||
/* | ||||
* ARB_depth_texture | ||||
*/ | ||||
#ifndef GL_ARB_depth_texture | ||||
#define GL_ARB_depth_texture 1 | ||||
#define GL_DEPTH_COMPONENT16_ARB 0x81A5 | ||||
#define GL_DEPTH_COMPONENT24_ARB 0x81A6 | ||||
#define GL_DEPTH_COMPONENT32_ARB 0x81A7 | ||||
#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A | ||||
#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B | ||||
#endif | ||||
/* | ||||
* ARB_multisample | ||||
*/ | ||||
#ifndef GL_ARB_multisample | ||||
#define GL_ARB_multisample 1 | ||||
#define GL_MULTISAMPLE_ARB 0x809D | ||||
#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x80 | ||||
9E | ||||
#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F | ||||
#define GL_SAMPLE_COVERAGE_ARB 0x80A0 | ||||
#define GL_SAMPLE_BUFFERS_ARB 0x80A8 | ||||
#define GL_SAMPLES_ARB 0x80A9 | ||||
#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA | ||||
#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB | ||||
#define GL_MULTISAMPLE_BIT_ARB 0x20000000 | ||||
#define GL_DOUBLEBUFFER 0x0C | ||||
32 | ||||
#define GL_AUX_BUFFERS 0x0C00 | ||||
#define WGL_SAMPLE_BUFFERS_ARB 0x2041 | ||||
#define WGL_SAMPLES_ARB 0x20 | ||||
42 | ||||
#endif | ||||
#ifndef GL_SGIS_generate_mipmap | ||||
#define GL_SGIS_generate_mipmap 1 | ||||
#define GL_GENERATE_MIPMAP_SGIS 0x81 | ||||
91 | ||||
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 | ||||
#endif | ||||
/* WGL spcific OpenGL extenstions */ | ||||
#ifdef WIN32 | ||||
/* | ||||
* WGL_ARB_extensions_string | ||||
*/ | ||||
#ifndef WGL_ARB_extensions_string | ||||
#define WGL_ARB_extensions_string 1 | ||||
typedef const char * (APIENTRY * wglGetExtensionsStringARBProc) (HDC hDC); | ||||
#endif | ||||
/* | ||||
* WGL_ARB_pbuffer | ||||
*/ | ||||
#ifndef WGL_ARB_pbuffer | ||||
#define WGL_ARB_pbuffer 1 | ||||
#define WGL_DRAW_TO_PBUFFER_ARB 0x20 | ||||
2D | ||||
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E | ||||
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F | ||||
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 | ||||
#define WGL_PBUFFER_LARGEST_ARB 0x20 | ||||
33 | ||||
#define WGL_PBUFFER_WIDTH_ARB 0x2034 | ||||
#define WGL_PBUFFER_HEIGHT_ARB 0x2035 | ||||
#define WGL_PBUFFER_LOST_ARB 0x2036 | ||||
DECLARE_HANDLE(HPBUFFERARB); | ||||
typedef HPBUFFERARB (APIENTRY * wglCreatePbufferARBProc) (HDC hDC, int iPix | ||||
elFormat, int iWidth, int iHeight, const int *piAttribList); | ||||
typedef HDC (APIENTRY * wglGetPbufferDCARBProc) (HPBUFFERARB hPbuffer); | ||||
typedef int (APIENTRY * wglReleasePbufferDCARBProc) (HPBUFFERARB hPbuffer, | ||||
HDC hDC); | ||||
typedef BOOL (APIENTRY * wglDestroyPbufferARBProc) (HPBUFFERARB hPbuffer); | ||||
typedef BOOL (APIENTRY * wglQueryPbufferARBProc) (HPBUFFERARB hPbuffer, int | ||||
iAttribute, int *piValue); | ||||
#endif | ||||
/* | ||||
* ARB_pixel_format | ||||
*/ | ||||
#ifndef WGL_ARB_pixel_format | ||||
#define WGL_ARB_pixel_format 1 | ||||
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 | ||||
#define WGL_DRAW_TO_WINDOW_ARB 0x2001 | ||||
#define WGL_DRAW_TO_BITMAP_ARB 0x2002 | ||||
#define WGL_ACCELERATION_ARB 0x2003 | ||||
#define WGL_NEED_PALETTE_ARB 0x2004 | ||||
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 | ||||
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 | ||||
#define WGL_SWAP_METHOD_ARB 0x2007 | ||||
#define WGL_NUMBER_OVERLAYS_ARB 0x20 | ||||
08 | ||||
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 | ||||
#define WGL_TRANSPARENT_ARB 0x200A | ||||
#define WGL_SHARE_DEPTH_ARB 0x200C | ||||
#define WGL_SHARE_STENCIL_ARB 0x200D | ||||
#define WGL_SHARE_ACCUM_ARB 0x200E | ||||
#define WGL_SUPPORT_GDI_ARB 0x200F | ||||
#define WGL_SUPPORT_OPENGL_ARB 0x2010 | ||||
#define WGL_DOUBLE_BUFFER_ARB 0x2011 | ||||
#define WGL_STEREO_ARB 0x2012 | ||||
#define WGL_PIXEL_TYPE_ARB 0x2013 | ||||
#define WGL_COLOR_BITS_ARB 0x2014 | ||||
#define WGL_RED_BITS_ARB 0x2015 | ||||
#define WGL_RED_SHIFT_ARB 0x2016 | ||||
#define WGL_GREEN_BITS_ARB 0x2017 | ||||
#define WGL_GREEN_SHIFT_ARB 0x2018 | ||||
#define WGL_BLUE_BITS_ARB 0x2019 | ||||
#define WGL_BLUE_SHIFT_ARB 0x201A | ||||
#define WGL_ALPHA_BITS_ARB 0x201B | ||||
#define WGL_ALPHA_SHIFT_ARB 0x201C | ||||
#define WGL_ACCUM_BITS_ARB 0x201D | ||||
#define WGL_ACCUM_RED_BITS_ARB 0x201E | ||||
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F | ||||
#define WGL_ACCUM_BLUE_BITS_ARB 0x20 | ||||
20 | ||||
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 | ||||
#define WGL_DEPTH_BITS_ARB 0x2022 | ||||
#define WGL_STENCIL_BITS_ARB 0x2023 | ||||
#define WGL_AUX_BUFFERS_ARB 0x2024 | ||||
#define WGL_NO_ACCELERATION_ARB 0x20 | ||||
25 | ||||
#define WGL_GENERIC_ACCELERATION_ARB 0x2026 | ||||
#define WGL_FULL_ACCELERATION_ARB 0x2027 | ||||
#define WGL_SWAP_EXCHANGE_ARB 0x2028 | ||||
#define WGL_SWAP_COPY_ARB 0x2029 | ||||
#define WGL_SWAP_UNDEFINED_ARB 0x202A | ||||
#define WGL_TYPE_RGBA_ARB 0x202B | ||||
#define WGL_TYPE_COLORINDEX_ARB 0x20 | ||||
2C | ||||
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 | ||||
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x20 | ||||
38 | ||||
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 | ||||
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x20 | ||||
3A | ||||
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x20 | ||||
3B | ||||
typedef BOOL (APIENTRY * wglGetPixelFormatAttribivARBProc) (HDC hdc, int iP | ||||
ixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int | ||||
*piValues); | ||||
typedef BOOL (APIENTRY * wglGetPixelFormatAttribfvARBProc) (HDC hdc, int iP | ||||
ixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLO | ||||
AT *pfValues); | ||||
typedef BOOL (APIENTRY * wglChoosePixelFormatARBProc) (HDC hdc, const int * | ||||
piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats | ||||
, UINT *nNumFormats); | ||||
#endif | ||||
/* | ||||
* ARB_render_texture | ||||
*/ | ||||
#ifndef WGL_ARB_render_texture | ||||
#define WGL_ARB_render_texture 1 | ||||
#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 | ||||
#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 | ||||
#define WGL_TEXTURE_FORMAT_ARB 0x2072 | ||||
#define WGL_TEXTURE_TARGET_ARB 0x2073 | ||||
#define WGL_MIPMAP_TEXTURE_ARB 0x2074 | ||||
#define WGL_TEXTURE_RGB_ARB 0x2075 | ||||
#define WGL_TEXTURE_RGBA_ARB 0x2076 | ||||
#define WGL_NO_TEXTURE_ARB 0x2077 | ||||
#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 | ||||
#define WGL_TEXTURE_1D_ARB 0x2079 | ||||
#define WGL_TEXTURE_2D_ARB 0x207A | ||||
#define WGL_NO_TEXTURE_ARB 0x2077 | ||||
#define WGL_MIPMAP_LEVEL_ARB 0x207B | ||||
#define WGL_CUBE_MAP_FACE_ARB 0x207C | ||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D | ||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E | ||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F | ||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 | ||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 | ||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 | ||||
#define WGL_FRONT_LEFT_ARB 0x2083 | ||||
#define WGL_FRONT_RIGHT_ARB 0x2084 | ||||
#define WGL_BACK_LEFT_ARB 0x2085 | ||||
#define WGL_BACK_RIGHT_ARB 0x2086 | ||||
#define WGL_AUX0_ARB 0x2087 | ||||
#define WGL_AUX1_ARB 0x2088 | ||||
#define WGL_AUX2_ARB 0x2089 | ||||
#define WGL_AUX3_ARB 0x208A | ||||
#define WGL_AUX4_ARB 0x208B | ||||
#define WGL_AUX5_ARB 0x208C | ||||
#define WGL_AUX6_ARB 0x208D | ||||
#define WGL_AUX7_ARB 0x208E | ||||
#define WGL_AUX8_ARB 0x208F | ||||
#define WGL_AUX9_ARB 0x2090 | ||||
typedef BOOL (APIENTRY * wglBindTexImageARBProc) (HPBUFFERARB hPbuffer, int | ||||
iBuffer); | ||||
typedef BOOL (APIENTRY * wglReleaseTexImageARBProc) (HPBUFFERARB hPbuffer, | ||||
int iBuffer); | ||||
typedef BOOL (APIENTRY * wglSetPbufferAttribARBProc) (HPBUFFERARB hPbuffer, | ||||
const int *piAttribList); | ||||
#endif | ||||
#elif !defined(__APPLE__) /* !WIN32 */ | ||||
/* GLX pcific OpenGL extenstions */ | ||||
#include <GL/glx.h> | ||||
#ifndef GLX_ARB_multisample | ||||
#define GLX_ARB_multisample1 | ||||
#define GLX_SAMPLE_BUFFERS_ARB 100001 | ||||
#define GLX_SAMPLES_ARB 1000 | ||||
00 | ||||
#endif | ||||
#ifndef GLX_SGIX_pbuffer | ||||
#define GLX_SGIX_pbuffer 1 | ||||
#define GLX_DOUBLEBUFFER 5 | ||||
#define GLX_AUX_BUFFERS 0x00 | ||||
000010 | ||||
#endif | ||||
#ifndef GLXPbuffer | ||||
# ifdef GLXPbufferSGIX | ||||
# define GLXPbuffer GLXPbufferSGIX | ||||
# endif | ||||
#endif | ||||
#ifndef GLXFBConfig | ||||
# ifdef GLXFBConfigSGIX | ||||
# define GLXFBConfig GLXFBConfigSGIX | ||||
# endif | ||||
#endif | ||||
typedef GLXFBConfig *(*glXChooseFBConfigProc) (Display *dpy, int screen, in | ||||
t *attribList, int *nitems); | ||||
typedef GLXPbuffer (*glXCreateGLXPbufferProc) (Display *dpy, GLXFBConfig co | ||||
nfig, unsigned int width, unsigned int height, int *attrib_list); | ||||
typedef GLXPbuffer (*glXCreatePbufferProc) (Display *dpy, GLXFBConfig confi | ||||
g, int *attrib_list); | ||||
typedef XVisualInfo *(*glXGetVisualFromFBConfigProc) (Display *dpy, GLXFBCo | ||||
nfig config); | ||||
typedef GLXContext (*glXCreateContextWithConfigProc) (Display *dpy, GLXFBC | ||||
onfig config, int render_type, GLXContext share_list, Bool direct); | ||||
typedef GLXContext (*glXCreateContextProc) (Display *dpy, XVisualInfo *vis, | ||||
GLXContext shareList, Bool direct); | ||||
typedef void (*glXDestroyPbufferProc) (Display *dpy, GLXPbuffer pbuf); | ||||
typedef int (*glXQueryGLXPbufferSGIXProc) (Display *, GLXPbuffer, int, unsi | ||||
gned int *); | ||||
typedef void (*glXQueryDrawableProc) (Display *, GLXDrawable, int, unsigned | ||||
int *); | ||||
#endif /* WIN32 */ | ||||
/* NVIDIA specific extension */ | ||||
/* | ||||
* NV_texture_rectangle | ||||
*/ | ||||
#ifndef GL_NV_texture_rectangle | ||||
#define GL_NV_texture_rectangle 1 | ||||
#define GL_TEXTURE_RECTANGLE_NV 0x84 | ||||
F5 | ||||
#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84 | ||||
F6 | ||||
#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 | ||||
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 | ||||
#endif | ||||
/* | ||||
* NV_texture_rectangle | ||||
*/ | ||||
#ifndef GL_EXT_texture_rectangle | ||||
#define GL_EXT_texture_rectangle 1 | ||||
#define GL_TEXTURE_RECTANGLE_EXT 0x84F5 | ||||
#define GL_TEXTURE_BINDING_RECTANGLE_EXT 0x84F6 | ||||
#define GL_PROXY_TEXTURE_RECTANGLE_EXT 0x84F7 | ||||
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT 0x84F8 | ||||
#endif | ||||
/* | ||||
* WGL_NV_texture_rectangle | ||||
*/ | ||||
#ifndef WGL_NV_texture_rectangle | ||||
#define WGL_NV_texture_rectangle 1 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 | ||||
#define WGL_TEXTURE_RECTANGLE_NV 0x20A2 | ||||
#endif | ||||
/* | ||||
* NV_render_depth_texture | ||||
*/ | ||||
#ifndef WGL_NV_render_depth_texture | ||||
#define WGL_NV_render_depth_texture 1 | ||||
#define WGL_NO_TEXTURE_ARB 0x2077 | ||||
#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 | ||||
#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 | ||||
#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 | ||||
#define WGL_DEPTH_COMPONENT_NV 0x20A7 | ||||
#endif | ||||
/* | ||||
* NV_float_buffer | ||||
*/ | ||||
#ifndef GL_NV_float_buffer | ||||
#define GL_NV_float_buffer 1 | ||||
#define GL_FLOAT_R_NV 0x8880 | ||||
#define GL_FLOAT_RG_NV 0x8881 | ||||
#define GL_FLOAT_RGB_NV 0x88 | ||||
82 | ||||
#define GL_FLOAT_RGBA_NV 0x8883 | ||||
#define GL_FLOAT_R16_NV 0x88 | ||||
84 | ||||
#define GL_FLOAT_R32_NV 0x88 | ||||
85 | ||||
#define GL_FLOAT_RG16_NV 0x8886 | ||||
#define GL_FLOAT_RG32_NV 0x8887 | ||||
#define GL_FLOAT_RGB16_NV 0x8888 | ||||
#define GL_FLOAT_RGB32_NV 0x8889 | ||||
#define GL_FLOAT_RGBA16_NV 0x888A | ||||
#define GL_FLOAT_RGBA32_NV 0x888B | ||||
#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C | ||||
#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D | ||||
#define GL_FLOAT_RGBA_MODE_NV 0x888E | ||||
#endif | ||||
#ifndef GLX_NV_float_buffer | ||||
#define GLX_NV_float_buffer 1 | ||||
#define GLX_FLOAT_COMPONENTS_NV 0x20 | ||||
B0 | ||||
#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 | ||||
#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 | ||||
#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 | ||||
#define GLX_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 | ||||
#define GLX_TEXTURE_FLOAT_R_NV 0x20B5 | ||||
#define GLX_TEXTURE_FLOAT_RG_NV 0x20 | ||||
B6 | ||||
#define GLX_TEXTURE_FLOAT_RGB_NV 0x20B7 | ||||
#define GLX_TEXTURE_FLOAT_RGBA_NV 0x20B8 | ||||
#endif | ||||
#ifndef WGL_NV_float_buffer | ||||
#define WGL_NV_float_buffer 1 | ||||
#define WGL_FLOAT_COMPONENTS_NV 0x20 | ||||
B0 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 | ||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 | ||||
#define WGL_TEXTURE_FLOAT_R_NV 0x20B5 | ||||
#define WGL_TEXTURE_FLOAT_RG_NV 0x20 | ||||
B6 | ||||
#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 | ||||
#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 | ||||
#endif | ||||
/* ATI specific extension */ | ||||
/* | ||||
* ATI_pixel_format_float | ||||
*/ | ||||
#ifndef WGL_ATI_pixel_format_float | ||||
#define WGL_ATI_pixel_format_float 1 | ||||
#define WGL_TYPE_RGBA_FLOAT_ATI 0x21 | ||||
A0 | ||||
#define GL_RGBA_FLOAT_MODE_ATI 0x8820 | ||||
#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 | ||||
#endif | ||||
/* | ||||
* ATI_texture_float | ||||
*/ | ||||
#ifndef GL_ATI_texture_float | ||||
#define GL_ATI_texture_float 1 | ||||
#define GL_RGBA_FLOAT32_ATI 0x8814 | ||||
#define GL_RGB_FLOAT32_ATI 0x8815 | ||||
#define GL_ALPHA_FLOAT32_ATI 0x8816 | ||||
#define GL_INTENSITY_FLOAT32_ATI 0x8817 | ||||
#define GL_LUMINANCE_FLOAT32_ATI 0x8818 | ||||
#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 | ||||
#define GL_RGBA_FLOAT16_ATI 0x881A | ||||
#define GL_RGB_FLOAT16_ATI 0x881B | ||||
#define GL_ALPHA_FLOAT16_ATI 0x881C | ||||
#define GL_INTENSITY_FLOAT16_ATI 0x881D | ||||
#define GL_LUMINANCE_FLOAT16_ATI 0x881E | ||||
#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F | ||||
#endif | ||||
/* | ||||
* ARB point sprite | ||||
*/ | ||||
#ifndef GL_ARB_point_sprite | ||||
#define GL_ARB_point_sprite 1 | ||||
#define GL_POINT_SPRITE_ARB 0x8861 | ||||
#define GL_COORD_REPLACE_ARB 0x8862 | ||||
#endif | ||||
#ifndef GL_NV_point_sprite | ||||
#define GL_NV_point_sprite 1 | ||||
#define GL_POINT_SPRITE_NV 0x8861 | ||||
#define GL_COORD_REPLACE_NV 0x8862 | ||||
#define GL_POINT_SPRITE_R_MODE_NV 0x8863 | ||||
#endif | ||||
#ifndef GL_VERSION_2_0 | ||||
#define GL_POINT_SPRITE 0x8861 | ||||
#define GL_COORD_REPLACE 0x8862 | ||||
#endif | ||||
/* | ||||
* ARB_vertex_program | ||||
*/ | ||||
#ifndef GL_ARB_vertex_program | ||||
#define GL_ARB_vertex_program 1 | ||||
#define GL_COLOR_SUM_ARB 0x8458 | ||||
#define GL_VERTEX_PROGRAM_ARB 0x8620 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 | ||||
#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 | ||||
#define GL_PROGRAM_LENGTH_ARB 0x8627 | ||||
#define GL_PROGRAM_STRING_ARB 0x8628 | ||||
#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E | ||||
#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F | ||||
#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 | ||||
#define GL_CURRENT_MATRIX_ARB 0x8641 | ||||
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 | ||||
#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 | ||||
#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B | ||||
#define GL_PROGRAM_BINDING_ARB 0x8677 | ||||
#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 | ||||
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A | ||||
#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 | ||||
#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 | ||||
#define GL_PROGRAM_FORMAT_ARB 0x8876 | ||||
#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 | ||||
#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 | ||||
#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 | ||||
#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 | ||||
#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 | ||||
#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 | ||||
#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 | ||||
#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 | ||||
#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 | ||||
#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 | ||||
#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA | ||||
#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB | ||||
#define GL_PROGRAM_ATTRIBS_ARB 0x88AC | ||||
#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD | ||||
#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE | ||||
#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF | ||||
#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 | ||||
#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 | ||||
#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 | ||||
#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 | ||||
#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 | ||||
#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 | ||||
#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 | ||||
#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 | ||||
#define GL_MATRIX0_ARB 0x88C0 | ||||
#define GL_MATRIX1_ARB 0x88C1 | ||||
#define GL_MATRIX2_ARB 0x88C2 | ||||
#define GL_MATRIX3_ARB 0x88C3 | ||||
#define GL_MATRIX4_ARB 0x88C4 | ||||
#define GL_MATRIX5_ARB 0x88C5 | ||||
#define GL_MATRIX6_ARB 0x88C6 | ||||
#define GL_MATRIX7_ARB 0x88C7 | ||||
#define GL_MATRIX8_ARB 0x88C8 | ||||
#define GL_MATRIX9_ARB 0x88C9 | ||||
#define GL_MATRIX10_ARB 0x88CA | ||||
#define GL_MATRIX11_ARB 0x88CB | ||||
#define GL_MATRIX12_ARB 0x88CC | ||||
#define GL_MATRIX13_ARB 0x88CD | ||||
#define GL_MATRIX14_ARB 0x88CE | ||||
#define GL_MATRIX15_ARB 0x88CF | ||||
#define GL_MATRIX16_ARB 0x88D0 | ||||
#define GL_MATRIX17_ARB 0x88D1 | ||||
#define GL_MATRIX18_ARB 0x88D2 | ||||
#define GL_MATRIX19_ARB 0x88D3 | ||||
#define GL_MATRIX20_ARB 0x88D4 | ||||
#define GL_MATRIX21_ARB 0x88D5 | ||||
#define GL_MATRIX22_ARB 0x88D6 | ||||
#define GL_MATRIX23_ARB 0x88D7 | ||||
#define GL_MATRIX24_ARB 0x88D8 | ||||
#define GL_MATRIX25_ARB 0x88D9 | ||||
#define GL_MATRIX26_ARB 0x88DA | ||||
#define GL_MATRIX27_ARB 0x88DB | ||||
#define GL_MATRIX28_ARB 0x88DC | ||||
#define GL_MATRIX29_ARB 0x88DD | ||||
#define GL_MATRIX30_ARB 0x88DE | ||||
#define GL_MATRIX31_ARB 0x88DF | ||||
#endif | ||||
/* | ||||
* ARB_fragment_program | ||||
*/ | ||||
#ifndef GL_ARB_fragment_program | ||||
#define GL_ARB_fragment_program 1 | ||||
#define GL_FRAGMENT_PROGRAM_ARB 0x8804 | ||||
#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 | ||||
#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 | ||||
#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 | ||||
#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 | ||||
#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 | ||||
#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A | ||||
#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B | ||||
#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C | ||||
#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D | ||||
#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E | ||||
#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F | ||||
#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 | ||||
#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 | ||||
#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 | ||||
#endif | ||||
typedef void (APIENTRY * glVertexAttrib1dProc) (GLuint index, GLdouble x); | ||||
typedef void (APIENTRY * glVertexAttrib1dvProc) (GLuint index, const GLdoub | ||||
le *v); | ||||
typedef void (APIENTRY * glVertexAttrib1fProc) (GLuint index, GLfloat x); | ||||
typedef void (APIENTRY * glVertexAttrib1fvProc) (GLuint index, const GLfloa | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib1sProc) (GLuint index, GLshort x); | ||||
typedef void (APIENTRY * glVertexAttrib1svProc) (GLuint index, const GLshor | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib2dProc) (GLuint index, GLdouble x, G | ||||
Ldouble y); | ||||
typedef void (APIENTRY * glVertexAttrib2dvProc) (GLuint index, const GLdoub | ||||
le *v); | ||||
typedef void (APIENTRY * glVertexAttrib2fProc) (GLuint index, GLfloat x, GL | ||||
float y); | ||||
typedef void (APIENTRY * glVertexAttrib2fvProc) (GLuint index, const GLfloa | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib2sProc) (GLuint index, GLshort x, GL | ||||
short y); | ||||
typedef void (APIENTRY * glVertexAttrib2svProc) (GLuint index, const GLshor | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib3dProc) (GLuint index, GLdouble x, G | ||||
Ldouble y, GLdouble z); | ||||
typedef void (APIENTRY * glVertexAttrib3dvProc) (GLuint index, const GLdoub | ||||
le *v); | ||||
typedef void (APIENTRY * glVertexAttrib3fProc) (GLuint index, GLfloat x, GL | ||||
float y, GLfloat z); | ||||
typedef void (APIENTRY * glVertexAttrib3fvProc) (GLuint index, const GLfloa | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib3sProc) (GLuint index, GLshort x, GL | ||||
short y, GLshort z); | ||||
typedef void (APIENTRY * glVertexAttrib3svProc) (GLuint index, const GLshor | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib4NbvProc) (GLuint index, const GLbyt | ||||
e *v); | ||||
typedef void (APIENTRY * glVertexAttrib4NivProc) (GLuint index, const GLint | ||||
*v); | ||||
typedef void (APIENTRY * glVertexAttrib4NsvProc) (GLuint index, const GLsho | ||||
rt *v); | ||||
typedef void (APIENTRY * glVertexAttrib4NubProc) (GLuint index, GLubyte x, | ||||
GLubyte y, GLubyte z, GLubyte w); | ||||
typedef void (APIENTRY * glVertexAttrib4NubvProc) (GLuint index, const GLub | ||||
yte *v); | ||||
typedef void (APIENTRY * glVertexAttrib4NuivProc) (GLuint index, const GLui | ||||
nt *v); | ||||
typedef void (APIENTRY * glVertexAttrib4NusvProc) (GLuint index, const GLus | ||||
hort *v); | ||||
typedef void (APIENTRY * glVertexAttrib4bvProc) (GLuint index, const GLbyte | ||||
*v); | ||||
typedef void (APIENTRY * glVertexAttrib4dProc) (GLuint index, GLdouble x, G | ||||
Ldouble y, GLdouble z, GLdouble w); | ||||
typedef void (APIENTRY * glVertexAttrib4dvProc) (GLuint index, const GLdoub | ||||
le *v); | ||||
typedef void (APIENTRY * glVertexAttrib4fProc) (GLuint index, GLfloat x, GL | ||||
float y, GLfloat z, GLfloat w); | ||||
typedef void (APIENTRY * glVertexAttrib4fvProc) (GLuint index, const GLfloa | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib4ivProc) (GLuint index, const GLint | ||||
*v); | ||||
typedef void (APIENTRY * glVertexAttrib4sProc) (GLuint index, GLshort x, GL | ||||
short y, GLshort z, GLshort w); | ||||
typedef void (APIENTRY * glVertexAttrib4svProc) (GLuint index, const GLshor | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib4ubvProc) (GLuint index, const GLuby | ||||
te *v); | ||||
typedef void (APIENTRY * glVertexAttrib4uivProc) (GLuint index, const GLuin | ||||
t *v); | ||||
typedef void (APIENTRY * glVertexAttrib4usvProc) (GLuint index, const GLush | ||||
ort *v); | ||||
typedef void (APIENTRY * glVertexAttribPointerProc) (GLuint index, GLint si | ||||
ze, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointe | ||||
r); | ||||
typedef void (APIENTRY * glEnableVertexAttribArrayProc) (GLuint index); | ||||
typedef void (APIENTRY * glDisableVertexAttribArrayProc) (GLuint index); | ||||
typedef void (APIENTRY * glProgramStringProc) (GLenum target, GLenum format | ||||
, GLsizei len, const GLvoid *string); | ||||
typedef void (APIENTRY * glBindProgramProc) (GLenum target, GLuint program) | ||||
; | ||||
typedef void (APIENTRY * glDeleteProgramsProc) (GLsizei n, const GLuint *pr | ||||
ograms); | ||||
typedef void (APIENTRY * glGenProgramsProc) (GLsizei n, GLuint *programs); | ||||
typedef void (APIENTRY * glProgramEnvParameter4dProc) (GLenum target, GLuin | ||||
t index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); | ||||
typedef void (APIENTRY * glProgramEnvParameter4dvProc) (GLenum target, GLui | ||||
nt index, const GLdouble *params); | ||||
typedef void (APIENTRY * glProgramEnvParameter4fProc) (GLenum target, GLuin | ||||
t index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); | ||||
typedef void (APIENTRY * glProgramEnvParameter4fvProc) (GLenum target, GLui | ||||
nt index, const GLfloat *params); | ||||
typedef void (APIENTRY * glProgramLocalParameter4dProc) (GLenum target, GLu | ||||
int index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); | ||||
typedef void (APIENTRY * glProgramLocalParameter4dvProc) (GLenum target, GL | ||||
uint index, const GLdouble *params); | ||||
typedef void (APIENTRY * glProgramLocalParameter4fProc) (GLenum target, GLu | ||||
int index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); | ||||
typedef void (APIENTRY * glProgramLocalParameter4fvProc) (GLenum target, GL | ||||
uint index, const GLfloat *params); | ||||
typedef void (APIENTRY * glGetProgramEnvParameterdvProc) (GLenum target, GL | ||||
uint index, GLdouble *params); | ||||
typedef void (APIENTRY * glGetProgramEnvParameterfvProc) (GLenum target, GL | ||||
uint index, GLfloat *params); | ||||
typedef void (APIENTRY * glGetProgramLocalParameterdvProc) (GLenum target, | ||||
GLuint index, GLdouble *params); | ||||
typedef void (APIENTRY * glGetProgramLocalParameterfvProc) (GLenum target, | ||||
GLuint index, GLfloat *params); | ||||
typedef void (APIENTRY * glGetProgramivProc) (GLenum target, GLenum pname, | ||||
GLint *params); | ||||
typedef void (APIENTRY * glGetProgramStringProc) (GLenum target, GLenum pna | ||||
me, GLvoid *string); | ||||
typedef void (APIENTRY * glGetVertexAttribdvProc) (GLuint index, GLenum pna | ||||
me, GLdouble *params); | ||||
typedef void (APIENTRY * glGetVertexAttribfvProc) (GLuint index, GLenum pna | ||||
me, GLfloat *params); | ||||
typedef void (APIENTRY * glGetVertexAttribivProc) (GLuint index, GLenum pna | ||||
me, GLint *params); | ||||
typedef void (APIENTRY * glGetVertexAttribPointervProc) (GLuint index, GLen | ||||
um pname, GLvoid* *pointer); | ||||
typedef GLboolean (APIENTRY * glIsProgramProc) (GLuint program); | ||||
/* | ||||
* ARB_shader_objects | ||||
*/ | ||||
#ifndef GL_ARB_shader_objects | ||||
#define GL_ARB_shader_objects 1 | ||||
/* GL types for handling shader object handles and program/shader text */ | ||||
typedef char GLcharARB; /* native character */ | ||||
typedef unsigned int GLhandleARB; /* shader object handle */ | ||||
#define GL_PROGRAM_OBJECT_ARB 0x8B40 | ||||
#define GL_SHADER_OBJECT_ARB 0x8B48 | ||||
#define GL_OBJECT_TYPE_ARB 0x8B4E | ||||
#define GL_OBJECT_SUBTYPE_ARB 0x8B4F | ||||
#define GL_FLOAT_VEC2_ARB 0x8B50 | ||||
#define GL_FLOAT_VEC3_ARB 0x8B51 | ||||
#define GL_FLOAT_VEC4_ARB 0x8B52 | ||||
#define GL_INT_VEC2_ARB 0x8B53 | ||||
#define GL_INT_VEC3_ARB 0x8B54 | ||||
#define GL_INT_VEC4_ARB 0x8B55 | ||||
#define GL_BOOL_ARB 0x8B56 | ||||
#define GL_BOOL_VEC2_ARB 0x8B57 | ||||
#define GL_BOOL_VEC3_ARB 0x8B58 | ||||
#define GL_BOOL_VEC4_ARB 0x8B59 | ||||
#define GL_FLOAT_MAT2_ARB 0x8B5A | ||||
#define GL_FLOAT_MAT3_ARB 0x8B5B | ||||
#define GL_FLOAT_MAT4_ARB 0x8B5C | ||||
#define GL_SAMPLER_1D_ARB 0x8B5D | ||||
#define GL_SAMPLER_2D_ARB 0x8B5E | ||||
#define GL_SAMPLER_3D_ARB 0x8B5F | ||||
#define GL_SAMPLER_CUBE_ARB 0x8B60 | ||||
#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 | ||||
#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 | ||||
#define GL_SAMPLER_2D_RECT_ARB 0x8B63 | ||||
#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 | ||||
#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 | ||||
#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 | ||||
#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 | ||||
#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 | ||||
#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 | ||||
#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 | ||||
#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 | ||||
#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 | ||||
#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 | ||||
#endif | ||||
typedef void (APIENTRY * glDeleteObjectProc) (GLhandleARB obj); | ||||
typedef GLhandleARB (APIENTRY * glGetHandleProc) (GLenum pname); | ||||
typedef void (APIENTRY * glDetachObjectProc) (GLhandleARB containerObj, GLh | ||||
andleARB attachedObj); | ||||
typedef GLhandleARB (APIENTRY * glCreateShaderObjectProc) (GLenum shaderTyp | ||||
e); | ||||
typedef void (APIENTRY * glShaderSourceProc) (GLhandleARB shaderObj, GLsize | ||||
i count, const GLcharARB* *string, const GLint *length); | ||||
typedef void (APIENTRY * glCompileShaderProc) (GLhandleARB shaderObj); | ||||
typedef GLhandleARB (APIENTRY * glCreateProgramObjectProc) (void); | ||||
typedef void (APIENTRY * glAttachObjectProc) (GLhandleARB containerObj, GLh | ||||
andleARB obj); | ||||
typedef void (APIENTRY * glLinkProgramProc) (GLhandleARB programObj); | ||||
typedef void (APIENTRY * glUseProgramObjectProc) (GLhandleARB programObj); | ||||
typedef void (APIENTRY * glValidateProgramProc) (GLhandleARB programObj); | ||||
typedef void (APIENTRY * glUniform1fProc) (GLint location, GLfloat v0); | ||||
typedef void (APIENTRY * glUniform2fProc) (GLint location, GLfloat v0, GLfl | ||||
oat v1); | ||||
typedef void (APIENTRY * glUniform3fProc) (GLint location, GLfloat v0, GLfl | ||||
oat v1, GLfloat v2); | ||||
typedef void (APIENTRY * glUniform4fProc) (GLint location, GLfloat v0, GLfl | ||||
oat v1, GLfloat v2, GLfloat v3); | ||||
typedef void (APIENTRY * glUniform1iProc) (GLint location, GLint v0); | ||||
typedef void (APIENTRY * glUniform2iProc) (GLint location, GLint v0, GLint | ||||
v1); | ||||
typedef void (APIENTRY * glUniform3iProc) (GLint location, GLint v0, GLint | ||||
v1, GLint v2); | ||||
typedef void (APIENTRY * glUniform4iProc) (GLint location, GLint v0, GLint | ||||
v1, GLint v2, GLint v3); | ||||
typedef void (APIENTRY * glUniform1fvProc) (GLint location, GLsizei count, | ||||
const GLfloat *value); | ||||
typedef void (APIENTRY * glUniform2fvProc) (GLint location, GLsizei count, | ||||
const GLfloat *value); | ||||
typedef void (APIENTRY * glUniform3fvProc) (GLint location, GLsizei count, | ||||
const GLfloat *value); | ||||
typedef void (APIENTRY * glUniform4fvProc) (GLint location, GLsizei count, | ||||
const GLfloat *value); | ||||
typedef void (APIENTRY * glUniform1ivProc) (GLint location, GLsizei count, | ||||
const GLint *value); | ||||
typedef void (APIENTRY * glUniform2ivProc) (GLint location, GLsizei count, | ||||
const GLint *value); | ||||
typedef void (APIENTRY * glUniform3ivProc) (GLint location, GLsizei count, | ||||
const GLint *value); | ||||
typedef void (APIENTRY * glUniform4ivProc) (GLint location, GLsizei count, | ||||
const GLint *value); | ||||
typedef void (APIENTRY * glUniformMatrix2fvProc) (GLint location, GLsizei c | ||||
ount, GLboolean transpose, const GLfloat *value); | ||||
typedef void (APIENTRY * glUniformMatrix3fvProc) (GLint location, GLsizei c | ||||
ount, GLboolean transpose, const GLfloat *value); | ||||
typedef void (APIENTRY * glUniformMatrix4fvProc) (GLint location, GLsizei c | ||||
ount, GLboolean transpose, const GLfloat *value); | ||||
typedef void (APIENTRY * glGetObjectParameterfvProc) (GLhandleARB obj, GLen | ||||
um pname, GLfloat *params); | ||||
typedef void (APIENTRY * glGetObjectParameterivProc) (GLhandleARB obj, GLen | ||||
um pname, GLint *params); | ||||
typedef void (APIENTRY * glGetInfoLogProc) (GLhandleARB obj, GLsizei maxLen | ||||
gth, GLsizei *length, GLcharARB *infoLog); | ||||
typedef void (APIENTRY * glGetAttachedObjectsProc) (GLhandleARB containerOb | ||||
j, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); | ||||
typedef GLint (APIENTRY * glGetUniformLocationProc) (GLhandleARB programObj | ||||
, const GLcharARB *name); | ||||
typedef void (APIENTRY * glGetActiveUniformProc) (GLhandleARB programObj, G | ||||
Luint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, | ||||
GLcharARB *name); | ||||
typedef void (APIENTRY * glGetUniformfvProc) (GLhandleARB programObj, GLint | ||||
location, GLfloat *params); | ||||
typedef void (APIENTRY * glGetUniformivProc) (GLhandleARB programObj, GLint | ||||
location, GLint *params); | ||||
typedef void (APIENTRY * glGetShaderSourceProc) (GLhandleARB obj, GLsizei m | ||||
axLength, GLsizei *length, GLcharARB *source); | ||||
/* | ||||
* ARB_vertex_shader | ||||
*/ | ||||
#ifndef GL_ARB_vertex_shader | ||||
#define GL_ARB_vertex_shader 1 | ||||
#define GL_VERTEX_SHADER_ARB 0x8B31 | ||||
#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A | ||||
#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B | ||||
#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C | ||||
#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D | ||||
#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 | ||||
#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A | ||||
#endif | ||||
typedef void (APIENTRY * glBindAttribLocationProc) (GLhandleARB programObj, | ||||
GLuint index, const GLcharARB *name); | ||||
typedef void (APIENTRY * glGetActiveAttribProc) (GLhandleARB programObj, GL | ||||
uint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, | ||||
GLcharARB *name); | ||||
typedef GLint (APIENTRY * glGetAttribLocationProc) (GLhandleARB programObj, | ||||
const GLcharARB *name); | ||||
/* | ||||
* ARB_fragment_shader | ||||
*/ | ||||
#ifndef GL_ARB_fragment_shader | ||||
#define GL_ARB_fragment_shader1 | ||||
#define GL_FRAGMENT_SHADER_ARB 0x8B30 | ||||
#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 | ||||
#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B | ||||
#endif | ||||
/* | ||||
* NV_fragment_program | ||||
*/ | ||||
#ifndef GL_NV_fragment_program | ||||
#define GL_NV_fragment_program 1 | ||||
#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 | ||||
#define GL_FRAGMENT_PROGRAM_NV 0x8870 | ||||
#define GL_MAX_TEXTURE_COORDS_NV 0x8871 | ||||
#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 | ||||
#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 | ||||
#define GL_PROGRAM_ERROR_STRING_NV 0x8874 | ||||
#endif | ||||
#ifndef GL_NV_vertex_program | ||||
#define GL_NV_vertex_program 1 | ||||
#define GL_VERTEX_PROGRAM_NV 0x8620 | ||||
#define GL_PROGRAM_ERROR_POSITION_NV 0x864B | ||||
#endif | ||||
typedef void (APIENTRY * glBindProgramNVProc) (GLenum target, GLuint id); | ||||
typedef void (APIENTRY * glDeleteProgramsNVProc) (GLsizei n, const GLuint * | ||||
programs); | ||||
typedef void (APIENTRY * glGenProgramsNVProc) (GLsizei n, GLuint *programs) | ||||
; | ||||
typedef void (APIENTRY * glLoadProgramNVProc) (GLenum target, GLuint id, GL | ||||
sizei len, const GLubyte *program); | ||||
typedef void (APIENTRY * glProgramParameter4fvNVProc) (GLenum target, GLuin | ||||
t index, const GLfloat *v); | ||||
#if defined(__cplusplus) | ||||
} | ||||
#endif | ||||
#endif // !__SG_EXTENSIONS_HXX | #endif // !__SG_EXTENSIONS_HXX | |||
End of changes. 3 change blocks. | ||||
1039 lines changed or deleted | 1 lines changed or added | |||
interpolater.hxx | interpolater.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: interpolater.hxx,v 1.4.2.1 2007-03-31 12:23:38 mfranz Exp $ | // $Id$ | |||
#ifndef _INTERPOLATER_H | #ifndef _INTERPOLATER_H | |||
#define _INTERPOLATER_H | #define _INTERPOLATER_H | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include "simgear/structure/SGReferenced.hxx" | #include <simgear/structure/SGReferenced.hxx> | |||
#include <map> | #include <map> | |||
#include <string> | ||||
#include STL_STRING | ||||
SG_USING_STD(string); | ||||
class SGPropertyNode; | class SGPropertyNode; | |||
/** | /** | |||
* A class that provids a simple linear 2d interpolation lookup table. | * A class that provids a simple linear 2d interpolation lookup table. | |||
* The actual table is expected to be loaded from a file. The | * The actual table is expected to be loaded from a file. The | |||
* independant variable must be strictly ascending. The dependent | * independant variable must be strictly ascending. The dependent | |||
* variable can be anything. | * variable can be anything. | |||
*/ | */ | |||
class SGInterpTable : public SGReferenced { | class SGInterpTable : public SGReferenced { | |||
skipping to change at line 70 | skipping to change at line 68 | |||
* Constructor. Loads the interpolation table from an interpolation | * Constructor. Loads the interpolation table from an interpolation | |||
* property node. | * property node. | |||
* @param interpolation property node having entry children | * @param interpolation property node having entry children | |||
*/ | */ | |||
SGInterpTable(const SGPropertyNode* interpolation); | SGInterpTable(const SGPropertyNode* interpolation); | |||
/** | /** | |||
* Constructor. Loads the interpolation table from the specified file. | * Constructor. Loads the interpolation table from the specified file. | |||
* @param file name of interpolation file | * @param file name of interpolation file | |||
*/ | */ | |||
SGInterpTable( const string& file ); | SGInterpTable( const std::string& file ); | |||
/** | /** | |||
* Add an entry to the table, extending the table's length. | * Add an entry to the table, extending the table's length. | |||
* | * | |||
* @param ind The independent variable. | * @param ind The independent variable. | |||
* @param dep The dependent variable. | * @param dep The dependent variable. | |||
*/ | */ | |||
void addEntry (double ind, double dep); | void addEntry (double ind, double dep); | |||
/** | /** | |||
End of changes. 4 change blocks. | ||||
6 lines changed or deleted | 4 lines changed or added | |||
iochannel.hxx | iochannel.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: iochannel.hxx,v 1.6 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _IOCHANNEL_HXX | #ifndef _IOCHANNEL_HXX | |||
#define _IOCHANNEL_HXX | #define _IOCHANNEL_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
// #include "protocol.hxx" | ||||
#include STL_STRING | ||||
#include <vector> | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(string); | ||||
#define SG_IO_MAX_MSG_SIZE 16384 | #define SG_IO_MAX_MSG_SIZE 16384 | |||
/** | /** | |||
* Specify if this is a read (IN), write (OUT), or r/w (BI) directional | * Specify if this is a read (IN), write (OUT), or r/w (BI) directional | |||
* channel | * channel | |||
*/ | */ | |||
enum SGProtocolDir { | enum SGProtocolDir { | |||
SG_IO_NONE = 0, | SG_IO_NONE = 0, | |||
SG_IO_IN = 1, | SG_IO_IN = 1, | |||
SG_IO_OUT = 2, | SG_IO_OUT = 2, | |||
skipping to change at line 156 | skipping to change at line 148 | |||
* @return result of close | * @return result of close | |||
*/ | */ | |||
virtual bool close(); | virtual bool close(); | |||
/** | /** | |||
* The eof() method returns true if end of file has been reached | * The eof() method returns true if end of file has been reached | |||
* in a context where that makes sense. Otherwise it returns | * in a context where that makes sense. Otherwise it returns | |||
* false. | * false. | |||
* @return result of eof check | * @return result of eof check | |||
*/ | */ | |||
virtual bool eof(); | virtual bool eof() const; | |||
inline void set_type( SGChannelType t ) { type = t; } | inline void set_type( SGChannelType t ) { type = t; } | |||
inline SGChannelType get_type() const { return type; } | inline SGChannelType get_type() const { return type; } | |||
inline void set_dir( const SGProtocolDir d ) { dir = d; } | inline void set_dir( const SGProtocolDir d ) { dir = d; } | |||
inline SGProtocolDir get_dir() const { return dir; } | inline SGProtocolDir get_dir() const { return dir; } | |||
inline bool isvalid() const { return valid; } | inline bool isvalid() const { return valid; } | |||
inline void set_valid( const bool v ) { valid = v; } | inline void set_valid( const bool v ) { valid = v; } | |||
}; | }; | |||
End of changes. 3 change blocks. | ||||
10 lines changed or deleted | 2 lines changed or added | |||
jupiter.hxx | jupiter.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: jupiter.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _JUPITER_HXX_ | #ifndef _JUPITER_HXX_ | |||
#define _JUPITER_HXX_ | #define _JUPITER_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Jupiter : public CelestialBody | class Jupiter : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
leastsqs.hxx | leastsqs.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: leastsqs.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _LEASTSQS_H | #ifndef _LEASTSQS_H | |||
#define _LEASTSQS_H | #define _LEASTSQS_H | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
/** | /** | |||
Classical least squares fit: | Classical least squares fit: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
logstream.hxx | logstream.hxx | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: logstream.hxx,v 1.10.2.1 2007-07-02 12:55:21 mfranz Exp $ | // $Id$ | |||
#ifndef _LOGSTREAM_H | #ifndef _LOGSTREAM_H | |||
#define _LOGSTREAM_H | #define _LOGSTREAM_H | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/debug/debug_types.h> | ||||
#ifdef _MSC_VER | #include <sstream> | |||
# include <windows.h> | ||||
#endif | ||||
#ifdef SG_HAVE_STD_INCLUDES | // forward decls | |||
# include <streambuf> | class SGPath; | |||
# include <iostream> | ||||
#else | ||||
# include <iostream.h> | ||||
# include <simgear/sg_traits.hxx> | ||||
#endif | ||||
#include <simgear/debug/debug_types.h> | namespace simgear | |||
{ | ||||
SG_USING_STD(streambuf); | class LogCallback | |||
SG_USING_STD(ostream); | { | |||
SG_USING_STD(cout); | public: | |||
SG_USING_STD(cerr); | virtual ~LogCallback() {} | |||
SG_USING_STD(endl); | virtual void operator()(sgDebugClass c, sgDebugPriority p, | |||
const char* file, int line, const std::string& aMessage) = 0; | ||||
}; | ||||
#ifdef __MWERKS__ | } // of namespace simgear | |||
SG_USING_STD(iostream); | ||||
#endif | ||||
// | ||||
// TODO: | ||||
// | ||||
// 1. Change output destination. Done. | ||||
// 2. Make logbuf thread safe. | ||||
// 3. Read environment for default debugClass and debugPriority. | ||||
// | ||||
/** | /** | |||
* logbuf is an output-only streambuf with the ability to disable sets of | * Class to manage the debug logging stream. | |||
* messages at runtime. Only messages with priority >= logbuf::logPriority | ||||
* and debugClass == logbuf::logClass are output. | ||||
*/ | */ | |||
#ifdef SG_NEED_STREAMBUF_HACK | class logstream | |||
class logbuf : public __streambuf | ||||
#else | ||||
class logbuf : public streambuf | ||||
#endif | ||||
{ | { | |||
public: | public: | |||
static void initGlobalLogstream(); | ||||
#ifndef SG_HAVE_STD_INCLUDES | ||||
typedef char_traits<char> traits_type; | ||||
typedef char_traits<char>::int_type int_type; | ||||
// typedef char_traits<char>::pos_type pos_type; | ||||
// typedef char_traits<char>::off_type off_type; | ||||
#endif | ||||
// logbuf( streambuf* sb ) : sbuf(sb) {} | ||||
/** Constructor */ | ||||
logbuf(); | ||||
/** Destructor */ | ||||
~logbuf(); | ||||
/** | ||||
* Is logging enabled? | ||||
* @return true or false*/ | ||||
bool enabled() { return logging_enabled; } | ||||
/** | ||||
* Set the logging level of subsequent messages. | ||||
* @param c debug class | ||||
* @param p priority | ||||
*/ | ||||
void set_log_state( sgDebugClass c, sgDebugPriority p ); | ||||
/** | /** | |||
* Set the global logging level. | * Set the global log class and priority level. | |||
* @param c debug class | * @param c debug class | |||
* @param p priority | * @param p priority | |||
*/ | */ | |||
static void set_log_level( sgDebugClass c, sgDebugPriority p ); | void setLogLevels( sgDebugClass c, sgDebugPriority p ); | |||
/** | ||||
* Set the allowed logging classes. | ||||
* @param c All enabled logging classes anded together. | ||||
*/ | ||||
static void set_log_classes (sgDebugClass c); | ||||
/** | ||||
* Get the logging classes currently enabled. | ||||
* @return All enabled debug logging anded together. | ||||
*/ | ||||
static sgDebugClass get_log_classes (); | ||||
/** | ||||
* Set the logging priority. | ||||
* @param c The priority cutoff for logging messages. | ||||
*/ | ||||
static void set_log_priority (sgDebugPriority p); | ||||
/** | ||||
* Get the current logging priority. | ||||
* @return The priority cutoff for logging messages. | ||||
*/ | ||||
static sgDebugPriority get_log_priority (); | ||||
/** | ||||
* Set the stream buffer | ||||
* @param sb stream buffer | ||||
*/ | ||||
void set_sb( streambuf* sb ); | ||||
#ifdef _MSC_VER | ||||
static void has_no_console() { has_console = false; } | ||||
#endif | ||||
protected: | ||||
/** sync/flush */ | ||||
inline virtual int sync(); | ||||
/** overflow */ | ||||
int_type overflow( int ch ); | ||||
// int xsputn( const char* s, istreamsize n ); | ||||
private: | ||||
// The streambuf used for actual output. Defaults to cerr.rdbuf(). | ||||
static streambuf* sbuf; | ||||
static bool logging_enabled; | ||||
#ifdef _MSC_VER | ||||
static bool has_console; | ||||
#endif | ||||
static sgDebugClass logClass; | ||||
static sgDebugPriority logPriority; | ||||
private: | ||||
// Not defined. | ||||
logbuf( const logbuf& ); | ||||
void operator= ( const logbuf& ); | ||||
}; | ||||
inline int | ||||
logbuf::sync() | ||||
{ | ||||
#ifdef SG_HAVE_STD_INCLUDES | ||||
return sbuf->pubsync(); | ||||
#else | ||||
return sbuf->sync(); | ||||
#endif | ||||
} | ||||
inline void | ||||
logbuf::set_log_state( sgDebugClass c, sgDebugPriority p ) | ||||
{ | ||||
logging_enabled = ((c & logClass) != 0 && p >= logPriority); | ||||
} | ||||
inline logbuf::int_type | bool would_log( sgDebugClass c, sgDebugPriority p ) const; | |||
logbuf::overflow( int c ) | ||||
{ | ||||
#ifdef _MSC_VER | ||||
if ( logging_enabled ) { | ||||
if ( !has_console ) { | ||||
AllocConsole(); | ||||
freopen("conin$", "r", stdin); | ||||
freopen("conout$", "w", stdout); | ||||
freopen("conout$", "w", stderr); | ||||
has_console = true; | ||||
} | ||||
return sbuf->sputc(c); | ||||
} | ||||
else | ||||
return EOF == 0 ? 1: 0; | ||||
#else | ||||
return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0); | ||||
#endif | ||||
} | ||||
/** | void logToFile( const SGPath& aPath, sgDebugClass c, sgDebugPriority p | |||
* logstream manipulator for setting the log level of a message. | ); | |||
*/ | ||||
struct loglevel | ||||
{ | ||||
loglevel( sgDebugClass c, sgDebugPriority p ) | ||||
: logClass(c), logPriority(p) {} | ||||
sgDebugClass logClass; | void set_log_priority( sgDebugPriority p); | |||
sgDebugPriority logPriority; | ||||
}; | ||||
/** | void set_log_classes( sgDebugClass c); | |||
* A helper class that ensures a streambuf and ostream are constructed and | ||||
* destroyed in the correct order. The streambuf must be created before th | ||||
e | ||||
* ostream but bases are constructed before members. Thus, making this cla | ||||
ss | ||||
* a private base of logstream, declared to the left of ostream, we ensure | ||||
the | ||||
* correct order of construction and destruction. | ||||
*/ | ||||
struct logstream_base | ||||
{ | ||||
// logstream_base( streambuf* sb ) : lbuf(sb) {} | ||||
logstream_base() {} | ||||
logbuf lbuf; | sgDebugClass get_log_classes() const; | |||
}; | ||||
/** | sgDebugPriority get_log_priority() const; | |||
* Class to manage the debug logging stream. | ||||
*/ | ||||
class logstream : private logstream_base, public ostream | ||||
{ | ||||
public: | ||||
/** | ||||
* The default is to send messages to cerr. | ||||
* @param out output stream | ||||
*/ | ||||
logstream( ostream& out ) | ||||
// : logstream_base(out.rdbuf()), | ||||
: logstream_base(), | ||||
ostream(&lbuf) { lbuf.set_sb(out.rdbuf());} | ||||
/** | /** | |||
* Set the output stream | * the core logging method | |||
* @param out output stream | ||||
*/ | */ | |||
void set_output( ostream& out ) { lbuf.set_sb( out.rdbuf() ); } | void log( sgDebugClass c, sgDebugPriority p, | |||
const char* fileName, int line, const std::string& msg); | ||||
/** | /** | |||
* Set the global log class and priority level. | * \relates logstream | |||
* @param c debug class | * Return the one and only logstream instance. | |||
* @param p priority | * We use a function instead of a global object so we are assured that c | |||
*/ | err | |||
void setLogLevels( sgDebugClass c, sgDebugPriority p ); | * has been initialised. | |||
* @return current logstream | ||||
*/ | ||||
friend logstream& sglog(); | ||||
/** | /** | |||
* Output operator to capture the debug level and priority of a message | * register a logging callback. Note callbacks are run in a | |||
. | * dedicated thread, so callbacks which pass data to other threads | |||
* @param l log level | * must use appropriate locking. | |||
*/ | */ | |||
inline ostream& operator<< ( const loglevel& l ); | void addCallback(simgear::LogCallback* cb); | |||
}; | ||||
inline ostream& | ||||
logstream::operator<< ( const loglevel& l ) | ||||
{ | ||||
lbuf.set_log_state( l.logClass, l.logPriority ); | ||||
return *this; | ||||
} | ||||
extern logstream *global_logstream; | ||||
/** | void removeCallback(simgear::LogCallback* cb); | |||
* \relates logstream | ||||
* Return the one and only logstream instance. | ||||
* We use a function instead of a global object so we are assured that cerr | ||||
* has been initialised. | ||||
* @return current logstream | ||||
*/ | ||||
inline logstream& | ||||
sglog() | ||||
{ | ||||
if (global_logstream == NULL) { | ||||
#ifdef __APPLE__ | private: | |||
/** | // constructor | |||
* There appears to be a bug in the C++ runtime in Mac OS X that | logstream(); | |||
* will crash if certain funtions are called (in this case | }; | |||
* cerr.rdbuf()) during static initialization of a class. This | ||||
* print statement is hack to kick the library in the pants so it | ||||
* won't crash when cerr.rdbuf() is first called -DW | ||||
**/ | ||||
cout << "Using Mac OS X hack for initializing C++ stdio..." << endl; | ||||
#endif | ||||
global_logstream = new logstream (cerr); | ||||
} | ||||
return *global_logstream; | logstream& sglog(); | |||
} | ||||
/** \def SG_LOG(C,P,M) | /** \def SG_LOG(C,P,M) | |||
* Log a message. | * Log a message. | |||
* @param C debug class | * @param C debug class | |||
* @param P priority | * @param P priority | |||
* @param M message | * @param M message | |||
*/ | */ | |||
#ifdef FG_NDEBUG | #ifdef FG_NDEBUG | |||
# define SG_LOG(C,P,M) | # define SG_LOG(C,P,M) | |||
#elif defined( __MWERKS__ ) | ||||
# define SG_LOG(C,P,M) ::sglog() << ::loglevel(C,P) << M << std::endl | ||||
#else | #else | |||
# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << endl | # define SG_LOG(C,P,M) do { \ | |||
if(sglog().would_log(C,P)) { \ | ||||
std::ostringstream os; \ | ||||
os << M; \ | ||||
sglog().log(C, P, __FILE__, __LINE__, os.str()); \ | ||||
} \ | ||||
} while(0) | ||||
#endif | #endif | |||
#define SG_STRINGIFY(x) #x | #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__) | |||
#define SG_TOSTRING(x) SG_STRINGIFY(x) | ||||
#define SG_ORIGIN __FILE__ ":" SG_TOSTRING(__LINE__) | ||||
#endif // _LOGSTREAM_H | #endif // _LOGSTREAM_H | |||
End of changes. 29 change blocks. | ||||
256 lines changed or deleted | 57 lines changed or added | |||
lowlevel.hxx | lowlevel.hxx | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, | // This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | // GNU General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: lowlevel.hxx,v 1.10 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
// | // | |||
#ifndef _SG_LOWLEVEL_HXX | #ifndef _SG_LOWLEVEL_HXX | |||
#define _SG_LOWLEVEL_HXX | #define _SG_LOWLEVEL_HXX | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <zlib.h> | #include <zlib.h> | |||
#include <plib/sg.h> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/misc/stdint.hxx> | #include <simgear/misc/stdint.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
// Note that output is written in little endian form (and converted as | // Note that output is written in little endian form (and converted as | |||
// necessary for big endian machines) | // necessary for big endian machines) | |||
void sgReadChar ( gzFile fd, char *var ) ; | void sgReadChar ( gzFile fd, char *var ) ; | |||
void sgWriteChar ( gzFile fd, const char var ) ; | void sgWriteChar ( gzFile fd, const char var ) ; | |||
void sgReadFloat ( gzFile fd, float *var ) ; | void sgReadFloat ( gzFile fd, float *var ) ; | |||
void sgWriteFloat ( gzFile fd, const float var ) ; | void sgWriteFloat ( gzFile fd, const float var ) ; | |||
void sgReadDouble ( gzFile fd, double *var ) ; | void sgReadDouble ( gzFile fd, double *var ) ; | |||
void sgWriteDouble ( gzFile fd, const double var ) ; | void sgWriteDouble ( gzFile fd, const double var ) ; | |||
void sgReadUInt ( gzFile fd, unsigned int *var ) ; | void sgReadUInt ( gzFile fd, unsigned int *var ) ; | |||
skipping to change at line 77 | skipping to change at line 77 | |||
void sgReadUShort ( gzFile fd, const unsigned int n, unsigned short *var ) ; | void sgReadUShort ( gzFile fd, const unsigned int n, unsigned short *var ) ; | |||
void sgWriteUShort ( gzFile fd, const unsigned int n, const unsigned short *var ) ; | void sgWriteUShort ( gzFile fd, const unsigned int n, const unsigned short *var ) ; | |||
void sgReadShort ( gzFile fd, const unsigned int n, short *var ) ; | void sgReadShort ( gzFile fd, const unsigned int n, short *var ) ; | |||
void sgWriteShort ( gzFile fd, const unsigned int n, const short *var ) ; | void sgWriteShort ( gzFile fd, const unsigned int n, const short *var ) ; | |||
void sgReadBytes ( gzFile fd, const unsigned int n, void *var ) ; | void sgReadBytes ( gzFile fd, const unsigned int n, void *var ) ; | |||
void sgWriteBytes ( gzFile fd, const unsigned int n, const void *var ) ; | void sgWriteBytes ( gzFile fd, const unsigned int n, const void *var ) ; | |||
void sgReadString ( gzFile fd, char **var ) ; | void sgReadString ( gzFile fd, char **var ) ; | |||
void sgWriteString ( gzFile fd, const char *var ) ; | void sgWriteString ( gzFile fd, const char *var ) ; | |||
inline void sgReadVec2 ( gzFile fd, sgVec2 var ) { | inline void sgReadVec2 ( gzFile fd, SGVec2f& var ) { | |||
sgReadFloat ( fd, 2, var ) ; | sgReadFloat ( fd, 2, var.data() ) ; | |||
} | ||||
inline void sgWriteVec2 ( gzFile fd, const SGVec2f& var ) { | ||||
sgWriteFloat ( fd, 2, var.data() ) ; | ||||
} | ||||
inline void sgReadVec3 ( gzFile fd, SGVec3f& var ) { | ||||
sgReadFloat ( fd, 3, var.data() ) ; | ||||
} | } | |||
inline void sgWriteVec2 ( gzFile fd, const sgVec2 var ) { | inline void sgWriteVec3 ( gzFile fd, const SGVec3f& var ) { | |||
sgWriteFloat ( fd, 2, var ) ; | sgWriteFloat ( fd, 3, var.data() ) ; | |||
} | } | |||
inline void sgReadVec3 ( gzFile fd, sgVec3 var ) { | inline void sgReaddVec3 ( gzFile fd, SGVec3d& var ) { | |||
sgReadFloat ( fd, 3, var ) ; | sgReadDouble ( fd, 3, var.data() ) ; | |||
} | } | |||
inline void sgWriteVec3 ( gzFile fd, const sgVec3 var ) { | inline void sgWritedVec3 ( gzFile fd, const SGVec3d& var ) { | |||
sgWriteFloat ( fd, 3, var ) ; | sgWriteDouble ( fd, 3, var.data() ) ; | |||
} | } | |||
inline void sgReaddVec3 ( gzFile fd, sgdVec3 var ) { | inline void sgReadVec4 ( gzFile fd, SGVec4f& var ) { | |||
sgReadDouble ( fd, 3, var ) ; | sgReadFloat ( fd, 4, var.data() ) ; | |||
} | } | |||
inline void sgWritedVec3 ( gzFile fd, const sgdVec3 var ) { | inline void sgWriteVec4 ( gzFile fd, const SGVec4f& var ) { | |||
sgWriteDouble ( fd, 3, var ) ; | sgWriteFloat ( fd, 4, var.data() ) ; | |||
} | } | |||
inline void sgReadVec4 ( gzFile fd, sgVec4 var ) { | inline void sgReadMat4 ( gzFile fd, SGMatrixf& var ) { | |||
sgReadFloat ( fd, 4, var ) ; | sgReadFloat ( fd, 16, (float *)var.data() ) ; | |||
} | } | |||
inline void sgWriteVec4 ( gzFile fd, const sgVec4 var ) { | inline void sgWriteMat4 ( gzFile fd, const SGMatrixf& var ) { | |||
sgWriteFloat ( fd, 4, var ) ; | sgWriteFloat ( fd, 16, (float *)var.data() ) ; | |||
} | } | |||
inline void sgReadMat4 ( gzFile fd, sgMat4 var ) { | inline void sgReadGeod ( gzFile fd, SGGeod& var ) { | |||
sgReadFloat ( fd, 16, (float *)var ) ; | double data[3]; | |||
sgReadDouble ( fd, 3, data ); | ||||
var = SGGeod::fromDegM( data[0], data[1], data[2] ); | ||||
} | } | |||
inline void sgWriteMat4 ( gzFile fd, const sgMat4 var ) { | inline void sgWriteGeod ( gzFile fd, const SGGeod& var ) { | |||
sgWriteFloat ( fd, 16, (float *)var ) ; | sgWriteDouble( fd, var.getLongitudeDeg() ); | |||
sgWriteDouble( fd, var.getLatitudeDeg() ); | ||||
sgWriteDouble( fd, var.getElevationM() ); | ||||
} | } | |||
void sgClearReadError(); | void sgClearReadError(); | |||
void sgClearWriteError(); | void sgClearWriteError(); | |||
int sgReadError(); | int sgReadError(); | |||
int sgWriteError(); | int sgWriteError(); | |||
#endif // _SG_LOWLEVEL_HXX | #endif // _SG_LOWLEVEL_HXX | |||
End of changes. 13 change blocks. | ||||
23 lines changed or deleted | 34 lines changed or added | |||
magvar.hxx | magvar.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: magvar.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _MAGVAR_HXX | #ifndef _MAGVAR_HXX | |||
#define _MAGVAR_HXX | #define _MAGVAR_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
// forward decls | ||||
class SGGeod; | ||||
/** | /** | |||
* Magnetic variation wrapper class. | * Magnetic variation wrapper class. | |||
* | * | |||
* The SGMagVar class calculates the magnetic variation and dip for | * The SGMagVar class calculates the magnetic variation and dip for | |||
* any position, altitude, and time. It is a complete | * any position, altitude, and time. It is a complete | |||
* re-implimentation of the NIMA WMM 2000 (not derived from their demo | * re-implimentation of the NIMA WMM 2000 (not derived from their demo | |||
* code.) | * code.) | |||
* | * | |||
* The SGMagVar class is really a simple wrapper around the core Ed | * The SGMagVar class is really a simple wrapper around the core Ed | |||
* Williams code which does all the hard work. This class allows you | * Williams code which does all the hard work. This class allows you | |||
skipping to change at line 78 | skipping to change at line 81 | |||
* the julian date. Lon and lat are specified in radians, altitude | * the julian date. Lon and lat are specified in radians, altitude | |||
* is specified in meters. Julian date can be conveniently | * is specified in meters. Julian date can be conveniently | |||
* calculated by using an instance of the SGTime class. | * calculated by using an instance of the SGTime class. | |||
* @param lon longitude in radians | * @param lon longitude in radians | |||
* @param lat latitude in radians | * @param lat latitude in radians | |||
* @param alt_m altitude above sea level in meters | * @param alt_m altitude above sea level in meters | |||
* @param jd julian date | * @param jd julian date | |||
*/ | */ | |||
void update( double lon, double lat, double alt_m, double jd ); | void update( double lon, double lat, double alt_m, double jd ); | |||
/** | ||||
* overloaded variant taking an SGGeod to specify position | ||||
*/ | ||||
void update( const SGGeod& geod, double jd ); | ||||
/** @return the current magnetic variation in radians. */ | /** @return the current magnetic variation in radians. */ | |||
double get_magvar() const { return magvar; } | double get_magvar() const { return magvar; } | |||
/** @return the current magnetic dip in radians. */ | /** @return the current magnetic dip in radians. */ | |||
double get_magdip() const { return magdip; } | double get_magdip() const { return magdip; } | |||
}; | }; | |||
/** | /** | |||
* \relates SGMagVar | * \relates SGMagVar | |||
* Lookup the magvar for any arbitrary location (This function doesn't | * Lookup the magvar for any arbitrary location (This function doesn't | |||
* save state like the SGMagVar class. This function triggers a fair | * save state like the SGMagVar class. This function triggers a fair | |||
* amount of CPU work, so use it cautiously. | * amount of CPU work, so use it cautiously. | |||
* @return the magvar in radians | * @return the magvar in radians | |||
*/ | */ | |||
double sgGetMagVar( double lon, double lat, double alt_m, double jd ); | double sgGetMagVar( double lon, double lat, double alt_m, double jd ); | |||
/** | ||||
* overload version of the above to take a SGGeod | ||||
*/ | ||||
double sgGetMagVar( const SGGeod& pos, double jd ); | ||||
#endif // _MAGVAR_HXX | #endif // _MAGVAR_HXX | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 14 lines changed or added | |||
mars.hxx | mars.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: mars.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _MARS_HXX_ | #ifndef _MARS_HXX_ | |||
#define _MARS_HXX_ | #define _MARS_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Mars : public CelestialBody | class Mars : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
mat.hxx | mat.hxx | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: mat.hxx,v 1.24.2.1 2007-05-13 11:52:45 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_MAT_HXX | #ifndef _SG_MAT_HXX | |||
#define _SG_MAT_HXX | #define _SG_MAT_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING // Standard C++ string library | #include <string> // Standard C++ string library | |||
#include <vector> | #include <vector> | |||
#include <map> | #include <map> | |||
#include <simgear/math/SGMath.hxx> | #include "Effect.hxx" | |||
#include <plib/sg.h> | #include <osg/ref_ptr> | |||
#include <plib/ssg.h> | #include <osg/Texture2D> | |||
#include <simgear/props/props.hxx> | namespace osg | |||
#include <simgear/structure/ssgSharedPtr.hxx> | { | |||
#include <simgear/structure/SGSharedPtr.hxx> | class StateSet; | |||
} | ||||
#include "matmodel.hxx" | #include <simgear/structure/SGSharedPtr.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
SG_USING_STD(string); | #include <simgear/bvh/BVHMaterial.hxx> | |||
SG_USING_STD(vector); | ||||
SG_USING_STD(map); | ||||
namespace simgear | ||||
{ | ||||
class Effect; | ||||
void reload_shaders(); | ||||
class SGReaderWriterOptions; | ||||
} | ||||
class SGMatModelGroup; | ||||
class SGCondition; | ||||
class SGPropertyNode; | ||||
class SGMaterialGlyph; | class SGMaterialGlyph; | |||
class SGTexturedTriangleBin; | ||||
/** | /** | |||
* A material in the scene graph. | * A material in the scene graph. | |||
* | * | |||
* A material represents information about a single surface type | * A material represents information about a single surface type | |||
* in the 3D scene graph, including texture, colour, lighting, | * in the 3D scene graph, including texture, colour, lighting, | |||
* tiling, and so on; most of the materials in FlightGear are | * tiling, and so on; most of the materials in FlightGear are | |||
* defined in the $FG_ROOT/materials.xml file, and can be changed | * defined in the $FG_ROOT/materials.xml file, and can be changed | |||
* at runtime. | * at runtime. | |||
*/ | */ | |||
class SGMaterial : public SGReferenced { | class SGMaterial : public simgear::BVHMaterial { | |||
public: | public: | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
// Public Constructors. | // Public Constructors. | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
/** | /** | |||
* Construct a material from a set of properties. | * Construct a material from a set of properties. | |||
* | * | |||
* @param props A property node containing subnodes with the | * @param props A property node containing subnodes with the | |||
* state information for the material. This node is usually | * state information for the material. This node is usually | |||
* loaded from the $FG_ROOT/materials.xml file. | * loaded from the $FG_ROOT/materials.xml file. | |||
*/ | */ | |||
SGMaterial( const string &fg_root, const SGPropertyNode *props, const cha | SGMaterial( const osgDB::Options*, | |||
r *season ); | const SGPropertyNode *props, | |||
SGPropertyNode *prop_root); | ||||
/** | ||||
* Construct a material from an absolute texture path. | SGMaterial(const simgear::SGReaderWriterOptions*, | |||
* | const SGPropertyNode *props, | |||
* @param texture_path A string containing an absolute path | SGPropertyNode *prop_root); | |||
* to a texture file (usually RGB). | ||||
*/ | ||||
SGMaterial( const string &texpath ); | ||||
/** | ||||
* Construct a material around an existing SSG state. | ||||
* | ||||
* This constructor allows the application to create a custom, | ||||
* low-level state for the scene graph and wrap a material around | ||||
* it. Note: the pointer ownership is transferred to the material. | ||||
* | ||||
* @param s The SSG state for this material. | ||||
*/ | ||||
SGMaterial( ssgSimpleState *s ); | ||||
/** | /** | |||
* Destructor. | * Destructor. | |||
*/ | */ | |||
~SGMaterial( void ); | ~SGMaterial( void ); | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
// Public methods. | // Public methods. | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
/** | /** | |||
* Force the texture to load if it hasn't already. | * Get the textured state. | |||
* | ||||
* @return true if the texture loaded, false if it was loaded | ||||
* already. | ||||
*/ | */ | |||
bool load_texture (int n = -1); | simgear::Effect* get_effect(const SGTexturedTriangleBin& triangleBin); | |||
simgear::Effect* get_effect(); | ||||
/** | /** | |||
* Get the textured state. | * Get the textured state. | |||
*/ | */ | |||
ssgSimpleState *get_state (int n = -1) const; | osg::Texture2D* get_object_mask(const SGTexturedTriangleBin& triangleBin) ; | |||
/** | /** | |||
* Get the number of textures assigned to this material. | * Get the number of textures assigned to this material. | |||
*/ | */ | |||
inline int get_num() const { return _status.size(); } | inline int get_num() const { return _status.size(); } | |||
/** | /** | |||
* Get the xsize of the texture, in meters. | * Get the xsize of the texture, in meters. | |||
*/ | */ | |||
inline double get_xsize() const { return xsize; } | inline double get_xsize() const { return xsize; } | |||
skipping to change at line 141 | skipping to change at line 131 | |||
/** | /** | |||
* Get the ysize of the texture, in meters. | * Get the ysize of the texture, in meters. | |||
*/ | */ | |||
inline double get_ysize() const { return ysize; } | inline double get_ysize() const { return ysize; } | |||
/** | /** | |||
* Get the light coverage. | * Get the light coverage. | |||
* | * | |||
* A smaller number means more generated night lighting. | * A smaller number means more generated night lighting. | |||
* | * | |||
* @return The area (m^2?) covered by each light. | * @return The area (m^2) covered by each light. | |||
*/ | */ | |||
inline double get_light_coverage () const { return light_coverage; } | inline double get_light_coverage () const { return light_coverage; } | |||
/** | /** | |||
* Return if the surface material is solid, if it is not solid, a fluid | * Get the building coverage. | |||
* can be assumed, that is usually water. | * | |||
* A smaller number means more generated buildings. | ||||
* | ||||
* @return The area (m^2) covered by each light. | ||||
*/ | ||||
inline double get_building_coverage () const { return building_coverage; | ||||
} | ||||
/** | ||||
* Get the building spacing. | ||||
* | ||||
* This is the minimum spacing between buildings | ||||
* | ||||
* @return The minimum distance between buildings | ||||
*/ | ||||
inline double get_building_spacing () const { return building_spacing; } | ||||
/** | ||||
* Get the building texture. | ||||
* | ||||
* This is the texture used for auto-generated buildings. | ||||
* | ||||
* @return The texture for auto-generated buildings. | ||||
*/ | */ | |||
bool get_solid () const { return solid; } | inline std::string get_building_texture () const { return building_textur e; } | |||
/** | /** | |||
* Get the friction factor for that material | * Get the building lightmap. | |||
* | ||||
* This is the lightmap used for auto-generated buildings. | ||||
* | ||||
* @return The lightmap for auto-generated buildings. | ||||
*/ | */ | |||
double get_friction_factor () const { return friction_factor; } | inline std::string get_building_lightmap () const { return building_light | |||
map; } | ||||
// Ratio of the 3 random building sizes | ||||
inline double get_building_small_fraction () const { return building_smal | ||||
l_ratio / (building_small_ratio + building_medium_ratio + building_large_ra | ||||
tio); } | ||||
inline double get_building_medium_fraction () const { return building_med | ||||
ium_ratio / (building_small_ratio + building_medium_ratio + building_large_ | ||||
ratio); } | ||||
inline double get_building_large_fraction () const { return building_larg | ||||
e_ratio / (building_small_ratio + building_medium_ratio + building_large_ra | ||||
tio); } | ||||
// Proportion of buildings with pitched roofs | ||||
inline double get_building_small_pitch () const { return building_small_p | ||||
itch; } | ||||
inline double get_building_medium_pitch () const { return building_medium | ||||
_pitch; } | ||||
inline double get_building_large_pitch () const { return building_large_p | ||||
itch; } | ||||
// Min/Max number of floors for each size | ||||
inline int get_building_small_min_floors () const { return building_smal | ||||
l_min_floors; } | ||||
inline int get_building_small_max_floors () const { return building_smal | ||||
l_max_floors; } | ||||
inline int get_building_medium_min_floors () const { return building_medi | ||||
um_min_floors; } | ||||
inline int get_building_medium_max_floors () const { return building_medi | ||||
um_max_floors; } | ||||
inline int get_building_large_min_floors () const { return building_large | ||||
_min_floors; } | ||||
inline int get_building_large_max_floors () const { return building_large | ||||
_max_floors; } | ||||
// Minimum width and depth for each size | ||||
inline double get_building_small_min_width () const { return building_sma | ||||
ll_min_width; } | ||||
inline double get_building_small_max_width () const { return building_sma | ||||
ll_max_width; } | ||||
inline double get_building_small_min_depth () const { return building_sma | ||||
ll_min_depth; } | ||||
inline double get_building_small_max_depth () const { return building_sma | ||||
ll_max_depth; } | ||||
inline double get_building_medium_min_width () const { return building_me | ||||
dium_min_width; } | ||||
inline double get_building_medium_max_width () const { return building_me | ||||
dium_max_width; } | ||||
inline double get_building_medium_min_depth () const { return building_me | ||||
dium_min_depth; } | ||||
inline double get_building_medium_max_depth () const { return building_me | ||||
dium_max_depth; } | ||||
inline double get_building_large_min_width () const { return building_lar | ||||
ge_min_width; } | ||||
inline double get_building_large_max_width () const { return building_lar | ||||
ge_max_width; } | ||||
inline double get_building_large_min_depth () const { return building_lar | ||||
ge_min_depth; } | ||||
inline double get_building_large_max_depth () const { return building_lar | ||||
ge_max_depth; } | ||||
inline double get_building_range () const { return building_range; } | ||||
inline double get_cos_object_max_density_slope_angle () const { return co | ||||
s_object_max_density_slope_angle; } | ||||
inline double get_cos_object_zero_density_slope_angle () const { return c | ||||
os_object_zero_density_slope_angle; } | ||||
/** | /** | |||
* Get the rolling friction for that material | * Get the wood coverage. | |||
* | ||||
* A smaller number means more generated woods within the forest. | ||||
* | ||||
* @return The area (m^2) covered by each wood. | ||||
*/ | */ | |||
double get_rolling_friction () const { return rolling_friction; } | inline double get_wood_coverage () const { return wood_coverage; } | |||
/** | /** | |||
* Get the bumpines for that material | * Get the tree height. | |||
* | ||||
* @return The average height of the trees. | ||||
*/ | */ | |||
double get_bumpiness () const { return bumpiness; } | inline double get_tree_height () const { return tree_height; } | |||
/** | /** | |||
* Get the load resistance | * Get the tree width. | |||
* | ||||
* @return The average width of the trees. | ||||
*/ | */ | |||
double get_load_resistance () const { return load_resistance; } | inline double get_tree_width () const { return tree_width; } | |||
/** | ||||
* Get the forest LoD range. | ||||
* | ||||
* @return The LoD range for the trees. | ||||
*/ | ||||
inline double get_tree_range () const { return tree_range; } | ||||
/** | ||||
* Get the number of tree varieties available | ||||
* | ||||
* @return the number of different trees defined in the texture strip | ||||
*/ | ||||
inline int get_tree_varieties () const { return tree_varieties; } | ||||
/** | ||||
* Get the texture strip to use for trees | ||||
* | ||||
* @return the texture to use for trees. | ||||
*/ | ||||
inline std::string get_tree_texture () const { return tree_texture; } | ||||
/** | ||||
* Get the cosine of the maximum tree density slope angle. We | ||||
* use the cosine as it can be compared directly to the z component | ||||
* of a triangle normal. | ||||
* | ||||
* @return the cosine of the maximum tree density slope angle. | ||||
*/ | ||||
inline double get_cos_tree_max_density_slope_angle () const { return cos_ | ||||
tree_max_density_slope_angle; } | ||||
/** | ||||
* Get the cosine of the maximum tree density slope angle. We | ||||
* use the cosine as it can be compared directly to the z component | ||||
* of a triangle normal. | ||||
* | ||||
* @return the cosine of the maximum tree density slope angle. | ||||
*/ | ||||
inline double get_cos_tree_zero_density_slope_angle () const { return cos | ||||
_tree_zero_density_slope_angle; } | ||||
/** | /** | |||
* Get the list of names for this material | * Get the list of names for this material | |||
*/ | */ | |||
const vector<string>& get_names() const { return _names; } | const std::vector<std::string>& get_names() const { return _names; } | |||
/** | /** | |||
* add the given name to the list of names this material is known | * add the given name to the list of names this material is known | |||
*/ | */ | |||
void add_name(const string& name) { _names.push_back(name); } | void add_name(const std::string& name) { _names.push_back(name); } | |||
/** | /** | |||
* Get the number of randomly-placed objects defined for this material. | * Get the number of randomly-placed objects defined for this material. | |||
*/ | */ | |||
int get_object_group_count () const { return object_groups.size(); } | int get_object_group_count () const { return object_groups.size(); } | |||
/** | /** | |||
* Get a randomly-placed object for this material. | * Get a randomly-placed object for this material. | |||
*/ | */ | |||
SGMatModelGroup * get_object_group (int index) const { | SGMatModelGroup * get_object_group (int index) const { | |||
return object_groups[index]; | return object_groups[index]; | |||
} | } | |||
/** | /** | |||
* Evaluate whether this material is valid given the current global | ||||
* property state. | ||||
*/ | ||||
bool valid() const; | ||||
/** | ||||
* Return pointer to glyph class, or 0 if it doesn't exist. | * Return pointer to glyph class, or 0 if it doesn't exist. | |||
*/ | */ | |||
SGMaterialGlyph * get_glyph (const string& name) const; | SGMaterialGlyph * get_glyph (const std::string& name) const; | |||
void set_light_color(const SGVec4f& color) | ||||
{ emission = color; } | ||||
const SGVec4f& get_light_color() const | ||||
{ return emission; } | ||||
SGVec2f get_tex_coord_scale() const | ||||
{ | ||||
float tex_width = get_xsize(); | ||||
float tex_height = get_ysize(); | ||||
return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f, | ||||
(0 < tex_height) ? 1000.0f/tex_height : 1.0f); | ||||
} | ||||
protected: | protected: | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
// Protected methods. | // Protected methods. | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
/** | /** | |||
* Initialization method, invoked by all public constructors. | * Initialization method, invoked by all public constructors. | |||
*/ | */ | |||
void init(); | void init(); | |||
protected: | protected: | |||
struct _internal_state { | struct _internal_state { | |||
_internal_state( ssgSimpleState *s, const string &t, bool l ) | _internal_state(simgear::Effect *e, bool l, | |||
: state(s), texture_path(t), texture_loaded(l) {} | const simgear::SGReaderWriterOptions *o); | |||
ssgSharedPtr<ssgSimpleState> state; | _internal_state(simgear::Effect *e, const std::string &t, bool l, | |||
string texture_path; | const simgear::SGReaderWriterOptions *o); | |||
bool texture_loaded; | void add_texture(const std::string &t, int i); | |||
osg::ref_ptr<simgear::Effect> effect; | ||||
std::vector<std::pair<std::string,int> > texture_paths; | ||||
bool effect_realized; | ||||
osg::ref_ptr<const simgear::SGReaderWriterOptions> options; | ||||
}; | }; | |||
private: | private: | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
// Internal state. | // Internal state. | |||
//////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////// | |||
// texture status | // texture status | |||
vector<_internal_state> _status; | std::vector<_internal_state> _status; | |||
// Round-robin counter | ||||
unsigned int _current_ptr; | ||||
// texture size | // texture size | |||
double xsize, ysize; | double xsize, ysize; | |||
// wrap texture? | // wrap texture? | |||
bool wrapu, wrapv; | bool wrapu, wrapv; | |||
// use mipmapping? | // use mipmapping? | |||
int mipmap; | bool mipmap; | |||
// coverage of night lighting. | // coverage of night lighting. | |||
double light_coverage; | double light_coverage; | |||
// True if the material is solid, false if it is a fluid | // coverage of buildings | |||
bool solid; | double building_coverage; | |||
// the friction factor of that surface material | ||||
double friction_factor; | ||||
// the rolling friction of that surface material | ||||
double rolling_friction; | ||||
// the bumpiness of that surface material | // building spacing | |||
double bumpiness; | double building_spacing; | |||
// the load resistance of that surface material | // building texture & lightmap | |||
double load_resistance; | std::string building_texture; | |||
std::string building_lightmap; | ||||
// Ratio of the 3 random building sizes | ||||
double building_small_ratio; | ||||
double building_medium_ratio; | ||||
double building_large_ratio; | ||||
// Proportion of buildings with pitched roofs | ||||
double building_small_pitch; | ||||
double building_medium_pitch; | ||||
double building_large_pitch; | ||||
// Min/Max number of floors for each size | ||||
int building_small_min_floors; | ||||
int building_small_max_floors; | ||||
int building_medium_min_floors; | ||||
int building_medium_max_floors; | ||||
int building_large_min_floors; | ||||
int building_large_max_floors; | ||||
// Minimum width and depth for each size | ||||
double building_small_min_width; | ||||
double building_small_max_width; | ||||
double building_small_min_depth; | ||||
double building_small_max_depth; | ||||
double building_medium_min_width; | ||||
double building_medium_max_width; | ||||
double building_medium_min_depth; | ||||
double building_medium_max_depth; | ||||
double building_large_min_width; | ||||
double building_large_max_width; | ||||
double building_large_min_depth; | ||||
double building_large_max_depth; | ||||
double building_range; | ||||
// Cosine of the angle of maximum and zero density, | ||||
// used to stop buildings and random objects from being | ||||
// created on too steep a slope. | ||||
double cos_object_max_density_slope_angle; | ||||
double cos_object_zero_density_slope_angle; | ||||
// coverage of woods | ||||
double wood_coverage; | ||||
// Range at which trees become visible | ||||
double tree_range; | ||||
// Height of the tree | ||||
double tree_height; | ||||
// Width of the tree | ||||
double tree_width; | ||||
// Number of varieties of tree texture | ||||
int tree_varieties; | ||||
// cosine of the tile angle of maximum and zero density, | ||||
// used to stop trees from being created on too steep a slope. | ||||
double cos_tree_max_density_slope_angle; | ||||
double cos_tree_zero_density_slope_angle; | ||||
// material properties | // material properties | |||
SGVec4f ambient, diffuse, specular, emission; | SGVec4f ambient, diffuse, specular, emission; | |||
double shininess; | double shininess; | |||
// effect for this material | ||||
std::string effect; | ||||
// the list of names for this material. May be empty. | // the list of names for this material. May be empty. | |||
vector<string> _names; | std::vector<std::string> _names; | |||
vector<SGSharedPtr<SGMatModelGroup> > object_groups; | std::vector<SGSharedPtr<SGMatModelGroup> > object_groups; | |||
// taxiway-/runway-sign texture elements | // taxiway-/runway-sign texture elements | |||
map<string, SGSharedPtr<SGMaterialGlyph> > glyphs; | std::map<std::string, SGSharedPtr<SGMaterialGlyph> > glyphs; | |||
//////////////////////////////////////////////////////////////////// | ||||
// Internal constructors and methods. | // Tree texture, typically a strip of applicable tree textures | |||
//////////////////////////////////////////////////////////////////// | std::string tree_texture; | |||
SGMaterial( const string &fg_root, const SGMaterial &mat ); // unimplemen | // Object mask, a simple RGB texture used as a mask when placing | |||
ted | // random vegetation, objects and buildings | |||
std::vector<osg::Texture2D*> _masks; | ||||
void read_properties( const string &fg_root, const SGPropertyNode *props, | // Condition, indicating when this material is active | |||
const char *season ); | SGSharedPtr<const SGCondition> condition; | |||
void build_ssg_state( bool defer_tex_load ); | ||||
void set_ssg_state( ssgSimpleState *s ); | ||||
void assignTexture( ssgSimpleState *state, string &fname, int _wrapu = TR | // Parameters from the materials file | |||
UE, int _wrapv = TRUE, int _mipmap = TRUE ); | const SGPropertyNode* parameters; | |||
//////////////////////////////////////////////////////////////////// | ||||
// Internal constructors and methods. | ||||
//////////////////////////////////////////////////////////////////// | ||||
void read_properties(const simgear::SGReaderWriterOptions* options, | ||||
const SGPropertyNode *props, | ||||
SGPropertyNode *prop_root); | ||||
void buildEffectProperties(const simgear::SGReaderWriterOptions* options) | ||||
; | ||||
simgear::Effect* get_effect(int i); | ||||
}; | }; | |||
class SGMaterialGlyph : public SGReferenced { | class SGMaterialGlyph : public SGReferenced { | |||
public: | public: | |||
SGMaterialGlyph(SGPropertyNode *); | SGMaterialGlyph(SGPropertyNode *); | |||
inline double get_left() const { return _left; } | inline double get_left() const { return _left; } | |||
inline double get_right() const { return _right; } | inline double get_right() const { return _right; } | |||
inline double get_width() const { return _right - _left; } | inline double get_width() const { return _right - _left; } | |||
protected: | protected: | |||
double _left; | double _left; | |||
double _right; | double _right; | |||
}; | }; | |||
class SGMaterialUserData : public ssgBase { | class SGMaterialUserData : public osg::Referenced { | |||
public: | public: | |||
SGMaterialUserData(const SGMaterial* material) : | SGMaterialUserData(const SGMaterial* material) : | |||
mMaterial(material) | mMaterial(material) | |||
{} | {} | |||
const SGMaterial* getMaterial() const | const SGMaterial* getMaterial() const | |||
{ return mMaterial; } | { return mMaterial; } | |||
private: | private: | |||
SGSharedPtr<const SGMaterial> mMaterial; | // this cannot be an SGSharedPtr since that would create a cicrular refer | |||
ence | ||||
// making it impossible to ever free the space needed by SGMaterial | ||||
const SGMaterial* mMaterial; | ||||
}; | }; | |||
void | ||||
SGSetTextureFilter( int max); | ||||
int | ||||
SGGetTextureFilter(); | ||||
#endif // _SG_MAT_HXX | #endif // _SG_MAT_HXX | |||
End of changes. 46 change blocks. | ||||
99 lines changed or deleted | 331 lines changed or added | |||
matlib.hxx | matlib.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: matlib.hxx,v 1.12 2006-06-11 13:59:59 frohlich Exp $ | // $Id$ | |||
#ifndef _MATLIB_HXX | #ifndef _MATLIB_HXX | |||
#define _MATLIB_HXX | #define _MATLIB_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/structure/SGSharedPtr.hxx> | #include <simgear/structure/SGSharedPtr.hxx> | |||
#include STL_STRING // Standard C++ string library | #include <string> // Standard C++ string library | |||
#include <map> // STL associative "array" | #include <map> // STL associative "array" | |||
#include <vector> // STL "array" | #include <vector> // STL "array" | |||
#include <plib/ssg.h> // plib include | ||||
class SGMaterial; | class SGMaterial; | |||
class SGPropertyNode; | ||||
SG_USING_STD(string); | namespace simgear { class Effect; } | |||
SG_USING_STD(map); | namespace osg { class Geode; } | |||
SG_USING_STD(vector); | ||||
SG_USING_STD(less); | ||||
// Material management class | // Material management class | |||
class SGMaterialLib { | class SGMaterialLib { | |||
private: | private: | |||
// associative array of materials | // associative array of materials | |||
typedef map < string, SGSharedPtr<SGMaterial>, less<string> > material_ | typedef std::vector< SGSharedPtr<SGMaterial> > material_list; | |||
map; | typedef material_list::iterator material_list_iterator; | |||
typedef std::map < std::string, material_list> material_map; | ||||
typedef material_map::iterator material_map_iterator; | typedef material_map::iterator material_map_iterator; | |||
typedef material_map::const_iterator const_material_map_iterator; | typedef material_map::const_iterator const_material_map_iterator; | |||
material_map matlib; | material_map matlib; | |||
public: | public: | |||
// Constructor | // Constructor | |||
SGMaterialLib ( void ); | SGMaterialLib ( void ); | |||
// Load a library of material properties | // Load a library of material properties | |||
bool load( const string &fg_root, const string& mpath, const char *seas | bool load( const std::string &fg_root, const std::string& mpath, | |||
on ); | SGPropertyNode *prop_root ); | |||
// Add the named texture with default properties | ||||
bool add_item( const string &tex_path ); | ||||
bool add_item( const string &mat_name, const string &tex_path ); | ||||
bool add_item( const string &mat_name, ssgSimpleState *state ); | ||||
// find a material record by material name | // find a material record by material name | |||
SGMaterial *find( const string& material ); | SGMaterial *find( const std::string& material ); | |||
/** | ||||
* Load the next deferred texture, if there is any. | ||||
*/ | ||||
void load_next_deferred(); | ||||
material_map_iterator begin() { return matlib.begin(); } | material_map_iterator begin() { return matlib.begin(); } | |||
const_material_map_iterator begin() const { return matlib.begin(); } | const_material_map_iterator begin() const { return matlib.begin(); } | |||
material_map_iterator end() { return matlib.end(); } | material_map_iterator end() { return matlib.end(); } | |||
const_material_map_iterator end() const { return matlib.end(); } | const_material_map_iterator end() const { return matlib.end(); } | |||
const SGMaterial* findMaterial(/*const*/ssgLeaf* leaf) const; | static const SGMaterial *findMaterial(const osg::Geode* geode); | |||
// Destructor | // Destructor | |||
~SGMaterialLib ( void ); | ~SGMaterialLib ( void ); | |||
}; | }; | |||
#endif // _MATLIB_HXX | #endif // _MATLIB_HXX | |||
End of changes. 10 change blocks. | ||||
29 lines changed or deleted | 12 lines changed or added | |||
matmodel.hxx | matmodel.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: matmodel.hxx,v 1.6 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_MAT_MODEL_HXX | #ifndef _SG_MAT_MODEL_HXX | |||
#define _SG_MAT_MODEL_HXX | #define _SG_MAT_MODEL_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING // Standard C++ string library | #include <string> // Standard C++ string library | |||
#include <vector> | ||||
#include <plib/sg.h> | #include <osg/ref_ptr> | |||
#include <plib/ssg.h> | #include <osg/Node> | |||
#include <osg/NodeVisitor> | ||||
#include <osg/Billboard> | ||||
#include <simgear/structure/SGReferenced.hxx> | #include <simgear/structure/SGReferenced.hxx> | |||
#include <simgear/structure/SGSharedPtr.hxx> | #include <simgear/structure/SGSharedPtr.hxx> | |||
#include <simgear/structure/ssgSharedPtr.hxx> | ||||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <simgear/math/sg_random.h> | ||||
SG_USING_STD(string); | ||||
class SGMatModelGroup; | class SGMatModelGroup; | |||
class SGModelLib; | ||||
/** | /** | |||
* A randomly-placeable object. | * A randomly-placeable object. | |||
* | * | |||
* SGMaterial uses this class to keep track of the model(s) and | * SGMaterial uses this class to keep track of the model(s) and | |||
* parameters for a single instance of a randomly-placeable object. | * parameters for a single instance of a randomly-placeable object. | |||
* The object can have more than one variant model (i.e. slightly | * The object can have more than one variant model (i.e. slightly | |||
* different shapes of trees), but they are considered equivalent | * different shapes of trees), but they are considered equivalent | |||
* and interchangeable. | * and interchangeable. | |||
*/ | */ | |||
class SGMatModel : public SGReferenced { | class SGMatModel : public SGReferenced { | |||
public: | public: | |||
/** | /** | |||
* The heading type for a randomly-placed object. | * The heading type for a randomly-placed object. | |||
*/ | */ | |||
enum HeadingType { | enum HeadingType { | |||
HEADING_FIXED, | HEADING_FIXED, | |||
HEADING_BILLBOARD, | HEADING_BILLBOARD, | |||
HEADING_RANDOM | HEADING_RANDOM, | |||
HEADING_MASK | ||||
}; | }; | |||
/** | /** | |||
* Get the number of variant models available for the object. | * Get the number of variant models available for the object. | |||
* | * | |||
* @return The number of variant models. | * @return The number of variant models. | |||
*/ | */ | |||
int get_model_count( SGModelLib *modellib, | int get_model_count( SGPropertyNode *prop_root ); | |||
const string &fg_root, | ||||
SGPropertyNode *prop_root, | ||||
double sim_time_sec ); | ||||
/** | ||||
* Get a specific variant model for the object. | ||||
* | ||||
* @param index The index of the model. | ||||
* @return The model. | ||||
*/ | ||||
ssgEntity *get_model( int index, | ||||
SGModelLib *modellib, | ||||
const string &fg_root, | ||||
SGPropertyNode *prop_root, | ||||
double sim_time_sec ); | ||||
/** | /** | |||
* Get a randomly-selected variant model for the object. | * Get a randomly-selected variant model for the object. | |||
* | * | |||
* @return A randomly select model from the variants. | * @return A randomly select model from the variants. | |||
*/ | */ | |||
ssgEntity *get_random_model( SGModelLib *modellib, | osg::Node *get_random_model( SGPropertyNode *prop_root, mt *seed ); | |||
const string &fg_root, | ||||
SGPropertyNode *prop_root, | ||||
double sim_time_sec ); | ||||
/** | /** | |||
* Get the average number of meters^2 occupied by each instance. | * Get the average number of meters^2 occupied by each instance. | |||
* | * | |||
* @return The coverage in meters^2. | * @return The coverage in meters^2. | |||
*/ | */ | |||
double get_coverage_m2 () const; | double get_coverage_m2 () const; | |||
/** | /** | |||
* Get the visual range of the object in meters. | ||||
* | ||||
* @return The visual range. | ||||
*/ | ||||
double get_range_m () const; | ||||
/** | ||||
* Get the minimum spacing between this and any | ||||
* other objects in m | ||||
* | ||||
* @return The spacing in m. | ||||
*/ | ||||
double get_spacing_m () const; | ||||
/** | ||||
* Get a randomized visual range | ||||
* | ||||
* @return a randomized visual range | ||||
*/ | ||||
double get_randomized_range_m(mt* seed) const; | ||||
/** | ||||
* Get the heading type for the object. | * Get the heading type for the object. | |||
* | * | |||
* @return The heading type. | * @return The heading type. | |||
*/ | */ | |||
HeadingType get_heading_type () const; | HeadingType get_heading_type () const; | |||
virtual ~SGMatModel (); | virtual ~SGMatModel (); | |||
protected: | protected: | |||
skipping to change at line 131 | skipping to change at line 136 | |||
SGMatModel (const SGPropertyNode * node, double range_m); | SGMatModel (const SGPropertyNode * node, double range_m); | |||
private: | private: | |||
/** | /** | |||
* Actually load the models. | * Actually load the models. | |||
* | * | |||
* This class uses lazy loading so that models won't be held | * This class uses lazy loading so that models won't be held | |||
* in memory for materials that are never referenced. | * in memory for materials that are never referenced. | |||
*/ | */ | |||
void load_models( SGModelLib *modellib, | void load_models( SGPropertyNode *prop_root ); | |||
const string &fg_root, | ||||
SGPropertyNode *prop_root, | ||||
double sim_time_sec ); | ||||
vector<string> _paths; | std::vector<std::string> _paths; | |||
mutable vector<ssgSharedPtr<ssgEntity> > _models; | mutable std::vector<osg::ref_ptr<osg::Node> > _models; | |||
mutable bool _models_loaded; | mutable bool _models_loaded; | |||
double _coverage_m2; | double _coverage_m2; | |||
double _spacing_m; | ||||
double _range_m; | double _range_m; | |||
HeadingType _heading_type; | HeadingType _heading_type; | |||
}; | }; | |||
/** | /** | |||
* A collection of related objects with the same visual range. | * A collection of related objects with the same visual range. | |||
* | * | |||
* Grouping objects with the same range together significantly | * Grouping objects with the same range together significantly | |||
* reduces the memory requirements of randomly-placed objects. | * reduces the memory requirements of randomly-placed objects. | |||
* Each SGMaterial instance keeps a (possibly-empty) list of | * Each SGMaterial instance keeps a (possibly-empty) list of | |||
skipping to change at line 189 | skipping to change at line 192 | |||
protected: | protected: | |||
friend class SGMaterial; | friend class SGMaterial; | |||
SGMatModelGroup (SGPropertyNode * node); | SGMatModelGroup (SGPropertyNode * node); | |||
private: | private: | |||
double _range_m; | double _range_m; | |||
vector<SGSharedPtr<SGMatModel> > _objects; | std::vector<SGSharedPtr<SGMatModel> > _objects; | |||
}; | }; | |||
#endif // _SG_MAT_MODEL_HXX | #endif // _SG_MAT_MODEL_HXX | |||
End of changes. 14 change blocks. | ||||
37 lines changed or deleted | 39 lines changed or added | |||
mercury.hxx | mercury.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: mercury.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _MERCURY_HXX_ | #ifndef _MERCURY_HXX_ | |||
#define _MERCURY_HXX_ | #define _MERCURY_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Mercury : public CelestialBody | class Mercury : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
metar.hxx | metar.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: metar.hxx,v 1.9 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _METAR_HXX | #ifndef _METAR_HXX | |||
#define _METAR_HXX | #define _METAR_HXX | |||
#include <vector> | #include <vector> | |||
#include <map> | #include <map> | |||
#include <string> | #include <string> | |||
#include <simgear/constants.h> | #include <simgear/constants.h> | |||
SG_USING_STD(vector); | ||||
SG_USING_STD(map); | ||||
SG_USING_STD(string); | ||||
const double SGMetarNaN = -1E20; | ||||
#define NaN SGMetarNaN | ||||
struct Token { | struct Token { | |||
char *id; | const char *id; | |||
char *text; | const char *text; | |||
}; | }; | |||
const double SGMetarNaN = -1E20; | ||||
class SGMetar; | class SGMetar; | |||
class SGMetarVisibility { | class SGMetarVisibility { | |||
friend class SGMetar; | friend class SGMetar; | |||
public: | public: | |||
SGMetarVisibility() : | SGMetarVisibility() : | |||
_distance(NaN), | _distance(SGMetarNaN), | |||
_direction(-1), | _direction(-1), | |||
_modifier(EQUALS), | _modifier(EQUALS), | |||
_tendency(NONE) {} | _tendency(NONE) {} | |||
enum Modifier { | enum Modifier { | |||
NOGO, | NOGO, | |||
EQUALS, | EQUALS, | |||
LESS_THAN, | LESS_THAN, | |||
GREATER_THAN | GREATER_THAN | |||
}; | }; | |||
skipping to change at line 72 | skipping to change at line 67 | |||
enum Tendency { | enum Tendency { | |||
NONE, | NONE, | |||
STABLE, | STABLE, | |||
INCREASING, | INCREASING, | |||
DECREASING | DECREASING | |||
}; | }; | |||
void set(double dist, int dir = -1, int mod = -1, int tend = -1); | void set(double dist, int dir = -1, int mod = -1, int tend = -1); | |||
inline double getVisibility_m() const { return _distance; } | inline double getVisibility_m() const { return _distance; } | |||
inline double getVisibility_ft() const { return _distance == | inline double getVisibility_ft() const { return _distance == | |||
NaN ? NaN : _distance * SG_METER_TO_FEET; } | SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_FEET; } | |||
inline double getVisibility_sm() const { return _distance == | inline double getVisibility_sm() const { return _distance == | |||
NaN ? NaN : _distance * SG_METER_TO_SM; } | SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_SM; } | |||
inline int getDirection() const { return _direction; } | inline int getDirection() const { return _direction; } | |||
inline int getModifier() const { return _modifier; } | inline int getModifier() const { return _modifier; } | |||
inline int getTendency() const { return _tendency; } | inline int getTendency() const { return _tendency; } | |||
protected: | protected: | |||
double _distance; | double _distance; | |||
int _direction; | int _direction; | |||
int _modifier; | int _modifier; | |||
int _tendency; | int _tendency; | |||
}; | }; | |||
// runway condition (surface and visibility) | // runway condition (surface and visibility) | |||
class SGMetarRunway { | class SGMetarRunway { | |||
friend class SGMetar; | friend class SGMetar; | |||
public: | public: | |||
SGMetarRunway() : | SGMetarRunway() : | |||
_deposit(-1), | _deposit(-1), | |||
_deposit_string(0), | _deposit_string(0), | |||
_extent(-1), | _extent(-1), | |||
_extent_string(0), | _extent_string(0), | |||
_depth(NaN), | _depth(SGMetarNaN), | |||
_friction(NaN), | _friction(SGMetarNaN), | |||
_friction_string(0), | _friction_string(0), | |||
_comment(0), | _comment(0), | |||
_wind_shear(false) {} | _wind_shear(false) {} | |||
inline int getDeposit() const { retu rn _deposit; } | inline int getDeposit() const { retu rn _deposit; } | |||
inline const char *getDepositString() const { retu rn _deposit_string; } | inline const char *getDepositString() const { retu rn _deposit_string; } | |||
inline double getExtent() const { retu rn _extent; } | inline double getExtent() const { retu rn _extent; } | |||
inline const char *getExtentString() const { retu rn _extent_string; } | inline const char *getExtentString() const { retu rn _extent_string; } | |||
inline double getDepth() const { retu rn _depth; } | inline double getDepth() const { retu rn _depth; } | |||
inline double getFriction() const { retu rn _friction; } | inline double getFriction() const { retu rn _friction; } | |||
inline const char *getFrictionString() const { retu rn _friction_string; } | inline const char *getFrictionString() const { retu rn _friction_string; } | |||
inline const char *getComment() const { retu rn _comment; } | inline const char *getComment() const { retu rn _comment; } | |||
inline const bool getWindShear() const { retu rn _wind_shear; } | inline bool getWindShear() const { retu rn _wind_shear; } | |||
inline const SGMetarVisibility& getMinVisibility() const { retu rn _min_visibility; } | inline const SGMetarVisibility& getMinVisibility() const { retu rn _min_visibility; } | |||
inline const SGMetarVisibility& getMaxVisibility() const { retu rn _max_visibility; } | inline const SGMetarVisibility& getMaxVisibility() const { retu rn _max_visibility; } | |||
protected: | protected: | |||
SGMetarVisibility _min_visibility; | SGMetarVisibility _min_visibility; | |||
SGMetarVisibility _max_visibility; | SGMetarVisibility _max_visibility; | |||
int _deposit; | int _deposit; | |||
const char *_deposit_string; | const char *_deposit_string; | |||
int _extent; | int _extent; | |||
const char *_extent_string; | const char *_extent_string; | |||
skipping to change at line 130 | skipping to change at line 125 | |||
double _friction; | double _friction; | |||
const char *_friction_string; | const char *_friction_string; | |||
const char *_comment; | const char *_comment; | |||
bool _wind_shear; | bool _wind_shear; | |||
}; | }; | |||
// cloud layer | // cloud layer | |||
class SGMetarCloud { | class SGMetarCloud { | |||
friend class SGMetar; | friend class SGMetar; | |||
public: | public: | |||
SGMetarCloud() : | enum Coverage { | |||
_coverage(-1), | COVERAGE_NIL = -1, | |||
_altitude(NaN), | COVERAGE_CLEAR = 0, | |||
_type(0), | COVERAGE_FEW = 1, | |||
_type_long(0) {} | COVERAGE_SCATTERED = 2, | |||
COVERAGE_BROKEN = 3, | ||||
void set(double alt, int cov = -1); | COVERAGE_OVERCAST = 4 | |||
}; | ||||
inline int getCoverage() const { return _coverage; } | ||||
inline double getAltitude_m() const { return _altitude; } | static const char * COVERAGE_NIL_STRING; | |||
inline double getAltitude_ft() const { return _altitude == | static const char * COVERAGE_CLEAR_STRING; | |||
NaN ? NaN : _altitude * SG_METER_TO_FEET; } | static const char * COVERAGE_FEW_STRING; | |||
inline char *getTypeString() const { return _type; } | static const char * COVERAGE_SCATTERED_STRING; | |||
inline char *getTypeLongString() const { return _type_long; } | static const char * COVERAGE_BROKEN_STRING; | |||
static const char * COVERAGE_OVERCAST_STRING; | ||||
SGMetarCloud() : _coverage(COVERAGE_NIL), _altitude(SGMetarNaN), _ty | ||||
pe(0), _type_long(0) {} | ||||
void set(double alt, Coverage cov = COVERAGE_NIL ); | ||||
inline Coverage getCoverage() const { return _coverage; } | ||||
static Coverage getCoverage( const std::string & coverage ); | ||||
inline double getAltitude_m() const { return _altitude; } | ||||
inline double getAltitude_ft() const { return _altitude == SGMetarNa | ||||
N ? SGMetarNaN : _altitude * SG_METER_TO_FEET; } | ||||
inline const char *getTypeString() const { return _type; } | ||||
inline const char *getTypeLongString() const { return _type_long; } | ||||
protected: | protected: | |||
int _coverage; // quarters: 0 -> clear ... 4 -> ove | Coverage _coverage; // quarters: 0 -> clear ... 4 -> overcast | |||
rcast | double _altitude; // 1000 m | |||
double _altitude; // 1000 m | const char *_type; // CU | |||
char *_type; // CU | const char *_type_long; // cumulus | |||
char *_type_long; // cumulus | ||||
}; | }; | |||
class SGMetar { | class SGMetar { | |||
public: | public: | |||
SGMetar(const string& m, const string& proxy = "", const string& por | SGMetar(const std::string& m); | |||
t = "", | ||||
const string &auth = "", const time_t time = 0); | ||||
~SGMetar(); | ~SGMetar(); | |||
enum ReportType { | enum ReportType { | |||
NONE, | NONE, | |||
AUTO, | AUTO, | |||
COR, | COR, | |||
RTD | RTD | |||
}; | }; | |||
enum Intensity { | ||||
NIL = 0, | ||||
LIGHT = 1, | ||||
MODERATE = 2, | ||||
HEAVY = 3 | ||||
}; | ||||
struct Weather { | ||||
Weather() { intensity = NIL; vincinity = false; } | ||||
Intensity intensity; | ||||
bool vincinity; | ||||
std::vector<std::string> descriptions; | ||||
std::vector<std::string> phenomena; | ||||
}; | ||||
inline const char *getData() const { return _data; } | inline const char *getData() const { return _data; } | |||
inline const char *getUnusedData() const { return _m; } | inline const char *getUnusedData() const { return _m; } | |||
inline const bool getProxy() const { return _x_proxy; } | inline bool getProxy() const { return _x_proxy; } | |||
inline const char *getId() const { return _icao; } | inline const char *getId() const { return _icao; } | |||
inline int getYear() const { return _year; } | inline int getYear() const { return _year; } | |||
inline int getMonth() const { return _month; } | inline int getMonth() const { return _month; } | |||
inline int getDay() const { return _day; } | inline int getDay() const { return _day; } | |||
inline int getHour() const { return _hour; } | inline int getHour() const { return _hour; } | |||
inline int getMinute() const { return _minute; } | inline int getMinute() const { return _minute; } | |||
inline int getReportType() const { return _report_type; } | inline int getReportType() const { return _report_type; } | |||
inline int getWindDir() const { return _wind_dir; } | inline int getWindDir() const { return _wind_dir; } | |||
inline double getWindSpeed_mps() const { return _wind_speed; } | inline double getWindSpeed_mps() const { return _wind_speed; } | |||
inline double getWindSpeed_kmh() const { return _wind_speed = | inline double getWindSpeed_kmh() const { return _wind_speed = | |||
= NaN ? NaN : _wind_speed * SG_MPS_TO_KMH; } | = SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KMH; } | |||
inline double getWindSpeed_kt() const { return _wind_speed = | inline double getWindSpeed_kt() const { return _wind_speed = | |||
= NaN ? NaN : _wind_speed * SG_MPS_TO_KT; } | = SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KT; } | |||
inline double getWindSpeed_mph() const { return _wind_speed = | inline double getWindSpeed_mph() const { return _wind_speed = | |||
= NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; } | = SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_MPH; } | |||
inline double getGustSpeed_mps() const { return _gust_speed; } | inline double getGustSpeed_mps() const { return _gust_speed; } | |||
inline double getGustSpeed_kmh() const { return _gust_speed = | inline double getGustSpeed_kmh() const { return _gust_speed = | |||
= NaN ? NaN : _gust_speed * SG_MPS_TO_KMH; } | = SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KMH; } | |||
inline double getGustSpeed_kt() const { return _gust_speed = | inline double getGustSpeed_kt() const { return _gust_speed = | |||
= NaN ? NaN : _gust_speed * SG_MPS_TO_KT; } | = SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KT; } | |||
inline double getGustSpeed_mph() const { return _gust_speed = | inline double getGustSpeed_mph() const { return _gust_speed = | |||
= NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; } | = SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_MPH; } | |||
inline int getWindRangeFrom() const { return _wind_range_f rom; } | inline int getWindRangeFrom() const { return _wind_range_f rom; } | |||
inline int getWindRangeTo() const { return _wind_range_t o; } | inline int getWindRangeTo() const { return _wind_range_t o; } | |||
inline const SGMetarVisibility& getMinVisibility() const { retu rn _min_visibility; } | inline const SGMetarVisibility& getMinVisibility() const { retu rn _min_visibility; } | |||
inline const SGMetarVisibility& getMaxVisibility() const { retu rn _max_visibility; } | inline const SGMetarVisibility& getMaxVisibility() const { retu rn _max_visibility; } | |||
inline const SGMetarVisibility& getVertVisibility() const { retu rn _vert_visibility; } | inline const SGMetarVisibility& getVertVisibility() const { retu rn _vert_visibility; } | |||
inline const SGMetarVisibility *getDirVisibility() const { retu rn _dir_visibility; } | inline const SGMetarVisibility *getDirVisibility() const { retu rn _dir_visibility; } | |||
inline double getTemperature_C() const { return _temp; } | inline double getTemperature_C() const { return _temp; } | |||
inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; } | inline double getTemperature_F() const { return _temp == SGMe tarNaN ? SGMetarNaN : 1.8 * _temp + 32; } | |||
inline double getDewpoint_C() const { return _dewp; } | inline double getDewpoint_C() const { return _dewp; } | |||
inline double getDewpoint_F() const { return _dewp == NaN | inline double getDewpoint_F() const { return _dewp == SGMe | |||
? NaN : 1.8 * _dewp + 32; } | tarNaN ? SGMetarNaN : 1.8 * _dewp + 32; } | |||
inline double getPressure_hPa() const { return _pressure == | inline double getPressure_hPa() const { return _pressure == | |||
NaN ? NaN : _pressure / 100; } | SGMetarNaN ? SGMetarNaN : _pressure / 100; } | |||
inline double getPressure_inHg() const { return _pressure == | inline double getPressure_inHg() const { return _pressure == | |||
NaN ? NaN : _pressure * SG_PA_TO_INHG; } | SGMetarNaN ? SGMetarNaN : _pressure * SG_PA_TO_INHG; } | |||
inline int getRain() const { return _rain; } | inline int getRain() const { return _rain; } | |||
inline int getHail() const { return _hail; } | inline int getHail() const { return _hail; } | |||
inline int getSnow() const { return _snow; } | inline int getSnow() const { return _snow; } | |||
inline bool getCAVOK() const { return _cavok; } | inline bool getCAVOK() const { return _cavok; } | |||
double getRelHumidity() const; | double getRelHumidity() const; | |||
inline const vector<SGMetarCloud>& getClouds() const { return _cl | inline const std::vector<SGMetarCloud>& getClouds() const { re | |||
ouds; } | turn _clouds; } | |||
inline const map<string, SGMetarRunway>& getRunways() const { re | inline const std::map<std::string, SGMetarRunway>& getRunways() cons | |||
turn _runways; } | t { return _runways; } | |||
inline const vector<string>& getWeather() const { re | inline const std::vector<std::string>& getWeather() cons | |||
turn _weather; } | t { return _weather; } | |||
inline const std::vector<struct Weather> getWeather2() const { re | ||||
turn _weather2; } | ||||
protected: | protected: | |||
string _url; | std::string _url; | |||
int _grpcount; | int _grpcount; | |||
bool _x_proxy; | bool _x_proxy; | |||
char *_data; | char *_data; | |||
char *_m; | char *_m; | |||
char _icao[5]; | char _icao[5]; | |||
int _year; | int _year; | |||
int _month; | int _month; | |||
int _day; | int _day; | |||
int _hour; | int _hour; | |||
int _minute; | int _minute; | |||
skipping to change at line 237 | skipping to change at line 260 | |||
double _gust_speed; | double _gust_speed; | |||
int _wind_range_from; | int _wind_range_from; | |||
int _wind_range_to; | int _wind_range_to; | |||
double _temp; | double _temp; | |||
double _dewp; | double _dewp; | |||
double _pressure; | double _pressure; | |||
int _rain; | int _rain; | |||
int _hail; | int _hail; | |||
int _snow; | int _snow; | |||
bool _cavok; | bool _cavok; | |||
std::vector<struct Weather> _weather2; | ||||
SGMetarVisibility _min_visibility; | SGMetarVisibility _min_visibility; | |||
SGMetarVisibility _max_visibility; | SGMetarVisibility _max_visibility; | |||
SGMetarVisibility _vert_visibility; | SGMetarVisibility _vert_visibility; | |||
SGMetarVisibility _dir_visibility[8]; | SGMetarVisibility _dir_visibility[8]; | |||
vector<SGMetarCloud> _clouds; | std::vector<SGMetarCloud> _clouds; | |||
map<string, SGMetarRunway> _runways; | std::map<std::string, SGMetarRunway> _runways; | |||
vector<string> _weather; | std::vector<std::string> _weather; | |||
bool scanPreambleDate(); | bool scanPreambleDate(); | |||
bool scanPreambleTime(); | bool scanPreambleTime(); | |||
void useCurrentDate(); | void useCurrentDate(); | |||
bool scanType(); | bool scanType(); | |||
bool scanId(); | bool scanId(); | |||
bool scanDate(); | bool scanDate(); | |||
bool scanModifier(); | bool scanModifier(); | |||
bool scanWind(); | bool scanWind(); | |||
skipping to change at line 272 | skipping to change at line 296 | |||
bool scanRunwayReport(); | bool scanRunwayReport(); | |||
bool scanWindShear(); | bool scanWindShear(); | |||
bool scanTrendForecast(); | bool scanTrendForecast(); | |||
bool scanColorState(); | bool scanColorState(); | |||
bool scanRemark(); | bool scanRemark(); | |||
bool scanRemainder(); | bool scanRemainder(); | |||
int scanNumber(char **str, int *num, int min, int max = 0); | int scanNumber(char **str, int *num, int min, int max = 0); | |||
bool scanBoundary(char **str); | bool scanBoundary(char **str); | |||
const struct Token *scanToken(char **str, const struct Token *list); | const struct Token *scanToken(char **str, const struct Token *list); | |||
char *loadData(const char *id, const string& proxy, const string& | ||||
port, | ||||
const string &auth, time_t time); | ||||
void normalizeData(); | void normalizeData(); | |||
}; | }; | |||
#undef NaN | ||||
#endif // _METAR_HXX | #endif // _METAR_HXX | |||
End of changes. 23 change blocks. | ||||
74 lines changed or deleted | 94 lines changed or added | |||
model.hxx | model.hxx | |||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <vector> | #include <vector> | |||
#include <set> | #include <set> | |||
SG_USING_STD(vector); | #include <osg/Node> | |||
SG_USING_STD(set); | #include <osg/Texture2D> | |||
#include <osgDB/ReaderWriter> | ||||
#include <plib/sg.h> | ||||
#include <plib/ssg.h> | ||||
#include <simgear/misc/sg_path.hxx> | #include <simgear/misc/sg_path.hxx> | |||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <simgear/scene/util/NodeAndDrawableVisitor.hxx> | ||||
// Has anyone done anything *really* stupid, like making min and max macros | namespace simgear | |||
? | { | |||
#ifdef min | class SGReaderWriterOptions; | |||
#undef min | } | |||
#endif | ||||
#ifdef max | osg::Texture2D* | |||
#undef max | SGLoadTexture2D(bool staticTexture, const std::string& path, | |||
#endif | const osgDB::Options* options = 0, | |||
bool wrapu = true, bool wrapv = true, int mipmaplevels = -1 | ||||
); | ||||
inline osg::Texture2D* | ||||
SGLoadTexture2D(const std::string& path, | ||||
const osgDB::Options* options = 0, | ||||
bool wrapu = true, bool wrapv = true, int mipmaplevels = -1 | ||||
) | ||||
{ | ||||
return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels) | ||||
; | ||||
} | ||||
inline osg::Texture2D* | ||||
SGLoadTexture2D(const SGPath& path, | ||||
const osgDB::Options* options = 0, | ||||
bool wrapu = true, bool wrapv = true, | ||||
int mipmaplevels = -1) | ||||
{ | ||||
return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv, | ||||
mipmaplevels); | ||||
} | ||||
inline osg::Texture2D* | ||||
SGLoadTexture2D(bool staticTexture, const SGPath& path, | ||||
const osgDB::Options* options = 0, | ||||
bool wrapu = true, bool wrapv = true, | ||||
int mipmaplevels = -1) | ||||
{ | ||||
return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv | ||||
, | ||||
mipmaplevels); | ||||
} | ||||
namespace simgear | ||||
{ | ||||
osg::Node* copyModel(osg::Node* model); | ||||
/** | // Change the StateSets of a model to hold different textures based on | |||
* Abstract class for adding data to the scene graph. modelLoaded() is | // a livery path. | |||
* called by sgLoad3DModel() after the model was loaded, and the destructor | ||||
* when the branch is removed from the graph. | class TextureUpdateVisitor : public NodeAndDrawableVisitor | |||
*/ | { | |||
class SGModelData : public ssgBase { | ||||
public: | public: | |||
virtual ~SGModelData() {} | TextureUpdateVisitor(const osgDB::FilePathList& pathList); | |||
virtual void modelLoaded( const string& path, SGPropertyNode *prop, | virtual void apply(osg::Node& node); | |||
ssgBranch *branch) {} | virtual void apply(osg::Drawable& drawable); | |||
// Copied from Mathias' earlier SGTextureUpdateVisitor | ||||
protected: | ||||
osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* att | ||||
r); | ||||
osg::StateSet* cloneStateSet(const osg::StateSet* stateSet); | ||||
private: | ||||
osgDB::FilePathList _pathList; | ||||
}; | }; | |||
/** | // Create new userdata structs in a copied model. | |||
* Load a 3D model with or without XML wrapper. Note, this version | // The BVH trees are shared with the original model, but the velocity field | |||
* Does not know about or load the panel/cockpit information. Use the | s | |||
* "model_panel.hxx" version if you want to load an aircraft | // should usually be distinct fields for distinct models. | |||
* (i.e. ownship) with a panel. | class UserDataCopyVisitor : public osg::NodeVisitor | |||
* | { | |||
* If the path ends in ".xml", then it will be used as a property- | public: | |||
* list wrapper to add animations to the model. | UserDataCopyVisitor(); | |||
* | virtual void apply(osg::Node& node); | |||
* Subsystems should not normally invoke this function directly; | }; | |||
* instead, they should use the FGModelLoader declared in loader.hxx. | ||||
*/ | ||||
ssgBranch * | ||||
sgLoad3DModel( const string& fg_root, const string &path, | ||||
SGPropertyNode *prop_root, double sim_time_sec, | ||||
ssgEntity *(*load_panel)(SGPropertyNode *) = 0, | ||||
SGModelData *data = 0 ); | ||||
/** | ||||
* Make an offset matrix from rotations and position offset. | ||||
*/ | ||||
void | ||||
sgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_ | ||||
rot, | ||||
double x_off, double y_off, double z_off ); | ||||
/** | ||||
* Make the animation | ||||
*/ | ||||
void | ||||
sgMakeAnimation( ssgBranch * model, | ||||
const char * name, | ||||
vector<SGPropertyNode_ptr> &name_nodes, | ||||
SGPropertyNode *prop_root, | ||||
SGPropertyNode_ptr node, | ||||
double sim_time_sec, | ||||
const SGPath &texture_path, | ||||
set<ssgBranch *> &ignore_branches ); | ||||
/** | ||||
* Set the filter state on models | ||||
*/ | ||||
bool | ||||
sgSetModelFilter( bool filter ); | ||||
/** | /** | |||
* Check if the ssg node contains an animation | * Transform an OSG subgraph by substituting Effects and EffectGeodes | |||
* for osg::Geodes with osg::StateSets. This is only guaranteed to | ||||
* work for models prouced by the .ac loader. | ||||
* | ||||
* returns a copy if any nodes are changed | ||||
*/ | */ | |||
bool | osg::ref_ptr<osg::Node> | |||
sgCheckAnimationBranch (ssgEntity * entity); | instantiateEffects(osg::Node* model, | |||
PropertyList& effectProps, | ||||
const SGReaderWriterOptions* options); | ||||
/** | /** | |||
* Enable or disable Display list usage | * Transform an OSG subgraph by substituting the Effects and | |||
* EffectGeodes for osg::Geodes with osg::StateSets, inheriting from | ||||
* the default model effect. This is only guaranteed to work for | ||||
* models prouced by the .ac loader. | ||||
* | ||||
* returns a copy if any nodes are changed | ||||
*/ | */ | |||
extern bool sgUseDisplayList; | ||||
inline osg::ref_ptr<osg::Node> | ||||
instantiateEffects(osg::Node* model, | ||||
const SGReaderWriterOptions* options) | ||||
{ | ||||
PropertyList effectProps; | ||||
return instantiateEffects(model, effectProps, options); | ||||
} | ||||
} | ||||
#endif // __MODEL_HXX | #endif // __MODEL_HXX | |||
End of changes. 11 change blocks. | ||||
71 lines changed or deleted | 97 lines changed or added | |||
modellib.hxx | modellib.hxx | |||
---|---|---|---|---|
// modellib.cxx - implement an SSG model library. | // Copyright (C) 2008 Till Busch buti@bux.at | |||
// | ||||
// This program is free software; you can redistribute it and/or | ||||
// modify it under the terms of the GNU General Public License as | ||||
// published by the Free Software Foundation; either version 2 of the | ||||
// License, or (at your option) any later version. | ||||
// | ||||
// This program is distributed in the hope that it will be useful, but | ||||
// WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
// General Public License for more details. | ||||
// | ||||
// You should have received a copy of the GNU General Public License | ||||
// along with this program; if not, write to the Free Software | ||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 | ||||
1, USA. | ||||
// | ||||
#ifndef _SG_MODEL_LIB_HXX | #ifndef _SG_MODEL_LIB_HXX | |||
#define _SG_MODEL_LIB_HXX 1 | #define _SG_MODEL_LIB_HXX 1 | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> // for SG_USING_STD | #include <simgear/compiler.h> // for SG_USING_STD | |||
#include <map> | #include <string> | |||
#include STL_STRING | ||||
#include <plib/ssg.h> | #include <osg/Node> | |||
#include <osgDB/ReaderWriter> | ||||
#include <simgear/structure/ssgSharedPtr.hxx> | ||||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include "model.hxx" | #include <simgear/misc/sg_path.hxx> | |||
SG_USING_STD(map); | namespace simgear { | |||
SG_USING_STD(string); | ||||
class SGModelData; // defined below | ||||
/** | /** | |||
* Class for loading and managing models with XML wrappers. | * Class for loading and managing models with XML wrappers. | |||
*/ | */ | |||
class SGModelLib | class SGModelLib | |||
{ | { | |||
public: | public: | |||
typedef osg::Node *(*panel_func)(SGPropertyNode *); | ||||
static void init(const std::string &root_dir, SGPropertyNode* root); | ||||
SGModelLib (); | static void setPanelFunc(panel_func pf); | |||
virtual ~SGModelLib (); | ||||
virtual void flush1(); | // Load a 3D model (any format) | |||
// data->modelLoaded() will be called after the model is loaded | ||||
virtual ssgEntity *load_model( const string &fg_root, | static osg::Node* loadModel(const std::string &path, | |||
const string &path, | SGPropertyNode *prop_root = NULL, | |||
SGPropertyNode *prop_root, | SGModelData *data=0, bool load2DPanels=fals | |||
double sim_time_sec, | e); | |||
bool cache_object, | ||||
SGModelData *data = 0 ); | // Load a 3D model (any format) through the DatabasePager. | |||
// This function initially just returns a proxy node that refers to | ||||
// the model file. Once the viewer steps onto that node the | ||||
// model will be loaded. | ||||
static osg::Node* loadDeferredModel(const std::string &path, | ||||
SGPropertyNode *prop_root = NULL, | ||||
SGModelData *data=0); | ||||
// Load a 3D model (any format) through the DatabasePager. | ||||
// This function initially just returns a PagedLOD node that refers to | ||||
// the model file. Once the viewer steps onto that node the | ||||
// model will be loaded. When the viewer does no longer reference this | ||||
// node for a long time the node is unloaded again. | ||||
static osg::Node* loadPagedModel(const std::string &path, | ||||
SGPropertyNode *prop_root = NULL, | ||||
SGModelData *data=0); | ||||
static std::string findDataFile(const std::string& file, | ||||
const osgDB::Options* opts = NULL, | ||||
SGPath currentDir = SGPath()); | ||||
protected: | protected: | |||
SGModelLib(); | ||||
~SGModelLib (); | ||||
private: | ||||
static SGPropertyNode_ptr static_propRoot; | ||||
static panel_func static_panelFunc; | ||||
}; | ||||
map<string,ssgSharedPtr<ssgEntity> > _table; | /** | |||
* Abstract class for adding data to the scene graph. modelLoaded() is | ||||
* called after the model was loaded, and the destructor when the branch | ||||
* is removed from the scene graph. | ||||
*/ | ||||
class SGModelData : public osg::Referenced { | ||||
public: | ||||
virtual ~SGModelData() {} | ||||
virtual void modelLoaded(const std::string& path, SGPropertyNode *prop, | ||||
osg::Node* branch) = 0; | ||||
virtual SGModelData* clone() const = 0; | ||||
}; | }; | |||
} | ||||
#endif // _SG_MODEL_LIB_HXX | #endif // _SG_MODEL_LIB_HXX | |||
End of changes. 12 change blocks. | ||||
20 lines changed or deleted | 75 lines changed or added | |||
moon.hxx | moon.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: moon.hxx,v 1.3 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_MOON_HXX_ | #ifndef _SG_MOON_HXX_ | |||
#define _SG_MOON_HXX_ | #define _SG_MOON_HXX_ | |||
#include <plib/ssg.h> | #include <osg/ref_ptr> | |||
#include <osg/MatrixTransform> | ||||
#include <osg/Material> | ||||
#include <simgear/misc/sg_path.hxx> | #include <simgear/math/SGMath.hxx> | |||
#include <simgear/structure/SGReferenced.hxx> | ||||
class SGMoon { | ||||
ssgTransform *moon_transform; | #include <simgear/misc/sg_path.hxx> | |||
ssgSimpleState *orb_state; | ||||
ssgSimpleState *halo_state; | ||||
ssgColourArray *cl; | class SGMoon : public SGReferenced { | |||
ssgVertexArray *halo_vl; | osg::ref_ptr<osg::MatrixTransform> moon_transform; | |||
ssgTexCoordArray *halo_tl; | osg::ref_ptr<osg::Material> orb_material; | |||
double prev_moon_angle; | double prev_moon_angle; | |||
public: | public: | |||
// Constructor | // Constructor | |||
SGMoon( void ); | SGMoon( void ); | |||
// Destructor | // Destructor | |||
~SGMoon( void ); | ~SGMoon( void ); | |||
// build the moon object | // build the moon object | |||
ssgBranch *build( SGPath path, double moon_size ); | osg::Node *build( SGPath path, double moon_size ); | |||
// repaint the moon colors based on current value of moon_anglein | // repaint the moon colors based on current value of moon_anglein | |||
// degrees relative to verticle | // degrees relative to verticle | |||
// 0 degrees = high noon | // 0 degrees = high noon | |||
// 90 degrees = moon rise/set | // 90 degrees = moon rise/set | |||
// 180 degrees = darkest midnight | // 180 degrees = darkest midnight | |||
bool repaint( double moon_angle ); | bool repaint( double moon_angle ); | |||
// reposition the moon at the specified right ascension and | // reposition the moon at the specified right ascension and | |||
// declination, offset by our current position (p) so that it | // declination, offset by our current position (p) so that it | |||
// appears fixed at a great distance from the viewer. Also add in | // appears fixed at a great distance from the viewer. Also add in | |||
// an optional rotation (i.e. for the current time of day.) | // an optional rotation (i.e. for the current time of day.) | |||
bool reposition( sgVec3 p, double angle, | bool reposition( double rightAscension, double declination, | |||
double rightAscension, double declination, | ||||
double moon_dist ); | double moon_dist ); | |||
}; | }; | |||
#endif // _SG_MOON_HXX_ | #endif // _SG_MOON_HXX_ | |||
End of changes. 8 change blocks. | ||||
14 lines changed or deleted | 12 lines changed or added | |||
moonpos.hxx | moonpos.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: moonpos.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _MOONPOS_HXX_ | #ifndef _MOONPOS_HXX_ | |||
#define _MOONPOS_HXX_ | #define _MOONPOS_HXX_ | |||
#include <simgear/constants.h> | #include <simgear/constants.h> | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class MoonPos : public CelestialBody | class MoonPos : public CelestialBody | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
naref.h | naref.h | |||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
#define _NAREF_H | #define _NAREF_H | |||
/* Rather than play elaborate and complicated games with | /* Rather than play elaborate and complicated games with | |||
* platform-dependent endianness headers, just detect the platforms we | * platform-dependent endianness headers, just detect the platforms we | |||
* support. This list is simpler and smaller, yet still quite | * support. This list is simpler and smaller, yet still quite | |||
* complete. */ | * complete. */ | |||
#if (defined(__x86_64) && defined(__linux__)) || defined(__sparcv9) || \ | #if (defined(__x86_64) && defined(__linux__)) || defined(__sparcv9) || \ | |||
defined(__powerpc64__) | defined(__powerpc64__) | |||
/* Win64 and Irix should work with this too, but have not been | /* Win64 and Irix should work with this too, but have not been | |||
* tested */ | * tested */ | |||
# define NASAL_NAN64 | # define NASAL_NAN64 | |||
#elif defined(_M_IX86) || defined(i386) || defined(__x86_64) || \ | #elif defined(_M_IX86) || defined(i386) || defined(__x86_64) || \ | |||
defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) | defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) || \ | |||
defined(_M_X64) || defined(__alpha__) || \ | ||||
(defined(__sh__) && defined(__LITTLE_ENDIAN__)) | ||||
# define NASAL_LE | # define NASAL_LE | |||
#elif defined(__sparc) || defined(__ppc__) ||defined(__PPC) || \ | #elif defined(__sparc) || defined(__ppc__) || defined(__PPC) || \ | |||
defined(__mips) || defined(__ARMEB__) | defined (__powerpc__) || defined (__powerpc64__) || defined (__alpha_ | |||
_) || \ | ||||
defined(__mips) || defined(__ARMEB__) || \ | ||||
defined(__hppa__) || defined(__s390__) || defined(__s390x__) || \ | ||||
(defined(__sh__) && !defined(__LITTLE_ENDIAN__)) | ||||
# define NASAL_BE | # define NASAL_BE | |||
#else | #else | |||
# error Unrecognized CPU architecture | # error Unrecognized CPU architecture | |||
#endif | #endif | |||
typedef union { | typedef union { | |||
struct naObj* obj; | struct naObj* obj; | |||
struct naStr* str; | struct naStr* str; | |||
struct naVec* vec; | struct naVec* vec; | |||
struct naHash* hash; | struct naHash* hash; | |||
struct naCode* code; | struct naCode* code; | |||
struct naFunc* func; | struct naFunc* func; | |||
struct naCCode* ccode; | struct naCCode* ccode; | |||
struct naGhost* ghost; | struct naGhost* ghost; | |||
} naPtr; | } naPtr; | |||
#if defined(NASAL_NAN64) | /* On supported 64 bit platforms (those where all memory returned from | |||
/* On suppoted 64 bit platforms (those where all memory returned from | ||||
* naAlloc() is guaranteed to lie between 0 and 2^48-1) we union the | * naAlloc() is guaranteed to lie between 0 and 2^48-1) we union the | |||
* double with the pointer, and use fancy tricks (see data.h) to make | * double with the pointer, and use fancy tricks (see data.h) to make | |||
* sure all pointers are stored as NaNs. */ | * sure all pointers are stored as NaNs. 32 bit layouts (and 64 bit | |||
typedef union { double num; void* ptr; } naRef; | * platforms where we haven't tested the trick above) need | |||
* endianness-dependent ordering to make sure that the reftag lies in | ||||
* the top bits of the double */ | ||||
#elif defined(NASAL_LE) || defined(NASAL_BE) | #if defined(NASAL_LE) | |||
/* 32 bit layouts (and 64 bit platforms where we haven't tested the | ||||
trick above) need endianness-dependent ordering to make sure that | ||||
the reftag lies in the top bits of the double */ | ||||
#ifdef NASAL_LE | ||||
typedef struct { naPtr ptr; int reftag; } naRefPart; | typedef struct { naPtr ptr; int reftag; } naRefPart; | |||
#else /* NASAL_BE */ | #elif defined(NASAL_BE) | |||
typedef struct { int reftag; naPtr ptr; } naRefPart; | typedef struct { int reftag; naPtr ptr; } naRefPart; | |||
#endif | #endif | |||
typedef union { | #if defined(NASAL_NAN64) | |||
double num; | typedef union { double num; void* ptr; } naRef; | |||
naRefPart ref; | #else | |||
} naRef; | typedef union { double num; naRefPart ref; } naRef; | |||
#endif | #endif | |||
#endif // _NAREF_H | #endif // _NAREF_H | |||
End of changes. 7 change blocks. | ||||
22 lines changed or deleted | 22 lines changed or added | |||
nasal.h | nasal.h | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
#define GCC_PURE __attribute__((__pure__)) | #define GCC_PURE __attribute__((__pure__)) | |||
#else | #else | |||
#define GCC_PURE | #define GCC_PURE | |||
#endif | #endif | |||
typedef struct Context* naContext; | typedef struct Context* naContext; | |||
// The function signature for an extension function: | // The function signature for an extension function: | |||
typedef naRef (*naCFunction)(naContext ctx, naRef me, int argc, naRef* args ); | typedef naRef (*naCFunction)(naContext ctx, naRef me, int argc, naRef* args ); | |||
// The function signature for an extension function with userdata passed ba | ||||
ck: | ||||
typedef naRef (*naCFunctionU) | ||||
(naContext ctx, naRef me, int argc, naRef* args, void* user_d | ||||
ata); | ||||
// All Nasal code runs under the watch of a naContext: | // All Nasal code runs under the watch of a naContext: | |||
naContext naNewContext(); | naContext naNewContext(); | |||
void naFreeContext(naContext c); | void naFreeContext(naContext c); | |||
// Use this when making a call to a new context "underneath" a | // Use this when making a call to a new context "underneath" a | |||
// preexisting context on the same stack. It allows stack walking to | // preexisting context on the same stack. It allows stack walking to | |||
// see through the boundary, and eliminates the need to release the | // see through the boundary, and eliminates the need to release the | |||
// mod lock (i.e. must be called with the mod lock held!) | // mod lock (i.e. must be called with the mod lock held!) | |||
naContext naSubContext(naContext super); | naContext naSubContext(naContext super); | |||
skipping to change at line 102 | skipping to change at line 106 | |||
// printf(). | // printf(). | |||
void naRuntimeError(naContext c, const char* fmt, ...); | void naRuntimeError(naContext c, const char* fmt, ...); | |||
// "Re-throws" a runtime error caught from the subcontext. Acts as a | // "Re-throws" a runtime error caught from the subcontext. Acts as a | |||
// naRuntimeError() called on the parent context. Does not return. | // naRuntimeError() called on the parent context. Does not return. | |||
void naRethrowError(naContext subc); | void naRethrowError(naContext subc); | |||
// Retrieve the specified member from the object, respecting the | // Retrieve the specified member from the object, respecting the | |||
// "parents" array as for "object.field". Returns zero for missing | // "parents" array as for "object.field". Returns zero for missing | |||
// fields. | // fields. | |||
int naMember_get(naRef obj, naRef field, naRef* out); | int naMember_get(naContext c, naRef obj, naRef field, naRef* out); | |||
int naMember_cget(naRef obj, const char* field, naRef* out); | int naMember_cget(naContext c, naRef obj, const char* field, naRef* out); | |||
// Returns a hash containing functions from the Nasal standard library | // Returns a hash containing functions from the Nasal standard library | |||
// Useful for passing as a namespace to an initial function call | // Useful for passing as a namespace to an initial function call | |||
naRef naInit_std(naContext c); | naRef naInit_std(naContext c); | |||
// Ditto, for other core libraries | // Ditto, for other core libraries | |||
naRef naInit_math(naContext c); | naRef naInit_math(naContext c); | |||
naRef naInit_bits(naContext c); | naRef naInit_bits(naContext c); | |||
naRef naInit_io(naContext c); | naRef naInit_io(naContext c); | |||
naRef naInit_regex(naContext c); | naRef naInit_regex(naContext c); | |||
naRef naInit_unix(naContext c); | naRef naInit_unix(naContext c); | |||
naRef naInit_thread(naContext c); | naRef naInit_thread(naContext c); | |||
naRef naInit_utf8(naContext c); | naRef naInit_utf8(naContext c); | |||
naRef naInit_sqlite(naContext c); | naRef naInit_sqlite(naContext c); | |||
naRef naInit_readline(naContext c); | naRef naInit_readline(naContext c); | |||
naRef naInit_gtk(naContext ctx); | naRef naInit_gtk(naContext ctx); | |||
naRef naInit_cairo(naContext ctx); | naRef naInit_cairo(naContext ctx); | |||
// Returns a hash which can be used to add methods callable on strings | ||||
naRef naInit_string(naContext c); | ||||
// Context stack inspection, frame zero is the "top" | // Context stack inspection, frame zero is the "top" | |||
int naStackDepth(naContext ctx); | int naStackDepth(naContext ctx); | |||
int naGetLine(naContext ctx, int frame); | int naGetLine(naContext ctx, int frame); | |||
naRef naGetSourceFile(naContext ctx, int frame); | naRef naGetSourceFile(naContext ctx, int frame); | |||
char* naGetError(naContext ctx); | char* naGetError(naContext ctx); | |||
// Type predicates | // Type predicates | |||
int naIsNil(naRef r) GCC_PURE; | int naIsNil(naRef r) GCC_PURE; | |||
int naIsNum(naRef r) GCC_PURE; | int naIsNum(naRef r) GCC_PURE; | |||
int naIsString(naRef r) GCC_PURE; | int naIsString(naRef r) GCC_PURE; | |||
skipping to change at line 146 | skipping to change at line 153 | |||
int naIsFunc(naRef r) GCC_PURE; | int naIsFunc(naRef r) GCC_PURE; | |||
int naIsCCode(naRef r) GCC_PURE; | int naIsCCode(naRef r) GCC_PURE; | |||
// Allocators/generators: | // Allocators/generators: | |||
naRef naNil() GCC_PURE; | naRef naNil() GCC_PURE; | |||
naRef naNum(double num) GCC_PURE; | naRef naNum(double num) GCC_PURE; | |||
naRef naNewString(naContext c); | naRef naNewString(naContext c); | |||
naRef naNewVector(naContext c); | naRef naNewVector(naContext c); | |||
naRef naNewHash(naContext c); | naRef naNewHash(naContext c); | |||
naRef naNewFunc(naContext c, naRef code); | naRef naNewFunc(naContext c, naRef code); | |||
/** | ||||
* Register extension function | ||||
* | ||||
* @param fptr Pointer to C-function | ||||
* @param user_data Optional user data passed back on calling the function | ||||
* @param destroy Optional callback called if function gets freed by garb | ||||
age | ||||
* collector to free user data if required. | ||||
*/ | ||||
naRef naNewCCode(naContext c, naCFunction fptr); | naRef naNewCCode(naContext c, naCFunction fptr); | |||
naRef naNewCCodeU(naContext c, naCFunctionU fptr, void* user_data); | ||||
naRef naNewCCodeUD(naContext c, naCFunctionU fptr, void* user_data, | ||||
void (*destroy)(void*)); | ||||
// Some useful conversion/comparison routines | // Some useful conversion/comparison routines | |||
int naEqual(naRef a, naRef b) GCC_PURE; | int naEqual(naRef a, naRef b) GCC_PURE; | |||
int naStrEqual(naRef a, naRef b) GCC_PURE; | int naStrEqual(naRef a, naRef b) GCC_PURE; | |||
int naTrue(naRef b) GCC_PURE; | int naTrue(naRef b) GCC_PURE; | |||
naRef naNumValue(naRef n) GCC_PURE; | naRef naNumValue(naRef n) GCC_PURE; | |||
naRef naStringValue(naContext c, naRef n); | naRef naStringValue(naContext c, naRef n); | |||
// String utilities: | // String utilities: | |||
int naStr_len(naRef s); | int naStr_len(naRef s) GCC_PURE; | |||
char* naStr_data(naRef s); | char* naStr_data(naRef s) GCC_PURE; | |||
naRef naStr_fromdata(naRef dst, char* data, int len); | naRef naStr_fromdata(naRef dst, const char* data, int len); | |||
naRef naStr_concat(naRef dest, naRef s1, naRef s2); | naRef naStr_concat(naRef dest, naRef s1, naRef s2); | |||
naRef naStr_substr(naRef dest, naRef str, int start, int len); | naRef naStr_substr(naRef dest, naRef str, int start, int len); | |||
naRef naInternSymbol(naRef sym); | naRef naInternSymbol(naRef sym); | |||
naRef getStringMethods(naContext c); | ||||
// Vector utilities: | // Vector utilities: | |||
int naVec_size(naRef v); | int naVec_size(naRef v); | |||
naRef naVec_get(naRef v, int i); | naRef naVec_get(naRef v, int i); | |||
void naVec_set(naRef vec, int i, naRef o); | void naVec_set(naRef vec, int i, naRef o); | |||
int naVec_append(naRef vec, naRef o); | int naVec_append(naRef vec, naRef o); | |||
void naVec_setsize(naContext c, naRef vec, int sz); | ||||
/** | ||||
* Remove and retrieve the first element of the vector. | ||||
* | ||||
* This operation reduces the size of the vector by one and moves all eleme | ||||
nts | ||||
* by one towards the begin of the vector. | ||||
* | ||||
* @return The element removed from the begin | ||||
*/ | ||||
naRef naVec_removefirst(naRef vec); | ||||
/** | ||||
* Remove and retrieve the last element of the vector. | ||||
* | ||||
* This operation reduces the size of the vector by one. | ||||
* | ||||
* @return The element removed from the end | ||||
*/ | ||||
naRef naVec_removelast(naRef vec); | naRef naVec_removelast(naRef vec); | |||
void naVec_setsize(naRef vec, int sz); | ||||
// Hash utilities: | // Hash utilities: | |||
int naHash_size(naRef h); | int naHash_size(naRef h); | |||
int naHash_get(naRef hash, naRef key, naRef* out); | int naHash_get(naRef hash, naRef key, naRef* out); | |||
naRef naHash_cget(naRef hash, char* key); | naRef naHash_cget(naRef hash, char* key); | |||
void naHash_set(naRef hash, naRef key, naRef val); | void naHash_set(naRef hash, naRef key, naRef val); | |||
void naHash_cset(naRef hash, char* key, naRef val); | void naHash_cset(naRef hash, char* key, naRef val); | |||
void naHash_delete(naRef hash, naRef key); | void naHash_delete(naRef hash, naRef key); | |||
/** | ||||
* Store the keys in ::hash into the vector at ::dst | ||||
* | ||||
* @see ::naNewVector | ||||
*/ | ||||
void naHash_keys(naRef dst, naRef hash); | void naHash_keys(naRef dst, naRef hash); | |||
// Ghost utilities: | // Ghost utilities: | |||
typedef struct naGhostType { | typedef struct naGhostType { | |||
void (*destroy)(void* ghost); | void(*destroy)(void*); | |||
const char* name; | const char* name; | |||
const char*(*get_member)(naContext c, void*, naRef key, naRef* out); | ||||
void(*set_member)(naContext c, void*, naRef key, naRef val); | ||||
} naGhostType; | } naGhostType; | |||
/** | ||||
* Create a ghost for an object without any attributes. If ::t contains poi | ||||
nters | ||||
* to get_member or set_member function they will be ignored. | ||||
*/ | ||||
naRef naNewGhost(naContext c, naGhostType* t, void* ghost); | naRef naNewGhost(naContext c, naGhostType* t, void* ghost); | |||
/** | ||||
* Create a ghost for an object. This version uses the get_member and set_m | ||||
ember | ||||
* function pointers in ::t upon trying to get or set a member respectively | ||||
from | ||||
* Nasal. | ||||
*/ | ||||
naRef naNewGhost2(naContext c, naGhostType* t, void* ghost); | ||||
naGhostType* naGhost_type(naRef ghost); | naGhostType* naGhost_type(naRef ghost); | |||
void* naGhost_ptr(naRef ghost); | void* naGhost_ptr(naRef ghost); | |||
int naIsGhost(naRef r); | int naIsGhost(naRef r); | |||
// Acquires a "modification lock" on a context, allowing the C code to | // Acquires a "modification lock" on a context, allowing the C code to | |||
// modify Nasal data without fear that such data may be "lost" by the | // modify Nasal data without fear that such data may be "lost" by the | |||
// garbage collector (nasal data the C stack is not examined in GC!). | // garbage collector (nasal data on the C stack is not examined in | |||
// This disallows garbage collection until the current thread can be | // GC!). This disallows garbage collection until the current thread | |||
// blocked. The lock should be acquired whenever nasal objects are | // can be blocked. The lock should be acquired whenever nasal objects | |||
// being modified. It need not be acquired when only read access is | // are being modified. It need not be acquired when only read access | |||
// needed, PRESUMING that the Nasal data being read is findable by the | // is needed, PRESUMING that the Nasal data being read is findable by | |||
// collector (via naSave, for example) and that another Nasal thread | // the collector (via naSave, for example) and that another Nasal | |||
// cannot or will not delete the reference to the data. It MUST NOT | // thread cannot or will not delete the reference to the data. It | |||
// be acquired by naCFunction's, as those are called with the lock | // MUST NOT be acquired by naCFunction's, as those are called with the | |||
// already held; acquiring two locks for the same thread will cause a | // lock already held; acquiring two locks for the same thread will | |||
// deadlock when the GC is invoked. It should be UNLOCKED by | // cause a deadlock when the GC is invoked. It should be UNLOCKED by | |||
// naCFunction's when they are about to do any long term non-nasal | // naCFunction's when they are about to do any long term non-nasal | |||
// processing and/or blocking I/O. Note that naModLock() may need to | // processing and/or blocking I/O. Note that naModLock() may need to | |||
// block to allow garbage collection to occur, and that garbage | // block to allow garbage collection to occur, and that garbage | |||
// collection by other threads may be blocked until naModUnlock() is | // collection by other threads may be blocked until naModUnlock() is | |||
// called. It must also be UNLOCKED by threads that hold a lock | // called. It must also be UNLOCKED by threads that hold a lock | |||
// already before making a naCall() or naContinue() call -- these | // already before making a naCall() or naContinue() call -- these | |||
// functions will attempt to acquire the lock again. | // functions will attempt to acquire the lock again. | |||
void naModLock(); | void naModLock(); | |||
void naModUnlock(); | void naModUnlock(); | |||
End of changes. 15 change blocks. | ||||
17 lines changed or deleted | 80 lines changed or added | |||
neptune.hxx | neptune.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: neptune.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _NEPTUNE_HXX_ | #ifndef _NEPTUNE_HXX_ | |||
#define _NEPTUNE_HXX_ | #define _NEPTUNE_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Neptune : public CelestialBody | class Neptune : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
newbucket.hxx | newbucket.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: newbucket.hxx,v 1.9 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
/** \file newbucket.hxx | /** \file newbucket.hxx | |||
* A class and associated utiltity functions to manage world scenery tiling . | * A class and associated utiltity functions to manage world scenery tiling . | |||
* | ||||
* Tile borders are aligned along circles of latitude and longitude. | ||||
* All tiles are 1/8 degree of latitude high and their width in degrees | ||||
* longitude depends on their latitude, adjusted in such a way that | ||||
* all tiles cover about the same amount of area of the earth surface. | ||||
*/ | */ | |||
#ifndef _NEWBUCKET_HXX | #ifndef _NEWBUCKET_HXX | |||
#define _NEWBUCKET_HXX | #define _NEWBUCKET_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/constants.h> | #include <simgear/constants.h> | |||
#include <simgear/math/SGMath.hxx> | ||||
#ifdef SG_HAVE_STD_INCLUDES | #include <cmath> | |||
# include <cmath> | #include <cstdio> // sprintf() | |||
# include <cstdio> // sprintf() | #include <ostream> | |||
#else | #include <string> | |||
# include <math.h> | #include <vector> | |||
# include <stdio.h> // sprintf() | ||||
#endif | ||||
#include STL_IOSTREAM | ||||
// I don't understand ... <math.h> or <cmath> should be included | ||||
// already depending on how you defined SG_HAVE_STD_INCLUDES, but I | ||||
// can go ahead and add this -- CLO | ||||
#ifdef __MWERKS__ | ||||
SG_USING_STD(sprintf); | ||||
SG_USING_STD(fabs); | ||||
#endif | ||||
#include STL_STRING | ||||
SG_USING_STD(string); | ||||
SG_USING_STD(ostream); | ||||
/** | /** | |||
* standard size of a bucket in degrees (1/8 of a degree) | * standard size of a bucket in degrees (1/8 of a degree) | |||
*/ | */ | |||
#define SG_BUCKET_SPAN 0.125 | #define SG_BUCKET_SPAN 0.125 | |||
/** | /** | |||
* half of a standard SG_BUCKET_SPAN | * half of a standard SG_BUCKET_SPAN | |||
*/ | */ | |||
#define SG_HALF_BUCKET_SPAN ( 0.5 * SG_BUCKET_SPAN ) | #define SG_HALF_BUCKET_SPAN ( 0.5 * SG_BUCKET_SPAN ) | |||
// return the horizontal tile span factor based on latitude | // return the horizontal tile span factor based on latitude | |||
static double sg_bucket_span( double l ) { | static double sg_bucket_span( double l ) { | |||
if ( l >= 89.0 ) { | if ( l >= 89.0 ) { | |||
return 360.0; | return 12.0; | |||
} else if ( l >= 88.0 ) { | ||||
return 8.0; | ||||
} else if ( l >= 86.0 ) { | } else if ( l >= 86.0 ) { | |||
return 4.0; | return 4.0; | |||
} else if ( l >= 83.0 ) { | } else if ( l >= 83.0 ) { | |||
return 2.0; | return 2.0; | |||
} else if ( l >= 76.0 ) { | } else if ( l >= 76.0 ) { | |||
return 1.0; | return 1.0; | |||
} else if ( l >= 62.0 ) { | } else if ( l >= 62.0 ) { | |||
return 0.5; | return 0.5; | |||
} else if ( l >= 22.0 ) { | } else if ( l >= 22.0 ) { | |||
return 0.25; | return 0.25; | |||
} else if ( l >= -22.0 ) { | } else if ( l >= -22.0 ) { | |||
return 0.125; | return 0.125; | |||
} else if ( l >= -62.0 ) { | } else if ( l >= -62.0 ) { | |||
return 0.25; | return 0.25; | |||
} else if ( l >= -76.0 ) { | } else if ( l >= -76.0 ) { | |||
return 0.5; | return 0.5; | |||
} else if ( l >= -83.0 ) { | } else if ( l >= -83.0 ) { | |||
return 1.0; | return 1.0; | |||
} else if ( l >= -86.0 ) { | } else if ( l >= -86.0 ) { | |||
return 2.0; | return 2.0; | |||
} else if ( l >= -88.0 ) { | ||||
return 4.0; | ||||
} else if ( l >= -89.0 ) { | } else if ( l >= -89.0 ) { | |||
return 8.0; | return 4.0; | |||
} else { | } else { | |||
return 360.0; | return 12.0; | |||
} | } | |||
} | } | |||
/** | /** | |||
* A class to manage world scenery tiling. | * A class to manage world scenery tiling. | |||
* This class encapsulates the world tiling scheme. It provides ways | * This class encapsulates the world tiling scheme. It provides ways | |||
* to calculate a unique tile index from a lat/lon, and it can provide | * to calculate a unique tile index from a lat/lon, and it can provide | |||
* information such as the dimensions of a given tile. | * information such as the dimensions of a given tile. | |||
*/ | */ | |||
class SGBucket { | class SGBucket { | |||
private: | private: | |||
double cx, cy; // centerpoint (lon, lat) in degrees of bucket | ||||
short lon; // longitude index (-180 to 179) | short lon; // longitude index (-180 to 179) | |||
short lat; // latitude index (-90 to 89) | short lat; // latitude index (-90 to 89) | |||
char x; // x subdivision (0 to 7) | char x; // x subdivision (0 to 7) | |||
char y; // y subdivision (0 to 7) | char y; // y subdivision (0 to 7) | |||
public: | public: | |||
/** | /** | |||
* Default constructor. | * Default constructor. | |||
*/ | */ | |||
SGBucket(); | SGBucket(); | |||
/** | /** | |||
* Construct a bucket given a specific location. | * Construct a bucket given a specific location. | |||
* @param dlon longitude specified in degrees | * @param dlon longitude specified in degrees | |||
* @param dlat latitude specified in degrees | * @param dlat latitude specified in degrees | |||
*/ | */ | |||
SGBucket(const double dlon, const double dlat); | SGBucket(const double dlon, const double dlat); | |||
/** | ||||
* Construct a bucket given a specific location. | ||||
* @param dlon longitude specified in degrees | ||||
* @param dlat latitude specified in degrees | ||||
*/ | ||||
SGBucket(const SGGeod& geod); | ||||
/** Construct a bucket. | /** Construct a bucket. | |||
* @param is_good if false, create an invalid bucket. This is | * @param is_good if false, create an invalid bucket. This is | |||
* useful * if you are comparing cur_bucket to last_bucket and | * useful * if you are comparing cur_bucket to last_bucket and | |||
* you want to * make sure last_bucket starts out as something | * you want to * make sure last_bucket starts out as something | |||
* impossible. | * impossible. | |||
*/ | */ | |||
SGBucket(const bool is_good); | SGBucket(const bool is_good); | |||
/** Construct a bucket given a unique bucket index number. | /** Construct a bucket given a unique bucket index number. | |||
* @param bindex unique bucket index | * @param bindex unique bucket index | |||
*/ | */ | |||
SGBucket(const long int bindex); | SGBucket(const long int bindex); | |||
/** | /** | |||
* Default destructor. | ||||
*/ | ||||
~SGBucket(); | ||||
/** | ||||
* Reset a bucket to represent a new lat and lon | * Reset a bucket to represent a new lat and lon | |||
* @param dlon longitude specified in degrees | * @param dlon longitude specified in degrees | |||
* @param dlat latitude specified in degrees | * @param dlat latitude specified in degrees | |||
*/ | */ | |||
void set_bucket( double dlon, double dlat ); | void set_bucket( double dlon, double dlat ); | |||
/** | /** | |||
* Reset a bucket to represent a new lat and lon | * Reset a bucket to represent a new lat and lon | |||
* @param lonlat an array of double[2] holding lon and lat | * @param lonlat an array of double[2] holding lon and lat | |||
* (specified) in degrees | * (specified) in degrees | |||
*/ | */ | |||
void set_bucket( double *lonlat ); | void set_bucket( double *lonlat ); | |||
/** | /** | |||
* Reset a bucket to represent a new lat and lon | ||||
* @param dlon longitude specified in degrees | ||||
* @param dlat latitude specified in degrees | ||||
*/ | ||||
void set_bucket(const SGGeod& geod); | ||||
/** | ||||
* Create an impossible bucket. | * Create an impossible bucket. | |||
* This is useful if you are comparing cur_bucket to last_bucket | * This is useful if you are comparing cur_bucket to last_bucket | |||
* and you want to make sure last_bucket starts out as something | * and you want to make sure last_bucket starts out as something | |||
* impossible. | * impossible. | |||
*/ | */ | |||
inline void make_bad() { | inline void make_bad() { | |||
set_bucket(0.0, 0.0); | set_bucket(0.0, 0.0); | |||
lon = -1000; | lon = -1000; | |||
} | } | |||
skipping to change at line 200 | skipping to change at line 193 | |||
*/ | */ | |||
inline long int gen_index() const { | inline long int gen_index() const { | |||
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x; | return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x; | |||
} | } | |||
/** | /** | |||
* Generate the unique scenery tile index for this bucket in ascii | * Generate the unique scenery tile index for this bucket in ascii | |||
* string form. | * string form. | |||
* @return tile index in string form | * @return tile index in string form | |||
*/ | */ | |||
inline string gen_index_str() const { | inline std::string gen_index_str() const { | |||
char tmp[20]; | char tmp[20]; | |||
sprintf(tmp, "%ld", | std::sprintf(tmp, "%ld", | |||
(((long)lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + | (((long)lon + 180) << 14) + ((lat + 90) << 6) | |||
x); | + (y << 3) + x); | |||
return (string)tmp; | return (std::string)tmp; | |||
} | } | |||
/** | /** | |||
* Build the base path name for this bucket. | * Build the base path name for this bucket. | |||
* @return base path in string form | * @return base path in string form | |||
*/ | */ | |||
string gen_base_path() const; | std::string gen_base_path() const; | |||
/** | /** | |||
* @return the center lon of a tile. | * @return the center lon of a tile. | |||
*/ | */ | |||
inline double get_center_lon() const { | inline double get_center_lon() const { | |||
double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN ); | double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN ); | |||
if ( span >= 1.0 ) { | if ( span >= 1.0 ) { | |||
return lon + span / 2.0; | return lon + get_width() / 2.0; | |||
} else { | } else { | |||
return lon + x * span + span / 2.0; | return lon + x * span + get_width() / 2.0; | |||
} | } | |||
} | } | |||
/** | /** | |||
* @return the center lat of a tile. | * @return the center lat of a tile. | |||
*/ | */ | |||
inline double get_center_lat() const { | inline double get_center_lat() const { | |||
return lat + y / 8.0 + SG_HALF_BUCKET_SPAN; | return lat + y / 8.0 + SG_HALF_BUCKET_SPAN; | |||
} | } | |||
skipping to change at line 253 | skipping to change at line 247 | |||
/** | /** | |||
* @return the width of the tile in meters. | * @return the width of the tile in meters. | |||
*/ | */ | |||
double get_width_m() const; | double get_width_m() const; | |||
/** | /** | |||
* @return the height of the tile in meters. | * @return the height of the tile in meters. | |||
*/ | */ | |||
double get_height_m() const; | double get_height_m() const; | |||
/** | ||||
* @return the center of the bucket in geodetic coordinates. | ||||
*/ | ||||
SGGeod get_center() const | ||||
{ return SGGeod::fromDeg(get_center_lon(), get_center_lat()); } | ||||
/** | ||||
* @return the center of the bucket in geodetic coordinates. | ||||
*/ | ||||
SGGeod get_corner(unsigned num) const | ||||
{ | ||||
double lonFac = ((num + 1) & 2) ? 0.5 : -0.5; | ||||
double latFac = ((num ) & 2) ? 0.5 : -0.5; | ||||
return SGGeod::fromDeg(get_center_lon() + lonFac*get_width(), | ||||
get_center_lat() + latFac*get_height()); | ||||
} | ||||
// Informational methods. | // Informational methods. | |||
/** | /** | |||
* @return the lon of the lower left corner of | * @return the lon of the lower left corner of | |||
* the 1x1 chunk containing this tile. | * the 1x1 chunk containing this tile. | |||
*/ | */ | |||
inline int get_chunk_lon() const { return lon; } | inline int get_chunk_lon() const { return lon; } | |||
/** | /** | |||
* @return the lat of the lower left corner of | * @return the lat of the lower left corner of | |||
skipping to change at line 279 | skipping to change at line 290 | |||
*/ | */ | |||
inline int get_x() const { return x; } | inline int get_x() const { return x; } | |||
/** | /** | |||
* @return the y coord within the 1x1 degree chunk this tile. | * @return the y coord within the 1x1 degree chunk this tile. | |||
*/ | */ | |||
inline int get_y() const { return y; } | inline int get_y() const { return y; } | |||
// friends | // friends | |||
friend ostream& operator<< ( ostream&, const SGBucket& ); | friend std::ostream& operator<< ( std::ostream&, const SGBucket& ); | |||
friend bool operator== ( const SGBucket&, const SGBucket& ); | friend bool operator== ( const SGBucket&, const SGBucket& ); | |||
}; | }; | |||
inline bool operator!= (const SGBucket& lhs, const SGBucket& rhs) | ||||
{ | ||||
return !(lhs == rhs); | ||||
} | ||||
/** | /** | |||
* \relates SGBucket | * \relates SGBucket | |||
* Return the bucket which is offset from the specified dlon, dlat by | * Return the bucket which is offset from the specified dlon, dlat by | |||
* the specified tile units in the X & Y direction. | * the specified tile units in the X & Y direction. | |||
* @param dlon starting lon in degrees | * @param dlon starting lon in degrees | |||
* @param dlat starting lat in degrees | * @param dlat starting lat in degrees | |||
* @param x number of bucket units to offset in x (lon) direction | * @param x number of bucket units to offset in x (lon) direction | |||
* @param y number of bucket units to offset in y (lat) direction | * @param y number of bucket units to offset in y (lat) direction | |||
* @return offset bucket | * @return offset bucket | |||
*/ | */ | |||
skipping to change at line 306 | skipping to change at line 322 | |||
* \relates SGBucket | * \relates SGBucket | |||
* Calculate the offset between two buckets (in quantity of buckets). | * Calculate the offset between two buckets (in quantity of buckets). | |||
* @param b1 bucket 1 | * @param b1 bucket 1 | |||
* @param b2 bucket 2 | * @param b2 bucket 2 | |||
* @param dx offset distance (lon) in tile units | * @param dx offset distance (lon) in tile units | |||
* @param dy offset distance (lat) in tile units | * @param dy offset distance (lat) in tile units | |||
*/ | */ | |||
void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ); | void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ); | |||
/** | /** | |||
* \relates SGBucket | ||||
* retrieve a list of buckets in the given bounding box | ||||
* @param min min lon,lat of bounding box in degrees | ||||
* @param max max lon,lat of bounding box in degrees | ||||
* @param list standard vector of buckets within the bounding box | ||||
*/ | ||||
void sgGetBuckets( const SGGeod& min, const SGGeod& max, std::vector<SGBuck | ||||
et>& list ); | ||||
/** | ||||
* Write the bucket lon, lat, x, and y to the output stream. | * Write the bucket lon, lat, x, and y to the output stream. | |||
* @param out output stream | * @param out output stream | |||
* @param b bucket | * @param b bucket | |||
*/ | */ | |||
inline ostream& | inline std::ostream& | |||
operator<< ( ostream& out, const SGBucket& b ) | operator<< ( std::ostream& out, const SGBucket& b ) | |||
{ | { | |||
return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y; | return out << b.lon << ":" << (int)b.x << ", " << b.lat << ":" << (int) b.y; | |||
} | } | |||
/** | /** | |||
* Compare two bucket structures for equality. | * Compare two bucket structures for equality. | |||
* @param b1 bucket 1 | * @param b1 bucket 1 | |||
* @param b2 bucket 2 | * @param b2 bucket 2 | |||
* @return comparison result | * @return comparison result | |||
*/ | */ | |||
inline bool | inline bool | |||
operator== ( const SGBucket& b1, const SGBucket& b2 ) | operator== ( const SGBucket& b1, const SGBucket& b2 ) | |||
End of changes. 23 change blocks. | ||||
48 lines changed or deleted | 73 lines changed or added | |||
newcloud.hxx | newcloud.hxx | |||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// | // | |||
#ifndef _NEWCLOUD_HXX | #ifndef _NEWCLOUD_HXX | |||
#define _NEWCLOUD_HXX | #define _NEWCLOUD_HXX | |||
#include <plib/sg.h> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <vector> | #include <vector> | |||
#include <osg/Fog> | ||||
#include "bbcache.hxx" | #include <simgear/math/sg_random.h> | |||
#include <simgear/scene/material/Effect.hxx> | ||||
#include <simgear/scene/material/EffectGeode.hxx> | ||||
SG_USING_STD(string); | using std::string; | |||
SG_USING_STD(vector); | using std::vector; | |||
/** | /** | |||
* 3D cloud class. | * 3D cloud class. | |||
*/ | */ | |||
class SGNewCloud { | class SGNewCloud { | |||
public: | public: | |||
enum CLFamilly_type { | SGNewCloud(const SGPath &texture_root, const SGPropertyNode *cld_de | |||
CLFamilly_cu = 0, | f, mt* s); | |||
CLFamilly_cb, | ||||
CLFamilly_st, | ||||
CLFamilly_ns, | ||||
CLFamilly_sc, | ||||
CLFamilly_as, | ||||
CLFamilly_ac, | ||||
CLFamilly_ci, | ||||
CLFamilly_cc, | ||||
CLFamilly_cs, | ||||
CLFamilly_nn | ||||
}; | ||||
SGNewCloud(CLFamilly_type classification=CLFamilly_nn); | ||||
SGNewCloud(string classification); | ||||
~SGNewCloud(); | ||||
enum CLbox_type { | ||||
CLbox_standard = 0, | ||||
CLbox_sc = 1, | ||||
CLbox_cumulus = 2, | ||||
CLbox_stratus = 3 | ||||
}; | ||||
enum CLTexture_type { | ||||
CLTexture_cumulus = 1, | ||||
CLTexture_stratus = 2, | ||||
CLTexture_max | ||||
}; | ||||
private: | ~SGNewCloud(); | |||
class spriteDef { | // Generate a Cloud | |||
public: | osg::ref_ptr<simgear::EffectGeode> genCloud (); | |||
sgVec3 pos; | ||||
float r; | ||||
CLbox_type sprite_type; | ||||
sgVec4 l0, l1, l2, l3; | ||||
sgVec3 normal, n0, n1, n2, n3; | ||||
int rank; | ||||
int box; | ||||
float dist; // distance used during sort | ||||
bool operator<(const spriteDef &b) const { | ||||
return (this->dist < b.dist); | ||||
} | ||||
}; | ||||
typedef struct { | ||||
sgVec3 pos; | ||||
float r; | ||||
// the type defines how the sprites can be positioned inside | ||||
the box, their size, etc | ||||
CLbox_type cont_type; | ||||
sgVec3 center; | ||||
} spriteContainer; | ||||
typedef vector<spriteDef> list_of_spriteDef; | ||||
typedef vector<spriteContainer> list_of_spriteContainer; | ||||
void init(void); | ||||
void computeSimpleLight(sgVec3 eyePos); | ||||
void addSprite(float x, float y, float z, float r, CLbox_type type, | ||||
int box); | ||||
// sort on distance to eye because of transparency | ||||
void sortSprite( sgVec3 eyePos ); | ||||
// render the cloud on screen or on the RTT texture to build the imp | ||||
ostor | ||||
void Render3Dcloud( bool drawBB, sgVec3 eyePos, sgVec3 deltaPos, flo | ||||
at dist_center ); | ||||
// compute rotations so that a quad is facing the camera | ||||
void CalcAngles(sgVec3 refpos, sgVec3 eyePos, float *angleY, float * | ||||
angleX); | ||||
// draw a cloud but this time we use the impostor texture | ||||
void RenderBB(sgVec3 deltaPos, bool first_time, float dist_center); | ||||
// determine if it is a good idea to use an impostor to render the c | ||||
loud | ||||
bool isBillboardable(float dist); | ||||
int cloudId, bbId; | ||||
sgVec3 rotX, rotY; | ||||
// int rank; | ||||
sgVec3 cloudpos, center; | ||||
float delta_base; | ||||
list_of_spriteDef list_spriteDef; | ||||
list_of_spriteContainer list_spriteContainer; | ||||
float radius; | ||||
CLFamilly_type familly; | ||||
// fading data | ||||
bool direction, fadeActive; | ||||
float duration, pauseLength, fadetimer; | ||||
float last_step; | ||||
public: | static float getDensity(void) | |||
// add a new box to the cloud | { | |||
void addContainer(float x, float y, float z, float r, CLbox_type typ | return sprite_density; | |||
e); | } | |||
// Set the sprite density | ||||
static void setDensity(double d) | ||||
{ | ||||
sprite_density = d; | ||||
} | ||||
private: | ||||
// generate all sprite with defined boxes | float min_width; | |||
void genSprites(void); | float max_width; | |||
float min_height; | ||||
float max_height; | ||||
float min_sprite_width; | ||||
float max_sprite_width; | ||||
float min_sprite_height; | ||||
float max_sprite_height; | ||||
// Minimum and maximum bottom, middle, top, sunny, shade lighting | ||||
// factors. For individual clouds we choose a bottom/middle/top | ||||
// shade from between each min/max value | ||||
float min_bottom_lighting_factor; | ||||
float max_bottom_lighting_factor; | ||||
float min_middle_lighting_factor; | ||||
float max_middle_lighting_factor; | ||||
float min_top_lighting_factor; | ||||
float max_top_lighting_factor; | ||||
float min_shade_lighting_factor; | ||||
float max_shade_lighting_factor; | ||||
// The density of the cloud is the shading applied | ||||
// to cloud sprites on the opposite side of the cloud | ||||
// from the sun. For an individual cloud instance a value | ||||
// between min_density and max_density is chosen. | ||||
float min_density; | ||||
float max_density; | ||||
// zscale indicates how sprites should be scaled vertically | ||||
// after billboarding. | ||||
float zscale; | ||||
bool height_map_texture; | ||||
int num_sprites; | ||||
int num_textures_x; | ||||
int num_textures_y; | ||||
string texture; | ||||
osg::Geometry* quad; | ||||
osg::ref_ptr<simgear::Effect> effect; | ||||
static float sprite_density; | ||||
// debug only, define a cumulus | // RNG seed for this cloud | |||
void new_cu(void); | mt* seed; | |||
// debug only | osg::Geometry* createOrthQuad(float w, float h, int varieties_x, in | |||
void drawContainers(void); | t varieties_y); | |||
// define the new position of the cloud (inside the cloud field, not | ||||
on sphere) | ||||
void SetPos(sgVec3 newPos); | ||||
// render the cloud, fakepos is a relative position inside the cloud | ||||
field | ||||
void Render(sgVec3 fakepos); | ||||
// | ||||
void startFade(bool direction, float duration, float pauseLength); | ||||
void setFade(float howMuch); | ||||
inline float getRadius() { return radius; } | ||||
inline sgVec3 *getCenter() { return ¢er; } | ||||
inline int getId() { return cloudId; } | ||||
inline CLFamilly_type getFamilly(void) { return familly; } | ||||
// load all textures used to draw cloud sprites | ||||
static void loadTextures( const string &tex_path ); | ||||
static sgVec3 modelSunDir; | ||||
static sgVec3 sunlight, ambLight; | ||||
static bool useAnisotropic; | ||||
static float nearRadius; | ||||
static bool lowQuality; | ||||
static SGBbCache *cldCache; | ||||
}; | }; | |||
#endif // _NEWCLOUD_HXX | #endif // _NEWCLOUD_HXX | |||
End of changes. 12 change blocks. | ||||
139 lines changed or deleted | 67 lines changed or added | |||
obj.hxx | obj.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: obj.hxx,v 1.5 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_OBJ_HXX | #ifndef _SG_OBJ_HXX | |||
#define _SG_OBJ_HXX | #define _SG_OBJ_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <plib/ssg.h> // plib include | #include <osg/Node> | |||
#include <osg/Group> | ||||
#include <simgear/math/point3d.hxx> | using std::string; | |||
SG_USING_STD(string); | ||||
class SGBucket; | ||||
class SGMaterialLib; | class SGMaterialLib; | |||
namespace simgear { | ||||
// Load a Binary obj file | class SGReaderWriterOptions; | |||
bool sgBinObjLoad( const string& path, const bool is_base, | } | |||
Point3D *center, | ||||
double *bounding_radius, | osg::Node* | |||
SGMaterialLib *matlib, | SGLoadBTG(const std::string& path, | |||
bool use_random_objects, | const simgear::SGReaderWriterOptions* options); | |||
ssgBranch *geometry, | ||||
ssgBranch *vasi_lights, | ||||
ssgBranch *rwy_lights, | ||||
ssgBranch *taxi_lights, | ||||
ssgVertexArray *ground_lights ); | ||||
// Generate an ocean tile | ||||
bool sgGenTile( const string& path, SGBucket b, | ||||
Point3D *center, double *bounding_radius, | ||||
SGMaterialLib *matlib, ssgBranch *geometry ); | ||||
#endif // _SG_OBJ_HXX | #endif // _SG_OBJ_HXX | |||
End of changes. 6 change blocks. | ||||
24 lines changed or deleted | 12 lines changed or added | |||
oursun.hxx | oursun.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: oursun.hxx,v 1.8 2006-07-27 05:15:20 durk Exp $ | // $Id$ | |||
#ifndef _SG_SUN_HXX_ | #ifndef _SG_SUN_HXX_ | |||
#define _SG_SUN_HXX_ | #define _SG_SUN_HXX_ | |||
#include <plib/ssg.h> | #include <osg/Array> | |||
#include <osg/Node> | ||||
#include <osg/MatrixTransform> | ||||
#include <simgear/structure/SGReferenced.hxx> | ||||
#include <simgear/misc/sg_path.hxx> | #include <simgear/misc/sg_path.hxx> | |||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
class SGSun { | class SGSun : public SGReferenced { | |||
ssgTransform *sun_transform; | osg::ref_ptr<osg::MatrixTransform> sun_transform; | |||
ssgSimpleState *sun_state; | ||||
ssgSimpleState *ihalo_state; | ||||
ssgSimpleState *ohalo_state; | ||||
ssgColourArray *sun_cl; | ||||
ssgColourArray *ihalo_cl; | ||||
ssgColourArray *ohalo_cl; | ||||
ssgVertexArray *sun_vl; | ||||
ssgVertexArray *ihalo_vl; | ||||
ssgVertexArray *ohalo_vl; | ||||
ssgTexCoordArray *sun_tl; | ||||
ssgTexCoordArray *ihalo_tl; | ||||
ssgTexCoordArray *ohalo_tl; | ||||
GLuint sun_texid; | osg::ref_ptr<osg::Vec4Array> sun_cl; | |||
GLubyte *sun_texbuf; | osg::ref_ptr<osg::Vec4Array> scene_cl; | |||
osg::ref_ptr<osg::Vec4Array> ihalo_cl; | ||||
osg::ref_ptr<osg::Vec4Array> ohalo_cl; | ||||
double visibility; | double visibility; | |||
double prev_sun_angle; | double prev_sun_angle; | |||
// distance of light traveling through the atmosphere | // distance of light traveling through the atmosphere | |||
double path_distance; | double path_distance; | |||
double sun_exp2_punch_through; | ||||
SGPropertyNode *env_node; | SGPropertyNode_ptr env_node; | |||
public: | public: | |||
// Constructor | // Constructor | |||
SGSun( void ); | SGSun( void ); | |||
// Destructor | // Destructor | |||
~SGSun( void ); | ~SGSun( void ); | |||
// return the sun object | // return the sun object | |||
ssgBranch *build( SGPath path, double sun_size, SGPropertyNode *propert y_tree_Node ); | osg::Node* build( SGPath path, double sun_size, SGPropertyNode *propert y_tree_Node ); | |||
// repaint the sun colors based on current value of sun_anglein | // repaint the sun colors based on current value of sun_anglein | |||
// degrees relative to verticle | // degrees relative to verticle | |||
// 0 degrees = high noon | // 0 degrees = high noon | |||
// 90 degrees = sun rise/set | // 90 degrees = sun rise/set | |||
// 180 degrees = darkest midnight | // 180 degrees = darkest midnight | |||
bool repaint( double sun_angle, double new_visibility ); | bool repaint( double sun_angle, double new_visibility ); | |||
// reposition the sun at the specified right ascension and | // reposition the sun at the specified right ascension and | |||
// declination, offset by our current position (p) so that it | // declination, offset by our current position (p) so that it | |||
// appears fixed at a great distance from the viewer. Also add in | // appears fixed at a great distance from the viewer. Also add in | |||
// an optional rotation (i.e. for the current time of day.) | // an optional rotation (i.e. for the current time of day.) | |||
bool reposition( sgVec3 p, double angle, | bool reposition( double rightAscension, double declination, | |||
double rightAscension, double declination, | ||||
double sun_dist, double lat, double alt_asl, double sun _angle ); | double sun_dist, double lat, double alt_asl, double sun _angle ); | |||
// retrun the current color of the sun | // retrun the current color of the sun | |||
inline float *get_color() { return ohalo_cl->get( 0 ); } | SGVec4f get_color(); | |||
SGVec4f get_scene_color(); | ||||
// return the texture id of the sun halo texture | ||||
inline GLuint get_texture_id() { return ohalo_state->getTextureHandle() | ||||
; } | ||||
}; | }; | |||
#endif // _SG_SUN_HXX_ | #endif // _SG_SUN_HXX_ | |||
End of changes. 10 change blocks. | ||||
30 lines changed or deleted | 18 lines changed or added | |||
persparam.hxx | persparam.hxx | |||
---|---|---|---|---|
/** | /** | |||
* $Id: persparam.hxx,v 1.4 2006-08-28 19:38:23 fredb Exp $ | * $Id$ | |||
*/ | */ | |||
#ifndef _SG_PERSPARAM_HXX | #ifndef _SG_PERSPARAM_HXX | |||
#define _SG_PERSPARAM_HXX 1 | #define _SG_PERSPARAM_HXX 1 | |||
#include <simgear/math/sg_random.h> | #include <simgear/math/sg_random.h> | |||
template <class T> | template <class T> | |||
class SGPersonalityParameter { | class SGPersonalityParameter { | |||
public: | public: | |||
SGPersonalityParameter( SGPropertyNode *props, const char *name, T defval ) | SGPersonalityParameter(const SGPropertyNode *props, const char *name, T d efval ) | |||
: _var( defval ), _min( defval ), _max( defval ) { | : _var( defval ), _min( defval ), _max( defval ) { | |||
SGPropertyNode_ptr node = props->getNode( name ); | const SGPropertyNode* node = props->getNode( name ); | |||
if ( node != 0 ) { | if ( node != 0 ) { | |||
SGPropertyNode_ptr rand_n = node->getNode( "random" ); | const SGPropertyNode* rand_n = node->getNode( "random" ); | |||
if ( rand_n != 0 ) { | if ( rand_n != 0 ) { | |||
_min = getNodeValue( rand_n, "min", (T)0 ); | _min = getNodeValue( rand_n, "min", (T)0 ); | |||
_max = getNodeValue( rand_n, "max", (T)1 ); | _max = getNodeValue( rand_n, "max", (T)1 ); | |||
shuffle(); | shuffle(); | |||
} else { | } else { | |||
_var = _min = _max = getNodeValue( props, name, defval ); | _var = _min = _max = getNodeValue( props, name, defval ); | |||
} | } | |||
} | } | |||
} | } | |||
SGPersonalityParameter<T> &operator=( T v ) { _var = v; return *this; } | SGPersonalityParameter<T> &operator=( T v ) { _var = v; return *this; } | |||
SGPersonalityParameter<T> &operator+=( T v ) { _var += v; return *this; } | SGPersonalityParameter<T> &operator+=( T v ) { _var += v; return *this; } | |||
SGPersonalityParameter<T> &operator-=( T v ) { _var -= v; return *this; } | SGPersonalityParameter<T> &operator-=( T v ) { _var -= v; return *this; } | |||
T shuffle() { return ( _var = _min + sg_random() * ( _max - _min ) ); } | T shuffle() { return ( _var = _min + sg_random() * ( _max - _min ) ); } | |||
T value() const { return _var; } | T value() const { return _var; } | |||
T getNodeValue( SGPropertyNode *props, const char *name, T defval ) const ; | T getNodeValue(const SGPropertyNode *props, const char *name, T defval ) const; | |||
operator T() const { return _var; } | operator T() const { return _var; } | |||
private: | private: | |||
T _var; | T _var; | |||
T _min; | T _min; | |||
T _max; | T _max; | |||
}; | }; | |||
template <> double | template <> double | |||
SGPersonalityParameter<double>::getNodeValue( SGPropertyNode *props, | SGPersonalityParameter<double>::getNodeValue( const SGPropertyNode *props, | |||
const char *name, | const char *name, | |||
double defval ) const; | double defval ) const; | |||
#endif // _SG_PERSPARAM_HXX | #endif // _SG_PERSPARAM_HXX | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 6 lines changed or added | |||
placement.hxx | placement.hxx | |||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
// | // | |||
// This file is in the Public Domain, and comes with no warranty. | // This file is in the Public Domain, and comes with no warranty. | |||
#ifndef _SG_PLACEMENT_HXX | #ifndef _SG_PLACEMENT_HXX | |||
#define _SG_PLACEMENT_HXX 1 | #define _SG_PLACEMENT_HXX 1 | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <plib/sg.h> | #include <osg/ref_ptr> | |||
#include <plib/ssg.h> | #include <osg/Node> | |||
#include <osg/Switch> | ||||
#include <osg/PositionAttitudeTransform> | ||||
#include <simgear/math/point3d.hxx> | #include <simgear/math/SGMath.hxx> | |||
#include <simgear/props/props.hxx> | ||||
#include <simgear/structure/ssgSharedPtr.hxx> | ||||
// Don't pull in the headers, since we don't need them here. | ||||
class SGLocation; | ||||
class ssgPlacementTransform; | ||||
// Has anyone done anything *really* stupid, like making min and max macros ? | // Has anyone done anything *really* stupid, like making min and max macros ? | |||
#ifdef min | #ifdef min | |||
#undef min | #undef min | |||
#endif | #endif | |||
#ifdef max | #ifdef max | |||
#undef max | #undef max | |||
#endif | #endif | |||
//////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////// | |||
skipping to change at line 46 | skipping to change at line 42 | |||
/** | /** | |||
* A wrapper for a model with a definite placement. | * A wrapper for a model with a definite placement. | |||
*/ | */ | |||
class SGModelPlacement | class SGModelPlacement | |||
{ | { | |||
public: | public: | |||
SGModelPlacement (); | SGModelPlacement (); | |||
virtual ~SGModelPlacement (); | virtual ~SGModelPlacement (); | |||
virtual void init( ssgBranch * model ); | virtual void init( osg::Node* model ); | |||
virtual void update(); | virtual void update(); | |||
virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; } | virtual osg::Node* getSceneGraph () { return _selector.get(); } | |||
virtual SGLocation * getSGLocation () { return _location; } | ||||
virtual bool getVisible () const; | virtual bool getVisible () const; | |||
virtual void setVisible (bool visible); | virtual void setVisible (bool visible); | |||
virtual double getLongitudeDeg () const { return _lon_deg; } | virtual double getLongitudeDeg () const { return _position.getLongitudeDe | |||
virtual double getLatitudeDeg () const { return _lat_deg; } | g(); } | |||
virtual double getElevationFt () const { return _elev_ft; } | virtual double getLatitudeDeg () const { return _position.getLatitudeDeg( | |||
); } | ||||
virtual double getElevationFt () const { return _position.getElevationFt( | ||||
); } | ||||
virtual void setLongitudeDeg (double lon_deg); | virtual void setLongitudeDeg (double lon_deg); | |||
virtual void setLatitudeDeg (double lat_deg); | virtual void setLatitudeDeg (double lat_deg); | |||
virtual void setElevationFt (double elev_ft); | virtual void setElevationFt (double elev_ft); | |||
virtual void setPosition (double lon_deg, double lat_deg, double elev_ft) ; | virtual void setPosition (double lon_deg, double lat_deg, double elev_ft) ; | |||
void setPosition(const SGGeod& position); | void setPosition(const SGGeod& position); | |||
const SGGeod& getPosition() const { return _position; } | ||||
virtual double getRollDeg () const { return _roll_deg; } | virtual double getRollDeg () const { return _roll_deg; } | |||
virtual double getPitchDeg () const { return _pitch_deg; } | virtual double getPitchDeg () const { return _pitch_deg; } | |||
virtual double getHeadingDeg () const { return _heading_deg; } | virtual double getHeadingDeg () const { return _heading_deg; } | |||
virtual void setRollDeg (double roll_deg); | virtual void setRollDeg (double roll_deg); | |||
virtual void setPitchDeg (double pitch_deg); | virtual void setPitchDeg (double pitch_deg); | |||
virtual void setHeadingDeg (double heading_deg); | virtual void setHeadingDeg (double heading_deg); | |||
virtual void setOrientation (double roll_deg, double pitch_deg, | virtual void setOrientation (double roll_deg, double pitch_deg, | |||
double heading_deg); | double heading_deg); | |||
void setOrientation(const SGQuatd& orientation); | void setOrientation(const SGQuatd& orientation); | |||
ssgPlacementTransform * getTransform(void) | void setReferenceTime(const double& referenceTime); | |||
{ return _position; } | void setBodyLinearVelocity(const SGVec3d& velocity); | |||
void setBodyAngularVelocity(const SGVec3d& velocity); | ||||
private: | private: | |||
// Geodetic position | // Geodetic position | |||
double _lon_deg; | SGGeod _position; | |||
double _lat_deg; | ||||
double _elev_ft; | ||||
// Orientation | // Orientation | |||
double _roll_deg; | double _roll_deg; | |||
double _pitch_deg; | double _pitch_deg; | |||
double _heading_deg; | double _heading_deg; | |||
ssgSharedPtr<ssgSelector> _selector; | osg::ref_ptr<osg::Switch> _selector; | |||
ssgSharedPtr<ssgPlacementTransform> _position; | osg::ref_ptr<osg::PositionAttitudeTransform> _transform; | |||
// Location | ||||
SGLocation * _location; | ||||
}; | }; | |||
#endif // _SG_PLACEMENT_HXX | #endif // _SG_PLACEMENT_HXX | |||
End of changes. 10 change blocks. | ||||
27 lines changed or deleted | 20 lines changed or added | |||
props.hxx | props.hxx | |||
---|---|---|---|---|
/** | /** | |||
* \file props.hxx | * \file props.hxx | |||
* Interface definition for a property list. | * Interface definition for a property list. | |||
* Started Fall 2000 by David Megginson, david@megginson.com | * Started Fall 2000 by David Megginson, david@megginson.com | |||
* This code is released into the Public Domain. | * This code is released into the Public Domain. | |||
* | * | |||
* See props.html for documentation [replace with URL when available]. | * See props.html for documentation [replace with URL when available]. | |||
* | * | |||
* $Id: props.hxx,v 1.18.2.4 2007-05-07 14:03:46 mfranz Exp $ | * $Id$ | |||
*/ | */ | |||
#ifndef __PROPS_HXX | #ifndef __PROPS_HXX | |||
#define __PROPS_HXX | #define __PROPS_HXX | |||
#ifndef PROPS_STANDALONE | #ifndef PROPS_STANDALONE | |||
#define PROPS_STANDALONE 0 | #define PROPS_STANDALONE 0 | |||
#endif | #endif | |||
#include <vector> | #include <vector> | |||
#if PROPS_STANDALONE | ||||
#include <string> | #include <string> | |||
#include <iostream> | #include <iostream> | |||
#include <sstream> | ||||
using std::string; | #include <boost/utility.hpp> | |||
using std::vector; | ||||
using std::istream; | ||||
using std::ostream; | ||||
#if PROPS_STANDALONE | ||||
#else | #else | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/debug/logstream.hxx> | #include <simgear/debug/logstream.hxx> | |||
#include STL_STRING | ||||
#include STL_IOSTREAM | ||||
SG_USING_STD(string); | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(istream); | ||||
SG_USING_STD(ostream); | ||||
#endif | #endif | |||
#include <simgear/math/SGMathFwd.hxx> | ||||
#include <simgear/math/sg_types.hxx> | ||||
#include <simgear/structure/SGReferenced.hxx> | #include <simgear/structure/SGReferenced.hxx> | |||
#include <simgear/structure/SGSharedPtr.hxx> | #include <simgear/structure/SGSharedPtr.hxx> | |||
// XXX This whole file should be in the simgear namespace, but I don't | ||||
// have the guts yet... | ||||
namespace simgear | ||||
{ | ||||
class PropertyInterpolationMgr; | ||||
template<typename T> | ||||
std::istream& readFrom(std::istream& stream, T& result) | ||||
{ | ||||
stream >> result; | ||||
return stream; | ||||
} | ||||
/** | ||||
* Parse a string as an object of a given type. | ||||
* XXX no error behavior yet. | ||||
* | ||||
* @tparam T the return type | ||||
* @param str the string | ||||
* @return the object. | ||||
*/ | ||||
template<typename T> | ||||
inline T parseString(const std::string& str) | ||||
{ | ||||
std::istringstream stream(str); | ||||
T result; | ||||
readFrom(stream, result); | ||||
return result; | ||||
} | ||||
/** | ||||
* Property value types. | ||||
*/ | ||||
#ifdef NONE | #ifdef NONE | |||
#pragma warn A sloppy coder has defined NONE as a macro! | #pragma warn A sloppy coder has defined NONE as a macro! | |||
#undef NONE | #undef NONE | |||
#endif | #endif | |||
#ifdef ALIAS | #ifdef ALIAS | |||
#pragma warn A sloppy coder has defined ALIAS as a macro! | #pragma warn A sloppy coder has defined ALIAS as a macro! | |||
#undef ALIAS | #undef ALIAS | |||
#endif | #endif | |||
skipping to change at line 91 | skipping to change at line 117 | |||
#ifdef DOUBLE | #ifdef DOUBLE | |||
#pragma warn A sloppy coder has defined DOUBLE as a macro! | #pragma warn A sloppy coder has defined DOUBLE as a macro! | |||
#undef DOUBLE | #undef DOUBLE | |||
#endif | #endif | |||
#ifdef STRING | #ifdef STRING | |||
#pragma warn A sloppy coder has defined STRING as a macro! | #pragma warn A sloppy coder has defined STRING as a macro! | |||
#undef STRING | #undef STRING | |||
#endif | #endif | |||
namespace props | ||||
{ | ||||
/** | ||||
* The possible types of an SGPropertyNode. Types that appear after | ||||
* EXTENDED are not stored in the SGPropertyNode itself. | ||||
*/ | ||||
enum Type { | ||||
NONE = 0, /**< The node hasn't been assigned a value yet. */ | ||||
ALIAS, /**< The node "points" to another node. */ | ||||
BOOL, | ||||
INT, | ||||
LONG, | ||||
FLOAT, | ||||
DOUBLE, | ||||
STRING, | ||||
UNSPECIFIED, | ||||
EXTENDED, /**< The node's value is not stored in the property; | ||||
* the actual value and type is retrieved from an | ||||
* SGRawValue node. This type is never returned by @see | ||||
* SGPropertyNode::getType. | ||||
*/ | ||||
// Extended properties | ||||
VEC3D, | ||||
VEC4D | ||||
}; | ||||
template<typename T> struct PropertyTraits; | ||||
#define DEFINTERNALPROP(TYPE, PROP) \ | ||||
template<> \ | ||||
struct PropertyTraits<TYPE> \ | ||||
{ \ | ||||
static const Type type_tag = PROP; \ | ||||
enum { Internal = 1 }; \ | ||||
} | ||||
DEFINTERNALPROP(bool, BOOL); | ||||
DEFINTERNALPROP(int, INT); | ||||
DEFINTERNALPROP(long, LONG); | ||||
DEFINTERNALPROP(float, FLOAT); | ||||
DEFINTERNALPROP(double, DOUBLE); | ||||
DEFINTERNALPROP(const char *, STRING); | ||||
DEFINTERNALPROP(const char[], STRING); | ||||
#undef DEFINTERNALPROP | ||||
} | ||||
} | ||||
//////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////// | |||
// A raw value. | // A raw value. | |||
// | // | |||
// This is the mechanism that information-providing routines can | // This is the mechanism that information-providing routines can | |||
// use to link their own values to the property manager. Any | // use to link their own values to the property manager. Any | |||
// SGValue can be tied to a raw value and then untied again. | // SGValue can be tied to a raw value and then untied again. | |||
// | // | |||
// Note: we are forced to use inlined methods here to ensure | // Note: we are forced to use inlined methods here to ensure | |||
// that the templates will be instantiated. We're probably taking | // that the templates will be instantiated. We're probably taking | |||
// a small performance hit for that. | // a small performance hit for that. | |||
//////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////// | |||
/** | /** | |||
* Base class for SGRawValue classes that holds no type | ||||
* information. This allows some generic manipulation of the | ||||
* SGRawValue object. | ||||
*/ | ||||
class SGRaw | ||||
{ | ||||
public: | ||||
/** | ||||
* Get the type enumeration for the raw value. | ||||
* | ||||
* @return the type. | ||||
*/ | ||||
virtual simgear::props::Type getType() const = 0; | ||||
virtual ~SGRaw() {} | ||||
/** | ||||
* Create a new deep copy of this raw value. | ||||
* | ||||
* The copy will contain its own version of the underlying value | ||||
* as well, and will be the same type. | ||||
* | ||||
* @return A deep copy of the current object. | ||||
*/ | ||||
virtual SGRaw* clone() const = 0; | ||||
}; | ||||
class SGRawExtended : public SGRaw | ||||
{ | ||||
public: | ||||
/** | ||||
* Make an SGRawValueContainer from the SGRawValue. | ||||
* | ||||
* This is a virtual function of SGRawExtended so that | ||||
* SGPropertyNode::untie doesn't need to know the type of an | ||||
* extended property. | ||||
*/ | ||||
virtual SGRawExtended* makeContainer() const = 0; | ||||
/** | ||||
* Write value out to a stream | ||||
*/ | ||||
virtual std::ostream& printOn(std::ostream& stream) const = 0; | ||||
/** | ||||
* Read value from a stream and store it. | ||||
*/ | ||||
virtual std::istream& readFrom(std::istream& stream) = 0; | ||||
}; | ||||
// Choose between different base classes based on whether the value is | ||||
// stored internal to the property node. This frees us from defining | ||||
// the virtual functions in the SGRawExtended interface where they | ||||
// don't make sense, e.g. readFrom for the const char* type. | ||||
template<typename T, int internal = simgear::props::PropertyTraits<T>::Inte | ||||
rnal> | ||||
class SGRawBase; | ||||
template<typename T> | ||||
class SGRawBase<T, 1> : public SGRaw | ||||
{ | ||||
}; | ||||
template<typename T> | ||||
class SGRawBase<T, 0> : public SGRawExtended | ||||
{ | ||||
virtual SGRawExtended* makeContainer() const; | ||||
virtual std::ostream& printOn(std::ostream& stream) const; | ||||
virtual std::istream& readFrom(std::istream& stream); | ||||
}; | ||||
/** | ||||
* Abstract base class for a raw value. | * Abstract base class for a raw value. | |||
* | * | |||
* <p>The property manager is implemented in two layers. The {@link | * <p>The property manager is implemented in two layers. The {@link | |||
* SGPropertyNode} is the highest and most abstract layer, | * SGPropertyNode} is the highest and most abstract layer, | |||
* representing an LValue/RValue pair: it records the position of the | * representing an LValue/RValue pair: it records the position of the | |||
* property in the property tree and contains facilities for | * property in the property tree and contains facilities for | |||
* navigation to other nodes. It is guaranteed to be persistent: the | * navigation to other nodes. It is guaranteed to be persistent: the | |||
* {@link SGPropertyNode} will not change during a session, even if | * {@link SGPropertyNode} will not change during a session, even if | |||
* the property is bound and unbound multiple times.</p> | * the property is bound and unbound multiple times.</p> | |||
* | * | |||
* <p>When the property value is not managed internally in the | * <p>When the property value is not managed internally in the | |||
* SGPropertyNode, the SGPropertyNode will contain a reference to an | * SGPropertyNode, the SGPropertyNode will contain a reference to an | |||
* SGRawValue (this class), which provides an abstract way to get, | * SGRawValue (this class), which provides an abstract way to get, | |||
* set, and clone the underlying value. The SGRawValue may change | * set, and clone the underlying value. The SGRawValue may change | |||
* frequently during a session as a value is retyped or bound and | * frequently during a session as a value is retyped or bound and | |||
* unbound to various data source, but the abstract SGPropertyNode | * unbound to various data source, but the abstract SGPropertyNode | |||
* layer insulates the application from those changes. The raw value | * layer insulates the application from those changes. | |||
* contains no facilities for data binding or for type conversion: it | ||||
* is simply the abstraction of a primitive data type (or a compound | ||||
* data type, in the case of a string).</p> | ||||
* | * | |||
* <p>The SGPropertyNode class always keeps a *copy* of a raw value, | * <p>The SGPropertyNode class always keeps a *copy* of a raw value, | |||
* not the original one passed to it; if you override a derived class | * not the original one passed to it; if you override a derived class | |||
* but do not replace the {@link #clone} method, strange things will | * but do not replace the {@link #clone} method, strange things will | |||
* happen.</p> | * happen.</p> | |||
* | * | |||
* <p>All derived SGRawValue classes must implement {@link #getValue}, | * <p>All derived SGRawValue classes must implement {@link #getValue}, | |||
* {@link #setValue}, and {@link #clone} for the appropriate type.</p> | * {@link #setValue}, and {@link #clone} for the appropriate type.</p> | |||
* | * | |||
* @see SGPropertyNode | * @see SGPropertyNode | |||
* @see SGRawValuePointer | * @see SGRawValuePointer | |||
* @see SGRawValueFunctions | * @see SGRawValueFunctions | |||
* @see SGRawValueFunctionsIndexed | * @see SGRawValueFunctionsIndexed | |||
* @see SGRawValueMethods | * @see SGRawValueMethods | |||
* @see SGRawValueMethodsIndexed | * @see SGRawValueMethodsIndexed | |||
* @see SGRawValueContainer | ||||
*/ | */ | |||
template <class T> | template <class T> | |||
class SGRawValue | class SGRawValue : public SGRawBase<T> | |||
{ | { | |||
public: | public: | |||
/** | /** | |||
* The default underlying value for this type. | * The default underlying value for this type. | |||
* | * | |||
* Every raw value has a default; the default is false for a | * Every raw value has a default; the default is false for a | |||
* boolean, 0 for the various numeric values, and "" for a string. | * boolean, 0 for the various numeric values, and "" for a string. | |||
* If additional types of raw values are added in the future, they | * If additional types of raw values are added in the future, they | |||
* may need different kinds of default values (such as epoch for a | * may need different kinds of default values (such as epoch for a | |||
* date type). The default value is used when creating new values. | * date type). The default value is used when creating new values. | |||
*/ | */ | |||
static const T DefaultValue; // Default for this kind of raw value. | static T DefaultValue() | |||
{ | ||||
return T(); | ||||
} | ||||
/** | /** | |||
* Constructor. | * Constructor. | |||
* | * | |||
* Use the default value for this type. | * Use the default value for this type. | |||
*/ | */ | |||
SGRawValue () {} | SGRawValue () {} | |||
/** | /** | |||
* Destructor. | * Destructor. | |||
skipping to change at line 191 | skipping to change at line 336 | |||
* some reason) this method returns false and leaves the original | * some reason) this method returns false and leaves the original | |||
* value unchanged. | * value unchanged. | |||
* | * | |||
* @param value The actual value for the property. | * @param value The actual value for the property. | |||
* @return true if the value was set successfully, false otherwise. | * @return true if the value was set successfully, false otherwise. | |||
* @see #getValue | * @see #getValue | |||
*/ | */ | |||
virtual bool setValue (T value) = 0; | virtual bool setValue (T value) = 0; | |||
/** | /** | |||
* Create a new deep copy of this raw value. | * Return the type tag for this raw value type. | |||
* | ||||
* The copy will contain its own version of the underlying value | ||||
* as well. | ||||
* | ||||
* @return A deep copy of the current object. | ||||
*/ | */ | |||
virtual SGRawValue * clone () const = 0; | virtual simgear::props::Type getType() const | |||
{ | ||||
return simgear::props::PropertyTraits<T>::type_tag; | ||||
} | ||||
}; | }; | |||
//////////////////////////////////////////////////////////////////////// | ||||
// Default values for every type. | ||||
//////////////////////////////////////////////////////////////////////// | ||||
template<> inline bool SGRawValue<bool>::DefaultValue() | ||||
{ | ||||
return false; | ||||
} | ||||
template<> inline const char * SGRawValue<const char *>::DefaultValue() | ||||
{ | ||||
return ""; | ||||
} | ||||
/** | /** | |||
* A raw value bound to a pointer. | * A raw value bound to a pointer. | |||
* | * | |||
* This is the most efficient way to tie an external value, but also | * This is the most efficient way to tie an external value, but also | |||
* the most dangerous, because there is no way for the supplier to | * the most dangerous, because there is no way for the supplier to | |||
* perform bounds checking and derived calculations except by polling | * perform bounds checking and derived calculations except by polling | |||
* the variable to see if it has changed. There is no default | * the variable to see if it has changed. There is no default | |||
* constructor, because this class would be meaningless without a | * constructor, because this class would be meaningless without a | |||
* pointer. | * pointer. | |||
*/ | */ | |||
skipping to change at line 253 | skipping to change at line 410 | |||
* This method will dereference the pointer and change the | * This method will dereference the pointer and change the | |||
* variable's value. | * variable's value. | |||
*/ | */ | |||
virtual bool setValue (T value) { *_ptr = value; return true; } | virtual bool setValue (T value) { *_ptr = value; return true; } | |||
/** | /** | |||
* Create a copy of this raw value. | * Create a copy of this raw value. | |||
* | * | |||
* The copy will use the same external pointer as the original. | * The copy will use the same external pointer as the original. | |||
*/ | */ | |||
virtual SGRawValue<T> * clone () const { | virtual SGRaw* clone () const { | |||
return new SGRawValuePointer<T>(_ptr); | return new SGRawValuePointer(_ptr); | |||
} | } | |||
private: | private: | |||
T * _ptr; | T * _ptr; | |||
}; | }; | |||
/** | /** | |||
* A value managed through static functions. | * A value managed through static functions. | |||
* | * | |||
* A read-only value will not have a setter; a write-only value will | * A read-only value will not have a setter; a write-only value will | |||
skipping to change at line 309 | skipping to change at line 466 | |||
/** | /** | |||
* Get the underlying value. | * Get the underlying value. | |||
* | * | |||
* This method will invoke the getter function to get a value. | * This method will invoke the getter function to get a value. | |||
* If no getter function was supplied, this method will always | * If no getter function was supplied, this method will always | |||
* return the default value for the type. | * return the default value for the type. | |||
*/ | */ | |||
virtual T getValue () const { | virtual T getValue () const { | |||
if (_getter) return (*_getter)(); | if (_getter) return (*_getter)(); | |||
else return SGRawValue<T>::DefaultValue; | else return SGRawValue<T>::DefaultValue(); | |||
} | } | |||
/** | /** | |||
* Set the underlying value. | * Set the underlying value. | |||
* | * | |||
* This method will invoke the setter function to change the | * This method will invoke the setter function to change the | |||
* underlying value. If no setter function was supplied, this | * underlying value. If no setter function was supplied, this | |||
* method will return false. | * method will return false. | |||
*/ | */ | |||
virtual bool setValue (T value) { | virtual bool setValue (T value) { | |||
if (_setter) { (*_setter)(value); return true; } | if (_setter) { (*_setter)(value); return true; } | |||
else return false; | else return false; | |||
} | } | |||
/** | /** | |||
* Create a copy of this raw value, bound to the same functions. | * Create a copy of this raw value, bound to the same functions. | |||
*/ | */ | |||
virtual SGRawValue<T> * clone () const { | virtual SGRaw* clone () const { | |||
return new SGRawValueFunctions<T>(_getter,_setter); | return new SGRawValueFunctions(_getter,_setter); | |||
} | } | |||
private: | private: | |||
getter_t _getter; | getter_t _getter; | |||
setter_t _setter; | setter_t _setter; | |||
}; | }; | |||
/** | /** | |||
* An indexed value bound to static functions. | * An indexed value bound to static functions. | |||
* | * | |||
skipping to change at line 357 | skipping to change at line 514 | |||
class SGRawValueFunctionsIndexed : public SGRawValue<T> | class SGRawValueFunctionsIndexed : public SGRawValue<T> | |||
{ | { | |||
public: | public: | |||
typedef T (*getter_t)(int); | typedef T (*getter_t)(int); | |||
typedef void (*setter_t)(int,T); | typedef void (*setter_t)(int,T); | |||
SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t sett er = 0) | SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t sett er = 0) | |||
: _index(index), _getter(getter), _setter(setter) {} | : _index(index), _getter(getter), _setter(setter) {} | |||
virtual ~SGRawValueFunctionsIndexed () {} | virtual ~SGRawValueFunctionsIndexed () {} | |||
virtual T getValue () const { | virtual T getValue () const { | |||
if (_getter) return (*_getter)(_index); | if (_getter) return (*_getter)(_index); | |||
else return SGRawValue<T>::DefaultValue; | else return SGRawValue<T>::DefaultValue(); | |||
} | } | |||
virtual bool setValue (T value) { | virtual bool setValue (T value) { | |||
if (_setter) { (*_setter)(_index, value); return true; } | if (_setter) { (*_setter)(_index, value); return true; } | |||
else return false; | else return false; | |||
} | } | |||
virtual SGRawValue<T> * clone () const { | virtual SGRaw* clone () const { | |||
return new SGRawValueFunctionsIndexed<T>(_index, _getter, _setter); | return new SGRawValueFunctionsIndexed(_index, _getter, _setter); | |||
} | } | |||
private: | private: | |||
int _index; | int _index; | |||
getter_t _getter; | getter_t _getter; | |||
setter_t _setter; | setter_t _setter; | |||
}; | }; | |||
/** | /** | |||
* A value managed through an object and access methods. | * A value managed through an object and access methods. | |||
* | * | |||
skipping to change at line 389 | skipping to change at line 546 | |||
class SGRawValueMethods : public SGRawValue<T> | class SGRawValueMethods : public SGRawValue<T> | |||
{ | { | |||
public: | public: | |||
typedef T (C::*getter_t)() const; | typedef T (C::*getter_t)() const; | |||
typedef void (C::*setter_t)(T); | typedef void (C::*setter_t)(T); | |||
SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0) | SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0) | |||
: _obj(obj), _getter(getter), _setter(setter) {} | : _obj(obj), _getter(getter), _setter(setter) {} | |||
virtual ~SGRawValueMethods () {} | virtual ~SGRawValueMethods () {} | |||
virtual T getValue () const { | virtual T getValue () const { | |||
if (_getter) { return (_obj.*_getter)(); } | if (_getter) { return (_obj.*_getter)(); } | |||
else { return SGRawValue<T>::DefaultValue; } | else { return SGRawValue<T>::DefaultValue(); } | |||
} | } | |||
virtual bool setValue (T value) { | virtual bool setValue (T value) { | |||
if (_setter) { (_obj.*_setter)(value); return true; } | if (_setter) { (_obj.*_setter)(value); return true; } | |||
else return false; | else return false; | |||
} | } | |||
virtual SGRawValue<T> * clone () const { | virtual SGRaw* clone () const { | |||
return new SGRawValueMethods<C,T>(_obj, _getter, _setter); | return new SGRawValueMethods(_obj, _getter, _setter); | |||
} | } | |||
private: | private: | |||
C &_obj; | C &_obj; | |||
getter_t _getter; | getter_t _getter; | |||
setter_t _setter; | setter_t _setter; | |||
}; | }; | |||
/** | /** | |||
* An indexed value managed through an object and access methods. | * An indexed value managed through an object and access methods. | |||
* | * | |||
skipping to change at line 422 | skipping to change at line 579 | |||
{ | { | |||
public: | public: | |||
typedef T (C::*getter_t)(int) const; | typedef T (C::*getter_t)(int) const; | |||
typedef void (C::*setter_t)(int, T); | typedef void (C::*setter_t)(int, T); | |||
SGRawValueMethodsIndexed (C &obj, int index, | SGRawValueMethodsIndexed (C &obj, int index, | |||
getter_t getter = 0, setter_t setter = 0) | getter_t getter = 0, setter_t setter = 0) | |||
: _obj(obj), _index(index), _getter(getter), _setter(setter) {} | : _obj(obj), _index(index), _getter(getter), _setter(setter) {} | |||
virtual ~SGRawValueMethodsIndexed () {} | virtual ~SGRawValueMethodsIndexed () {} | |||
virtual T getValue () const { | virtual T getValue () const { | |||
if (_getter) { return (_obj.*_getter)(_index); } | if (_getter) { return (_obj.*_getter)(_index); } | |||
else { return SGRawValue<T>::DefaultValue; } | else { return SGRawValue<T>::DefaultValue(); } | |||
} | } | |||
virtual bool setValue (T value) { | virtual bool setValue (T value) { | |||
if (_setter) { (_obj.*_setter)(_index, value); return true; } | if (_setter) { (_obj.*_setter)(_index, value); return true; } | |||
else return false; | else return false; | |||
} | } | |||
virtual SGRawValue<T> * clone () const { | virtual SGRaw* clone () const { | |||
return new SGRawValueMethodsIndexed<C,T>(_obj, _index, _getter, _setter | return new SGRawValueMethodsIndexed(_obj, _index, _getter, _setter); | |||
); | ||||
} | } | |||
private: | private: | |||
C &_obj; | C &_obj; | |||
int _index; | int _index; | |||
getter_t _getter; | getter_t _getter; | |||
setter_t _setter; | setter_t _setter; | |||
}; | }; | |||
/** | ||||
* A raw value that contains its value. This provides a way for | ||||
* property nodes to contain values that shouldn't be stored in the | ||||
* property node itself. | ||||
*/ | ||||
template <class T> | ||||
class SGRawValueContainer : public SGRawValue<T> | ||||
{ | ||||
public: | ||||
/** | ||||
* Explicit constructor. | ||||
*/ | ||||
SGRawValueContainer(const T& obj) : _obj(obj) {} | ||||
/** | ||||
* Destructor. | ||||
*/ | ||||
virtual ~SGRawValueContainer() {} | ||||
/** | ||||
* Get the underlying value. | ||||
*/ | ||||
virtual T getValue() const { return _obj; } | ||||
/** | ||||
* Set the underlying value. | ||||
* | ||||
* This method will dereference the pointer and change the | ||||
* variable's value. | ||||
*/ | ||||
virtual bool setValue (T value) { _obj = value; return true; } | ||||
/** | ||||
* Create a copy of this raw value. | ||||
*/ | ||||
virtual SGRaw* clone () const { | ||||
return new SGRawValueContainer(_obj); | ||||
} | ||||
private: | ||||
T _obj; | ||||
}; | ||||
template<typename T> | ||||
SGRawExtended* SGRawBase<T, 0>::makeContainer() const | ||||
{ | ||||
return new SGRawValueContainer<T>(static_cast<const SGRawValue<T>*>(thi | ||||
s) | ||||
->getValue()); | ||||
} | ||||
template<typename T> | ||||
std::ostream& SGRawBase<T, 0>::printOn(std::ostream& stream) const | ||||
{ | ||||
return stream << static_cast<SGRawValue<T>*>(this)->getValue(); | ||||
} | ||||
template<typename T> | ||||
std::istream& SGRawBase<T, 0>::readFrom(std::istream& stream) | ||||
{ | ||||
T value; | ||||
simgear::readFrom(stream, value); | ||||
static_cast<SGRawValue<T>*>(this)->setValue(value); | ||||
return stream; | ||||
} | ||||
/** | /** | |||
* The smart pointer that manage reference counting | * The smart pointer that manage reference counting | |||
*/ | */ | |||
class SGPropertyNode; | class SGPropertyNode; | |||
typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr; | typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr; | |||
typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr; | typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr; | |||
namespace simgear | ||||
{ | ||||
typedef std::vector<SGPropertyNode_ptr> PropertyList; | ||||
} | ||||
/** | /** | |||
* The property change listener interface. | * The property change listener interface. | |||
* | * | |||
* <p>Any class that needs to listen for property changes must implement | * <p>Any class that needs to listen for property changes must implement | |||
* this interface.</p> | * this interface.</p> | |||
*/ | */ | |||
class SGPropertyChangeListener | class SGPropertyChangeListener | |||
{ | { | |||
public: | public: | |||
virtual ~SGPropertyChangeListener (); | virtual ~SGPropertyChangeListener (); | |||
virtual void valueChanged (SGPropertyNode * node); | virtual void valueChanged (SGPropertyNode * node); | |||
virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child) ; | virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child) ; | |||
virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * chil d); | virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * chil d); | |||
protected: | protected: | |||
friend class SGPropertyNode; | friend class SGPropertyNode; | |||
virtual void register_property (SGPropertyNode * node); | virtual void register_property (SGPropertyNode * node); | |||
virtual void unregister_property (SGPropertyNode * node); | virtual void unregister_property (SGPropertyNode * node); | |||
private: | private: | |||
vector<SGPropertyNode *> _properties; | std::vector<SGPropertyNode *> _properties; | |||
}; | }; | |||
/** | /** | |||
* A node in a property tree. | * A node in a property tree. | |||
*/ | */ | |||
class SGPropertyNode : public SGReferenced | class SGPropertyNode : public SGReferenced | |||
{ | { | |||
public: | public: | |||
/** | /** | |||
* Public constants. | * Public constants. | |||
*/ | */ | |||
enum { | enum { | |||
MAX_STRING_LEN = 1024 | MAX_STRING_LEN = 1024 | |||
}; | }; | |||
/** | /** | |||
* Property value types. | ||||
*/ | ||||
enum Type { | ||||
NONE = 0, | ||||
ALIAS, | ||||
BOOL, | ||||
INT, | ||||
LONG, | ||||
FLOAT, | ||||
DOUBLE, | ||||
STRING, | ||||
UNSPECIFIED | ||||
}; | ||||
/** | ||||
* Access mode attributes. | * Access mode attributes. | |||
* | * | |||
* <p>The ARCHIVE attribute is strictly advisory, and controls | * <p>The ARCHIVE attribute is strictly advisory, and controls | |||
* whether the property should normally be saved and restored.</p> | * whether the property should normally be saved and restored.</p> | |||
*/ | */ | |||
enum Attribute { | enum Attribute { | |||
READ = 1, | READ = 1, | |||
WRITE = 2, | WRITE = 2, | |||
ARCHIVE = 4, | ARCHIVE = 4, | |||
REMOVED = 8, | REMOVED = 8, | |||
TRACE_READ = 16, | TRACE_READ = 16, | |||
TRACE_WRITE = 32, | TRACE_WRITE = 32, | |||
USERARCHIVE = 64 | USERARCHIVE = 64, | |||
PRESERVE = 128 | ||||
// beware: if you add another attribute here, | ||||
// also update value of "LAST_USED_ATTRIBUTE". | ||||
}; | }; | |||
/** | /** | |||
* Last used attribute | * Last used attribute | |||
* Update as needed when enum Attribute is changed | * Update as needed when enum Attribute is changed | |||
*/ | */ | |||
static const int LAST_USED_ATTRIBUTE; | static const int LAST_USED_ATTRIBUTE; | |||
/** | /** | |||
* Default constructor. | * Default constructor. | |||
skipping to change at line 538 | skipping to change at line 757 | |||
*/ | */ | |||
virtual ~SGPropertyNode (); | virtual ~SGPropertyNode (); | |||
// | // | |||
// Basic properties. | // Basic properties. | |||
// | // | |||
/** | /** | |||
* Test whether this node contains a primitive leaf value. | * Test whether this node contains a primitive leaf value. | |||
*/ | */ | |||
bool hasValue () const { return (_type != NONE); } | bool hasValue () const { return (_type != simgear::props::NONE); } | |||
/** | /** | |||
* Get the node's simple (XML) name. | * Get the node's simple (XML) name. | |||
*/ | */ | |||
const char * getName () const { return _name.c_str(); } | const char * getName () const { return _name.c_str(); } | |||
/** | /** | |||
* Get the node's simple name as a string. | ||||
*/ | ||||
const std::string& getNameString () const { return _name; } | ||||
/** | ||||
* Get the node's pretty display name, with subscript when needed. | * Get the node's pretty display name, with subscript when needed. | |||
*/ | */ | |||
const char * getDisplayName (bool simplify = false) const; | std::string getDisplayName (bool simplify = false) const; | |||
/** | /** | |||
* Get the node's integer index. | * Get the node's integer index. | |||
*/ | */ | |||
int getIndex () const { return _index; } | int getIndex () const { return _index; } | |||
/** | /** | |||
* Get a non-const pointer to the node's parent. | * Get a non-const pointer to the node's parent. | |||
*/ | */ | |||
SGPropertyNode * getParent () { return _parent; } | SGPropertyNode * getParent () { return _parent; } | |||
skipping to change at line 572 | skipping to change at line 796 | |||
*/ | */ | |||
const SGPropertyNode * getParent () const { return _parent; } | const SGPropertyNode * getParent () const { return _parent; } | |||
// | // | |||
// Children. | // Children. | |||
// | // | |||
/** | /** | |||
* Get the number of child nodes. | * Get the number of child nodes. | |||
*/ | */ | |||
int nChildren () const { return _children.size(); } | int nChildren () const { return (int)_children.size(); } | |||
/** | /** | |||
* Get a child node by position (*NOT* index). | * Get a child node by position (*NOT* index). | |||
*/ | */ | |||
SGPropertyNode * getChild (int position); | SGPropertyNode * getChild (int position); | |||
/** | /** | |||
* Get a const child node by position (*NOT* index). | * Get a const child node by position (*NOT* index). | |||
*/ | */ | |||
const SGPropertyNode * getChild (int position) const; | const SGPropertyNode * getChild (int position) const; | |||
/** | /** | |||
* Test whether a named child exists. | * Test whether a named child exists. | |||
*/ | */ | |||
bool hasChild (const char * name, int index = 0) const | bool hasChild (const char * name, int index = 0) const | |||
{ | { | |||
return (getChild(name, index) != 0); | return (getChild(name, index) != 0); | |||
} | } | |||
/** | /** | |||
* Get a child node by name and index. | * Test whether a named child exists. | |||
*/ | */ | |||
SGPropertyNode * getChild (const char * name, int index = 0, | bool hasChild (const std::string& name, int index = 0) const | |||
bool create = false); | { | |||
return (getChild(name, index) != 0); | ||||
} | ||||
/** | /** | |||
* Create a new child node with the given name and an unused index | ||||
* | ||||
* @param min_index Minimal index for new node (skips lower indices) | ||||
* @param append Whether to simply use the index after the last used i | ||||
ndex | ||||
* or use a lower, unused index if it exists | ||||
*/ | ||||
SGPropertyNode * addChild ( const char* name, | ||||
int min_index = 0, | ||||
bool append = true ); | ||||
SGPropertyNode * addChild ( const std::string& name, | ||||
int min_index = 0, | ||||
bool append = true ) | ||||
{ return addChild(name.c_str(), min_index, append); } | ||||
/** | ||||
* Create multiple child nodes with the given name an unused indices | ||||
* | ||||
* @param count The number of nodes create | ||||
* @param min_index Minimal index for new nodes (skips lower indices) | ||||
* @param append Whether to simply use the index after the last used i | ||||
ndex | ||||
* or use a lower, unused index if it exists | ||||
*/ | ||||
simgear::PropertyList addChildren ( const std::string& name, | ||||
size_t count, | ||||
int min_index = 0, | ||||
bool append = true ); | ||||
/** | ||||
* Get a child node by name and index. | ||||
*/ | ||||
SGPropertyNode * getChild (const char* name, int index = 0, | ||||
bool create = false); | ||||
SGPropertyNode * getChild (const std::string& name, int index = 0, | ||||
bool create = false); | ||||
/** | ||||
* Get a const child node by name and index. | * Get a const child node by name and index. | |||
*/ | */ | |||
const SGPropertyNode * getChild (const char * name, int index = 0) const; | const SGPropertyNode * getChild (const char * name, int index = 0) const; | |||
/** | /** | |||
* Get a const child node by name and index. | ||||
*/ | ||||
const SGPropertyNode * getChild (const std::string& name, int index = 0) | ||||
const | ||||
{ return getChild(name.c_str(), index); } | ||||
/** | ||||
* Get a vector of all children with the specified name. | * Get a vector of all children with the specified name. | |||
*/ | */ | |||
vector<SGPropertyNode_ptr> getChildren (const char * name) const; | simgear::PropertyList getChildren (const char * name) const; | |||
/** | ||||
* Get a vector of all children with the specified name. | ||||
*/ | ||||
simgear::PropertyList getChildren (const std::string& name) const | ||||
{ return getChildren(name.c_str()); } | ||||
/** | /** | |||
* Remove child by position. | * Remove child by position. | |||
*/ | */ | |||
SGPropertyNode_ptr removeChild (int pos, bool keep = true); | SGPropertyNode_ptr removeChild (int pos, bool keep = true); | |||
/** | /** | |||
* Remove a child node | * Remove a child node | |||
*/ | */ | |||
SGPropertyNode_ptr removeChild (const char * name, int index = 0, | SGPropertyNode_ptr removeChild (const char * name, int index = 0, | |||
bool keep = true); | bool keep = true); | |||
/** | /** | |||
* Remove a child node | ||||
*/ | ||||
SGPropertyNode_ptr removeChild (const std::string& name, int index = 0, | ||||
bool keep = true) | ||||
{ return removeChild(name.c_str(), index, keep); } | ||||
/** | ||||
* Remove all children with the specified name. | * Remove all children with the specified name. | |||
*/ | */ | |||
vector<SGPropertyNode_ptr> removeChildren (const char * name, | simgear::PropertyList removeChildren (const char * name, bool keep = true | |||
bool keep = true); | ); | |||
/** | ||||
* Remove all children with the specified name. | ||||
*/ | ||||
simgear::PropertyList removeChildren (const std::string& name, | ||||
bool keep = true) | ||||
{ return removeChildren(name.c_str(), keep); } | ||||
// | // | |||
// Alias support. | // Alias support. | |||
// | // | |||
/** | /** | |||
* Alias this node's leaf value to another's. | * Alias this node's leaf value to another's. | |||
*/ | */ | |||
bool alias (SGPropertyNode * target); | bool alias (SGPropertyNode * target); | |||
/** | /** | |||
* Alias this node's leaf value to another's by relative path. | * Alias this node's leaf value to another's by relative path. | |||
*/ | */ | |||
bool alias (const char * path); | bool alias (const char * path); | |||
/** | /** | |||
* Alias this node's leaf value to another's by relative path. | ||||
*/ | ||||
bool alias (const std::string& path) | ||||
{ return alias(path.c_str()); } | ||||
/** | ||||
* Remove any alias for this node. | * Remove any alias for this node. | |||
*/ | */ | |||
bool unalias (); | bool unalias (); | |||
/** | /** | |||
* Test whether the node's leaf value is aliased to another's. | * Test whether the node's leaf value is aliased to another's. | |||
*/ | */ | |||
bool isAlias () const { return (_type == ALIAS); } | bool isAlias () const { return (_type == simgear::props::ALIAS); } | |||
/** | /** | |||
* Get a non-const pointer to the current alias target, if any. | * Get a non-const pointer to the current alias target, if any. | |||
*/ | */ | |||
SGPropertyNode * getAliasTarget (); | SGPropertyNode * getAliasTarget (); | |||
/** | /** | |||
* Get a const pointer to the current alias target, if any. | * Get a const pointer to the current alias target, if any. | |||
*/ | */ | |||
const SGPropertyNode * getAliasTarget () const; | const SGPropertyNode * getAliasTarget () const; | |||
// | // | |||
// Path information. | // Path information. | |||
// | // | |||
/** | /** | |||
* Get the path to this node from the root. | * Get the path to this node from the root. | |||
*/ | */ | |||
const char * getPath (bool simplify = false) const; | std::string getPath (bool simplify = false) const; | |||
/** | /** | |||
* Get a pointer to the root node. | * Get a pointer to the root node. | |||
*/ | */ | |||
SGPropertyNode * getRootNode (); | SGPropertyNode * getRootNode (); | |||
/** | /** | |||
* Get a const pointer to the root node. | * Get a const pointer to the root node. | |||
*/ | */ | |||
const SGPropertyNode * getRootNode () const; | const SGPropertyNode * getRootNode () const; | |||
/** | /** | |||
* Get a pointer to another node by relative path. | * Get a pointer to another node by relative path. | |||
*/ | */ | |||
SGPropertyNode * getNode (const char * relative_path, bool create = false ); | SGPropertyNode * getNode (const char * relative_path, bool create = false ); | |||
/** | /** | |||
* Get a pointer to another node by relative path. | * Get a pointer to another node by relative path. | |||
*/ | ||||
SGPropertyNode * getNode (const std::string& relative_path, bool create = | ||||
false) | ||||
{ return getNode(relative_path.c_str(), create); } | ||||
/** | ||||
* Get a pointer to another node by relative path. | ||||
* | * | |||
* This method leaves the index off the last member of the path, | * This method leaves the index off the last member of the path, | |||
* so that the user can specify it separately (and save some | * so that the user can specify it separately (and save some | |||
* string building). For example, getNode("/bar[1]/foo", 3) is | * string building). For example, getNode("/bar[1]/foo", 3) is | |||
* exactly equivalent to getNode("bar[1]/foo[3]"). The index | * exactly equivalent to getNode("bar[1]/foo[3]"). The index | |||
* provided overrides any given in the path itself for the last | * provided overrides any given in the path itself for the last | |||
* component. | * component. | |||
*/ | */ | |||
SGPropertyNode * getNode (const char * relative_path, int index, | SGPropertyNode * getNode (const char * relative_path, int index, | |||
bool create = false); | bool create = false); | |||
/** | /** | |||
* Get a pointer to another node by relative path. | ||||
* | ||||
* This method leaves the index off the last member of the path, | ||||
* so that the user can specify it separately (and save some | ||||
* string building). For example, getNode("/bar[1]/foo", 3) is | ||||
* exactly equivalent to getNode("bar[1]/foo[3]"). The index | ||||
* provided overrides any given in the path itself for the last | ||||
* component. | ||||
*/ | ||||
SGPropertyNode * getNode (const std::string& relative_path, int index, | ||||
bool create = false) | ||||
{ return getNode(relative_path.c_str(), index, create); } | ||||
/** | ||||
* Get a const pointer to another node by relative path. | * Get a const pointer to another node by relative path. | |||
*/ | */ | |||
const SGPropertyNode * getNode (const char * relative_path) const; | const SGPropertyNode * getNode (const char * relative_path) const; | |||
/** | /** | |||
* Get a const pointer to another node by relative path. | * Get a const pointer to another node by relative path. | |||
*/ | ||||
const SGPropertyNode * getNode (const std::string& relative_path) const | ||||
{ return getNode(relative_path.c_str()); } | ||||
/** | ||||
* Get a const pointer to another node by relative path. | ||||
* | * | |||
* This method leaves the index off the last member of the path, | * This method leaves the index off the last member of the path, | |||
* so that the user can specify it separate. | * so that the user can specify it separate. | |||
*/ | */ | |||
const SGPropertyNode * getNode (const char * relative_path, | const SGPropertyNode * getNode (const char * relative_path, | |||
int index) const; | int index) const; | |||
/** | ||||
* Get a const pointer to another node by relative path. | ||||
* | ||||
* This method leaves the index off the last member of the path, | ||||
* so that the user can specify it separate. | ||||
*/ | ||||
const SGPropertyNode * getNode (const std::string& relative_path, | ||||
int index) const | ||||
{ return getNode(relative_path.c_str(), index); } | ||||
// | // | |||
// Access Mode. | // Access Mode. | |||
// | // | |||
/** | /** | |||
* Check a single mode attribute for the property node. | * Check a single mode attribute for the property node. | |||
*/ | */ | |||
bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); } | bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); } | |||
/** | /** | |||
skipping to change at line 743 | skipping to change at line 1071 | |||
*/ | */ | |||
void setAttributes (int attr) { _attr = attr; } | void setAttributes (int attr) { _attr = attr; } | |||
// | // | |||
// Leaf Value (primitive). | // Leaf Value (primitive). | |||
// | // | |||
/** | /** | |||
* Get the type of leaf value, if any, for this node. | * Get the type of leaf value, if any, for this node. | |||
*/ | */ | |||
Type getType () const; | simgear::props::Type getType () const; | |||
/** | /** | |||
* Get a bool value for this node. | * Get a bool value for this node. | |||
*/ | */ | |||
bool getBoolValue () const; | bool getBoolValue () const; | |||
/** | /** | |||
* Get an int value for this node. | * Get an int value for this node. | |||
*/ | */ | |||
int getIntValue () const; | int getIntValue () const; | |||
skipping to change at line 776 | skipping to change at line 1104 | |||
* Get a double value for this node. | * Get a double value for this node. | |||
*/ | */ | |||
double getDoubleValue () const; | double getDoubleValue () const; | |||
/** | /** | |||
* Get a string value for this node. | * Get a string value for this node. | |||
*/ | */ | |||
const char * getStringValue () const; | const char * getStringValue () const; | |||
/** | /** | |||
* Get a value from a node. If the actual type of the node doesn't | ||||
* match the desired type, a conversion isn't guaranteed. | ||||
*/ | ||||
template<typename T> | ||||
T getValue(typename boost::enable_if_c<simgear::props::PropertyTraits<T>: | ||||
:Internal> | ||||
::type* dummy = 0) const; | ||||
// Getter for extended property | ||||
template<typename T> | ||||
T getValue(typename boost::disable_if_c<simgear::props::PropertyTraits<T> | ||||
::Internal> | ||||
::type* dummy = 0) const; | ||||
/** | ||||
* Get a list of values from all children with the given name | ||||
*/ | ||||
template<typename T, typename T_get /* = T */> // TODO use C++11 or trait | ||||
s | ||||
std::vector<T> getChildValues(const std::string& name) const; | ||||
/** | ||||
* Get a list of values from all children with the given name | ||||
*/ | ||||
template<typename T> | ||||
std::vector<T> getChildValues(const std::string& name) const; | ||||
/** | ||||
* Set a bool value for this node. | * Set a bool value for this node. | |||
*/ | */ | |||
bool setBoolValue (bool value); | bool setBoolValue (bool value); | |||
/** | /** | |||
* Set an int value for this node. | * Set an int value for this node. | |||
*/ | */ | |||
bool setIntValue (int value); | bool setIntValue (int value); | |||
/** | /** | |||
skipping to change at line 806 | skipping to change at line 1158 | |||
* Set a double value for this node. | * Set a double value for this node. | |||
*/ | */ | |||
bool setDoubleValue (double value); | bool setDoubleValue (double value); | |||
/** | /** | |||
* Set a string value for this node. | * Set a string value for this node. | |||
*/ | */ | |||
bool setStringValue (const char * value); | bool setStringValue (const char * value); | |||
/** | /** | |||
* Set a string value for this node. | ||||
*/ | ||||
bool setStringValue (const std::string& value) | ||||
{ return setStringValue(value.c_str()); } | ||||
/** | ||||
* Set a value of unspecified type for this node. | * Set a value of unspecified type for this node. | |||
*/ | */ | |||
bool setUnspecifiedValue (const char * value); | bool setUnspecifiedValue (const char * value); | |||
// | template<typename T> | |||
// Data binding. | bool setValue(const T& val, | |||
// | typename boost::enable_if_c<simgear::props::PropertyTraits< | |||
T>::Internal> | ||||
::type* dummy = 0); | ||||
template<typename T> | ||||
bool setValue(const T& val, | ||||
typename boost::disable_if_c<simgear::props::PropertyTraits | ||||
<T>::Internal> | ||||
::type* dummy = 0); | ||||
/** | template<int N> | |||
* Test whether this node is bound to an external data source. | bool setValue(const char (&val)[N]) | |||
*/ | { | |||
bool isTied () const { return _tied; } | return setValue(&val[0]); | |||
} | ||||
/** | /** | |||
* Bind this node to an external bool source. | * Interpolate current value to target value within given time. | |||
*/ | * | |||
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true); | * @param type Type of interpolation ("numeric", "color", etc.) | |||
* @param target Node containing target value | ||||
* @param duration Duration of interpolation (in seconds) | ||||
* @param easing Easing function (http://easings.net/) | ||||
*/ | ||||
bool interpolate( const std::string& type, | ||||
const SGPropertyNode& target, | ||||
double duration = 0.6, | ||||
const std::string& easing = "swing" ); | ||||
/** | /** | |||
* Bind this node to an external int source. | * Interpolate current value to a series of values within given durations | |||
. | ||||
* | ||||
* @param type Type of interpolation ("numeric", "color", etc.) | ||||
* @param values Nodes containing intermediate and target values | ||||
* @param duration Durations for each interpolation step (in seconds) | ||||
* @param easing Easing function (http://easings.net/) | ||||
*/ | */ | |||
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true); | bool interpolate( const std::string& type, | |||
const simgear::PropertyList& values, | ||||
const double_list& deltas, | ||||
const std::string& easing = "swing" ); | ||||
/** | /** | |||
* Bind this node to an external long int source. | * Set the interpolation manager used by the interpolate methods. | |||
*/ | */ | |||
bool tie (const SGRawValue<long> &rawValue, bool useDefault = true); | static void setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr); | |||
/** | /** | |||
* Bind this node to an external float source. | * Print the value of the property to a stream. | |||
*/ | */ | |||
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true); | std::ostream& printOn(std::ostream& stream) const; | |||
/** | // | |||
* Bind this node to an external double source. | // Data binding. | |||
*/ | // | |||
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true); | ||||
/** | /** | |||
* Bind this node to an external string source. | * Test whether this node is bound to an external data source. | |||
*/ | */ | |||
bool tie (const SGRawValue<const char *> &rawValue, bool useDefault = tru | bool isTied () const { return _tied; } | |||
e); | ||||
/** | ||||
* Bind this node to an external source. | ||||
*/ | ||||
template<typename T> | ||||
bool tie(const SGRawValue<T> &rawValue, bool useDefault = true); | ||||
/** | /** | |||
* Unbind this node from any external data source. | * Unbind this node from any external data source. | |||
*/ | */ | |||
bool untie (); | bool untie (); | |||
// | // | |||
// Convenience methods using paths. | // Convenience methods using paths. | |||
// TODO: add attribute methods | // TODO: add attribute methods | |||
// | // | |||
/** | /** | |||
* Get another node's type. | * Get another node's type. | |||
*/ | */ | |||
Type getType (const char * relative_path) const; | simgear::props::Type getType (const char * relative_path) const; | |||
/** | ||||
* Get another node's type. | ||||
*/ | ||||
simgear::props::Type getType (const std::string& relative_path) const | ||||
{ return getType(relative_path.c_str()); } | ||||
/** | /** | |||
* Test whether another node has a leaf value. | * Test whether another node has a leaf value. | |||
*/ | */ | |||
bool hasValue (const char * relative_path) const; | bool hasValue (const char * relative_path) const; | |||
/** | /** | |||
* Test whether another node has a leaf value. | ||||
*/ | ||||
bool hasValue (const std::string& relative_path) const | ||||
{ return hasValue(relative_path.c_str()); } | ||||
/** | ||||
* Get another node's value as a bool. | * Get another node's value as a bool. | |||
*/ | */ | |||
bool getBoolValue (const char * relative_path, | bool getBoolValue (const char * relative_path, | |||
bool defaultValue = false) const; | bool defaultValue = false) const; | |||
/** | /** | |||
* Get another node's value as a bool. | ||||
*/ | ||||
bool getBoolValue (const std::string& relative_path, | ||||
bool defaultValue = false) const | ||||
{ return getBoolValue(relative_path.c_str(), defaultValue); } | ||||
/** | ||||
* Get another node's value as an int. | * Get another node's value as an int. | |||
*/ | */ | |||
int getIntValue (const char * relative_path, | int getIntValue (const char * relative_path, | |||
int defaultValue = 0) const; | int defaultValue = 0) const; | |||
/** | /** | |||
* Get another node's value as an int. | ||||
*/ | ||||
int getIntValue (const std::string& relative_path, | ||||
int defaultValue = 0) const | ||||
{ return getIntValue(relative_path.c_str(), defaultValue); } | ||||
/** | ||||
* Get another node's value as a long int. | * Get another node's value as a long int. | |||
*/ | */ | |||
long getLongValue (const char * relative_path, | long getLongValue (const char * relative_path, | |||
long defaultValue = 0L) const; | long defaultValue = 0L) const; | |||
/** | /** | |||
* Get another node's value as a long int. | ||||
*/ | ||||
long getLongValue (const std::string& relative_path, | ||||
long defaultValue = 0L) const | ||||
{ return getLongValue(relative_path.c_str(), defaultValue); } | ||||
/** | ||||
* Get another node's value as a float. | * Get another node's value as a float. | |||
*/ | */ | |||
float getFloatValue (const char * relative_path, | float getFloatValue (const char * relative_path, | |||
float defaultValue = 0.0) const; | float defaultValue = 0.0f) const; | |||
/** | ||||
* Get another node's value as a float. | ||||
*/ | ||||
float getFloatValue (const std::string& relative_path, | ||||
float defaultValue = 0.0f) const | ||||
{ return getFloatValue(relative_path.c_str(), defaultValue); } | ||||
/** | /** | |||
* Get another node's value as a double. | * Get another node's value as a double. | |||
*/ | */ | |||
double getDoubleValue (const char * relative_path, | double getDoubleValue (const char * relative_path, | |||
double defaultValue = 0.0L) const; | double defaultValue = 0.0) const; | |||
/** | ||||
* Get another node's value as a double. | ||||
*/ | ||||
double getDoubleValue (const std::string& relative_path, | ||||
double defaultValue = 0.0) const | ||||
{ return getDoubleValue(relative_path.c_str(), defaultValue); } | ||||
/** | /** | |||
* Get another node's value as a string. | * Get another node's value as a string. | |||
*/ | */ | |||
const char * getStringValue (const char * relative_path, | const char * getStringValue (const char * relative_path, | |||
const char * defaultValue = "") const; | const char * defaultValue = "") const; | |||
/** | /** | |||
* Get another node's value as a string. | ||||
*/ | ||||
const char * getStringValue (const std::string& relative_path, | ||||
const char * defaultValue = "") const | ||||
{ return getStringValue(relative_path.c_str(), defaultValue); } | ||||
/** | ||||
* Set another node's value as a bool. | * Set another node's value as a bool. | |||
*/ | */ | |||
bool setBoolValue (const char * relative_path, bool value); | bool setBoolValue (const char * relative_path, bool value); | |||
/** | /** | |||
* Set another node's value as a bool. | ||||
*/ | ||||
bool setBoolValue (const std::string& relative_path, bool value) | ||||
{ return setBoolValue(relative_path.c_str(), value); } | ||||
/** | ||||
* Set another node's value as an int. | * Set another node's value as an int. | |||
*/ | */ | |||
bool setIntValue (const char * relative_path, int value); | bool setIntValue (const char * relative_path, int value); | |||
/** | /** | |||
* Set another node's value as an int. | ||||
*/ | ||||
bool setIntValue (const std::string& relative_path, int value) | ||||
{ return setIntValue(relative_path.c_str(), value); } | ||||
/** | ||||
* Set another node's value as a long int. | * Set another node's value as a long int. | |||
*/ | */ | |||
bool setLongValue (const char * relative_path, long value); | bool setLongValue (const char * relative_path, long value); | |||
/** | /** | |||
* Set another node's value as a long int. | ||||
*/ | ||||
bool setLongValue (const std::string& relative_path, long value) | ||||
{ return setLongValue(relative_path.c_str(), value); } | ||||
/** | ||||
* Set another node's value as a float. | * Set another node's value as a float. | |||
*/ | */ | |||
bool setFloatValue (const char * relative_path, float value); | bool setFloatValue (const char * relative_path, float value); | |||
/** | /** | |||
* Set another node's value as a float. | ||||
*/ | ||||
bool setFloatValue (const std::string& relative_path, float value) | ||||
{ return setFloatValue(relative_path.c_str(), value); } | ||||
/** | ||||
* Set another node's value as a double. | * Set another node's value as a double. | |||
*/ | */ | |||
bool setDoubleValue (const char * relative_path, double value); | bool setDoubleValue (const char * relative_path, double value); | |||
/** | /** | |||
* Set another node's value as a double. | ||||
*/ | ||||
bool setDoubleValue (const std::string& relative_path, double value) | ||||
{ return setDoubleValue(relative_path.c_str(), value); } | ||||
/** | ||||
* Set another node's value as a string. | * Set another node's value as a string. | |||
*/ | */ | |||
bool setStringValue (const char * relative_path, const char * value); | bool setStringValue (const char * relative_path, const char * value); | |||
bool setStringValue(const char * relative_path, const std::string& value) | ||||
{ return setStringValue(relative_path, value.c_str()); } | ||||
/** | ||||
* Set another node's value as a string. | ||||
*/ | ||||
bool setStringValue (const std::string& relative_path, const char * value | ||||
) | ||||
{ return setStringValue(relative_path.c_str(), value); } | ||||
bool setStringValue (const std::string& relative_path, | ||||
const std::string& value) | ||||
{ return setStringValue(relative_path.c_str(), value.c_str()); } | ||||
/** | /** | |||
* Set another node's value with no specified type. | * Set another node's value with no specified type. | |||
*/ | */ | |||
bool setUnspecifiedValue (const char * relative_path, const char * value) ; | bool setUnspecifiedValue (const char * relative_path, const char * value) ; | |||
/** | /** | |||
* Test whether another node is bound to an external data source. | * Test whether another node is bound to an external data source. | |||
*/ | */ | |||
bool isTied (const char * relative_path) const; | bool isTied (const char * relative_path) const; | |||
/** | /** | |||
* Test whether another node is bound to an external data source. | ||||
*/ | ||||
bool isTied (const std::string& relative_path) const | ||||
{ return isTied(relative_path.c_str()); } | ||||
/** | ||||
* Bind another node to an external bool source. | * Bind another node to an external bool source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<bool> &rawValue, | bool tie (const char * relative_path, const SGRawValue<bool> &rawValue, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external bool source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<bool> &rawVa | ||||
lue, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Bind another node to an external int source. | * Bind another node to an external int source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<int> &rawValue, | bool tie (const char * relative_path, const SGRawValue<int> &rawValue, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external int source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<int> &rawVal | ||||
ue, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Bind another node to an external long int source. | * Bind another node to an external long int source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<long> &rawValue, | bool tie (const char * relative_path, const SGRawValue<long> &rawValue, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external long int source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<long> &rawVa | ||||
lue, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Bind another node to an external float source. | * Bind another node to an external float source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<float> &rawValue, | bool tie (const char * relative_path, const SGRawValue<float> &rawValue, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external float source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<float> &rawV | ||||
alue, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Bind another node to an external double source. | * Bind another node to an external double source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<double> &rawValue, | bool tie (const char * relative_path, const SGRawValue<double> &rawValue, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external double source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<double> &raw | ||||
Value, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Bind another node to an external string source. | * Bind another node to an external string source. | |||
*/ | */ | |||
bool tie (const char * relative_path, const SGRawValue<const char *> &raw Value, | bool tie (const char * relative_path, const SGRawValue<const char *> &raw Value, | |||
bool useDefault = true); | bool useDefault = true); | |||
/** | /** | |||
* Bind another node to an external string source. | ||||
*/ | ||||
bool tie (const std::string& relative_path, const SGRawValue<const char*> | ||||
&rawValue, | ||||
bool useDefault = true) | ||||
{ return tie(relative_path.c_str(), rawValue, useDefault); } | ||||
/** | ||||
* Unbind another node from any external data source. | * Unbind another node from any external data source. | |||
*/ | */ | |||
bool untie (const char * relative_path); | bool untie (const char * relative_path); | |||
/** | /** | |||
* Unbind another node from any external data source. | ||||
*/ | ||||
bool untie (const std::string& relative_path) | ||||
{ return untie(relative_path.c_str()); } | ||||
/** | ||||
* Add a change listener to the property. If "initial" is set call the | * Add a change listener to the property. If "initial" is set call the | |||
* listener initially. | * listener initially. | |||
*/ | */ | |||
void addChangeListener (SGPropertyChangeListener * listener, | void addChangeListener (SGPropertyChangeListener * listener, | |||
bool initial = false); | bool initial = false); | |||
/** | /** | |||
* Remove a change listener from the property. | * Remove a change listener from the property. | |||
*/ | */ | |||
void removeChangeListener (SGPropertyChangeListener * listener); | void removeChangeListener (SGPropertyChangeListener * listener); | |||
/** | /** | |||
* Get the number of listeners. | * Get the number of listeners. | |||
*/ | */ | |||
int nListeners () const { return _listeners ? _listeners->size() : 0; } | int nListeners () const { return _listeners ? (int)_listeners->size() : 0 ; } | |||
/** | /** | |||
* Fire a value change event to all listeners. | * Fire a value change event to all listeners. | |||
*/ | */ | |||
void fireValueChanged (); | void fireValueChanged (); | |||
/** | /** | |||
* Fire a child-added event to all listeners. | * Fire a child-added event to all listeners. | |||
*/ | */ | |||
void fireChildAdded (SGPropertyNode * child); | void fireChildAdded (SGPropertyNode * child); | |||
/** | /** | |||
* Trigger a child-added and value-changed event for every child (Unlimit | ||||
ed | ||||
* depth). | ||||
* | ||||
* @param fire_self Whether to trigger the events also for the node its | ||||
elf. | ||||
* | ||||
* It can be used to simulating the creation of a property tree, eg. for | ||||
* (re)initializing a subsystem which is controlled through the property | ||||
tree. | ||||
*/ | ||||
void fireCreatedRecursive(bool fire_self = false); | ||||
/** | ||||
* Fire a child-removed event to all listeners. | * Fire a child-removed event to all listeners. | |||
*/ | */ | |||
void fireChildRemoved (SGPropertyNode * child); | void fireChildRemoved (SGPropertyNode * child); | |||
/** | /** | |||
* Fire a child-removed event for every child of this node (Unlimited dep | ||||
th) | ||||
* | ||||
* Upon removal of a child node only for this single node a child-removed | ||||
* event is triggered. If eg. resource cleanup relies on receiving a | ||||
* child-removed event for every child this method can be used. | ||||
*/ | ||||
void fireChildrenRemovedRecursive(); | ||||
/** | ||||
* Clear any existing value and set the type to NONE. | * Clear any existing value and set the type to NONE. | |||
*/ | */ | |||
void clearValue (); | void clearValue (); | |||
/** | ||||
* Compare two property trees. The property trees are equal if: 1) | ||||
* They have no children, and have the same type and the values are | ||||
* equal, or 2) have the same number of children, and the | ||||
* corresponding children in each tree are equal. "corresponding" | ||||
* means have the same name and index. | ||||
* | ||||
* Attributes, removed children, and aliases aren't considered. | ||||
*/ | ||||
static bool compare (const SGPropertyNode& lhs, const SGPropertyNode& rhs | ||||
); | ||||
protected: | protected: | |||
void fireValueChanged (SGPropertyNode * node); | void fireValueChanged (SGPropertyNode * node); | |||
void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child); | void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child); | |||
void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child); | void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child); | |||
/** | /** | |||
* Protected constructor for making new nodes on demand. | * Protected constructor for making new nodes on demand. | |||
*/ | */ | |||
SGPropertyNode (const char * name, int index, SGPropertyNode * parent); | SGPropertyNode (const std::string& name, int index, SGPropertyNode * pare | |||
nt); | ||||
template<typename Itr> | ||||
SGPropertyNode (Itr begin, Itr end, int index, SGPropertyNode * parent); | ||||
static simgear::PropertyInterpolationMgr* _interpolation_mgr; | ||||
private: | private: | |||
// Get the raw value | // Get the raw value | |||
bool get_bool () const; | bool get_bool () const; | |||
int get_int () const; | int get_int () const; | |||
long get_long () const; | long get_long () const; | |||
float get_float () const; | float get_float () const; | |||
double get_double () const; | double get_double () const; | |||
const char * get_string () const; | const char * get_string () const; | |||
// Set the raw value | // Set the raw value | |||
bool set_bool (bool value); | bool set_bool (bool value); | |||
bool set_int (int value); | bool set_int (int value); | |||
bool set_long (long value); | bool set_long (long value); | |||
bool set_float (float value); | bool set_float (float value); | |||
bool set_double (double value); | bool set_double (double value); | |||
bool set_string (const char * value); | bool set_string (const char * value); | |||
/** | /** | |||
* Get the value as a string. | * Get the value as a string. | |||
*/ | */ | |||
skipping to change at line 1067 | skipping to change at line 1638 | |||
/** | /** | |||
* Trace a read access. | * Trace a read access. | |||
*/ | */ | |||
void trace_read () const; | void trace_read () const; | |||
/** | /** | |||
* Trace a write access. | * Trace a write access. | |||
*/ | */ | |||
void trace_write () const; | void trace_write () const; | |||
/** | ||||
* Remove this node from all nodes that link to it in their path cache. | ||||
*/ | ||||
void remove_from_path_caches(); | ||||
class hash_table; | ||||
int _index; | int _index; | |||
string _name; | std::string _name; | |||
mutable string _display_name; | ||||
/// To avoid cyclic reference counting loops this shall not be a referenc e | /// To avoid cyclic reference counting loops this shall not be a referenc e | |||
/// counted pointer | /// counted pointer | |||
SGPropertyNode * _parent; | SGPropertyNode * _parent; | |||
vector<SGPropertyNode_ptr> _children; | simgear::PropertyList _children; | |||
vector<SGPropertyNode_ptr> _removedChildren; | simgear::PropertyList _removedChildren; | |||
vector<hash_table *> _linkedNodes; | mutable std::string _buffer; | |||
mutable string _path; | simgear::props::Type _type; | |||
mutable string _buffer; | ||||
hash_table * _path_cache; | ||||
Type _type; | ||||
bool _tied; | bool _tied; | |||
int _attr; | int _attr; | |||
// The right kind of pointer... | // The right kind of pointer... | |||
union { | union { | |||
SGPropertyNode * alias; | SGPropertyNode * alias; | |||
SGRawValue<bool> * bool_val; | SGRaw* val; | |||
SGRawValue<int> * int_val; | ||||
SGRawValue<long> * long_val; | ||||
SGRawValue<float> * float_val; | ||||
SGRawValue<double> * double_val; | ||||
SGRawValue<const char *> * string_val; | ||||
} _value; | } _value; | |||
union { | union { | |||
bool bool_val; | bool bool_val; | |||
int int_val; | int int_val; | |||
long long_val; | long long_val; | |||
float float_val; | float float_val; | |||
double double_val; | double double_val; | |||
char * string_val; | char * string_val; | |||
} _local_val; | } _local_val; | |||
vector <SGPropertyChangeListener *> * _listeners; | std::vector<SGPropertyChangeListener *> * _listeners; | |||
/** | // Pass name as a pair of iterators | |||
* Register/unregister node that links to this node in its path cache. | template<typename Itr> | |||
*/ | SGPropertyNode * getChildImpl (Itr begin, Itr end, int index = 0, bool cr | |||
void add_linked_node (hash_table * node) { _linkedNodes.push_back(node); | eate = false); | |||
} | // very internal method | |||
bool remove_linked_node (hash_table * node); | template<typename Itr> | |||
/** | SGPropertyNode* getExistingChild (Itr begin, Itr end, int index, bool cre | |||
* A very simple hash table. | ate); | |||
*/ | // very internal path parsing function | |||
class hash_table { | template<typename SplitItr> | |||
public: | friend SGPropertyNode* find_node_aux(SGPropertyNode * current, SplitItr& | |||
itr, | ||||
bool create, int last_index); | ||||
// For boost | ||||
friend size_t hash_value(const SGPropertyNode& node); | ||||
}; | ||||
/** | // Convenience functions for use in templates | |||
* An entry in a bucket in a hash table. | template<typename T> | |||
*/ | T getValue(const SGPropertyNode*); | |||
class entry { | ||||
public: | ||||
entry (); | ||||
~entry (); | ||||
const char * get_key () { return _key.c_str(); } | ||||
void set_key (const char * key); | ||||
SGPropertyNode * get_value () { return _value; } | ||||
void set_value (SGPropertyNode * value); | ||||
private: | ||||
string _key; | ||||
SGSharedPtr<SGPropertyNode> _value; | ||||
}; | ||||
/** | template<> | |||
* A bucket in a hash table. | inline bool getValue<bool>(const SGPropertyNode* node) { return node->getBo | |||
*/ | olValue(); } | |||
class bucket { | ||||
public: | template<> | |||
bucket (); | inline int getValue<int>(const SGPropertyNode* node) { return node->getIntV | |||
~bucket (); | alue(); } | |||
entry * get_entry (const char * key, bool create = false); | ||||
bool erase (SGPropertyNode * node); | template<> | |||
void clear (hash_table * owner); | inline long getValue<long>(const SGPropertyNode* node) { return node->getLo | |||
private: | ngValue(); } | |||
int _length; | ||||
entry ** _entries; | template<> | |||
}; | inline float getValue<float>(const SGPropertyNode* node) | |||
{ | ||||
friend class bucket; | return node->getFloatValue(); | |||
} | ||||
hash_table (); | ||||
~hash_table (); | template<> | |||
SGPropertyNode * get (const char * key); | inline double getValue<double>(const SGPropertyNode* node) | |||
void put (const char * key, SGPropertyNode * value); | { | |||
bool erase (SGPropertyNode * node); | return node->getDoubleValue(); | |||
} | ||||
private: | ||||
unsigned int hashcode (const char * key); | template<> | |||
unsigned int _data_length; | inline const char * getValue<const char*>(const SGPropertyNode* node) | |||
bucket ** _data; | { | |||
}; | return node->getStringValue (); | |||
} | ||||
template<> | ||||
inline std::string getValue<std::string>(const SGPropertyNode* node) | ||||
{ | ||||
return node->getStringValue(); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, bool value) | ||||
{ | ||||
return node->setBoolValue(value); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, int value) | ||||
{ | ||||
return node->setIntValue(value); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, long value) | ||||
{ | ||||
return node->setLongValue(value); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, float value) | ||||
{ | ||||
return node->setFloatValue(value); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, double value) | ||||
{ | ||||
return node->setDoubleValue(value); | ||||
} | ||||
inline bool setValue(SGPropertyNode* node, const char* value) | ||||
{ | ||||
return node->setStringValue(value); | ||||
} | ||||
inline bool setValue (SGPropertyNode* node, const std::string& value) | ||||
{ | ||||
return node->setStringValue(value.c_str()); | ||||
} | ||||
template<typename T> | ||||
bool SGPropertyNode::tie(const SGRawValue<T> &rawValue, bool useDefault) | ||||
{ | ||||
using namespace simgear::props; | ||||
if (_type == ALIAS || _tied) | ||||
return false; | ||||
useDefault = useDefault && hasValue(); | ||||
T old_val = SGRawValue<T>::DefaultValue(); | ||||
if (useDefault) | ||||
old_val = getValue<T>(this); | ||||
clearValue(); | ||||
if (PropertyTraits<T>::Internal) | ||||
_type = PropertyTraits<T>::type_tag; | ||||
else | ||||
_type = EXTENDED; | ||||
_tied = true; | ||||
_value.val = rawValue.clone(); | ||||
if (useDefault) { | ||||
int save_attributes = getAttributes(); | ||||
setAttribute( WRITE, true ); | ||||
setValue(old_val); | ||||
setAttributes( save_attributes ); | ||||
} | ||||
return true; | ||||
} | ||||
template<> | ||||
bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, | ||||
bool useDefault); | ||||
template<typename T> | ||||
T SGPropertyNode::getValue(typename boost::disable_if_c<simgear::props | ||||
::PropertyTraits<T>::Internal>::type* dummy) con | ||||
st | ||||
{ | ||||
using namespace simgear::props; | ||||
if (_attr == (READ|WRITE) && _type == EXTENDED | ||||
&& _value.val->getType() == PropertyTraits<T>::type_tag) { | ||||
return static_cast<SGRawValue<T>*>(_value.val)->getValue(); | ||||
} | ||||
if (getAttribute(TRACE_READ)) | ||||
trace_read(); | ||||
if (!getAttribute(READ)) | ||||
return SGRawValue<T>::DefaultValue(); | ||||
switch (_type) { | ||||
case EXTENDED: | ||||
if (_value.val->getType() == PropertyTraits<T>::type_tag) | ||||
return static_cast<SGRawValue<T>*>(_value.val)->getValue(); | ||||
break; | ||||
case STRING: | ||||
case UNSPECIFIED: | ||||
return simgear::parseString<T>(make_string()); | ||||
break; | ||||
default: // avoid compiler warning | ||||
break; | ||||
} | ||||
return SGRawValue<T>::DefaultValue(); | ||||
} | ||||
template<typename T> | ||||
inline T SGPropertyNode::getValue(typename boost::enable_if_c<simgear::prop | ||||
s | ||||
::PropertyTraits<T>::Internal>::type* dum | ||||
my) const | ||||
{ | ||||
return ::getValue<T>(this); | ||||
} | ||||
template<typename T, typename T_get /* = T */> // TODO use C++11 or traits | ||||
std::vector<T> SGPropertyNode::getChildValues(const std::string& name) cons | ||||
t | ||||
{ | ||||
const simgear::PropertyList& props = getChildren(name); | ||||
std::vector<T> values( props.size() ); | ||||
for( size_t i = 0; i < props.size(); ++i ) | ||||
values[i] = props[i]->getValue<T_get>(); | ||||
return values; | ||||
} | ||||
template<typename T> | ||||
inline | ||||
std::vector<T> SGPropertyNode::getChildValues(const std::string& name) cons | ||||
t | ||||
{ | ||||
return getChildValues<T, T>(name); | ||||
} | ||||
template<typename T> | ||||
bool SGPropertyNode::setValue(const T& val, | ||||
typename boost::disable_if_c<simgear::props | ||||
::PropertyTraits<T>::Internal>::type* dummy) | ||||
{ | ||||
using namespace simgear::props; | ||||
if (_attr == (READ|WRITE) && _type == EXTENDED | ||||
&& _value.val->getType() == PropertyTraits<T>::type_tag) { | ||||
static_cast<SGRawValue<T>*>(_value.val)->setValue(val); | ||||
return true; | ||||
} | ||||
if (getAttribute(WRITE) | ||||
&& ((_type == EXTENDED | ||||
&& _value.val->getType() == PropertyTraits<T>::type_tag) | ||||
|| _type == NONE || _type == UNSPECIFIED)) { | ||||
if (_type == NONE || _type == UNSPECIFIED) { | ||||
clearValue(); | ||||
_type = EXTENDED; | ||||
_value.val = new SGRawValueContainer<T>(val); | ||||
} else { | ||||
static_cast<SGRawValue<T>*>(_value.val)->setValue(val); | ||||
} | ||||
if (getAttribute(TRACE_WRITE)) | ||||
trace_write(); | ||||
return true; | ||||
} | ||||
return false; | ||||
} | ||||
template<typename T> | ||||
inline bool SGPropertyNode::setValue(const T& val, | ||||
typename boost::enable_if_c<simgear::p | ||||
rops | ||||
::PropertyTraits<T>::Internal>::type* | ||||
dummy) | ||||
{ | ||||
return ::setValue(this, val); | ||||
} | ||||
/** | ||||
* Utility function for creation of a child property node. | ||||
*/ | ||||
inline SGPropertyNode* makeChild(SGPropertyNode* parent, const char* name, | ||||
int index = 0) | ||||
{ | ||||
return parent->getChild(name, index, true); | ||||
} | ||||
/** | ||||
* Utility function for creation of a child property node using a | ||||
* relative path. | ||||
*/ | ||||
namespace simgear | ||||
{ | ||||
template<typename StringType> | ||||
inline SGPropertyNode* makeNode(SGPropertyNode* parent, const StringType& n | ||||
ame) | ||||
{ | ||||
return parent->getNode(name, true); | ||||
} | ||||
} | ||||
// For boost::hash | ||||
size_t hash_value(const SGPropertyNode& node); | ||||
// Helper comparison and hash functions for common cases | ||||
namespace simgear | ||||
{ | ||||
namespace props | ||||
{ | ||||
struct Compare | ||||
{ | ||||
bool operator()(const SGPropertyNode* lhs, const SGPropertyNode* rhs) c | ||||
onst | ||||
{ | ||||
return SGPropertyNode::compare(*lhs, *rhs); | ||||
} | ||||
bool operator()(SGPropertyNode_ptr lhs, const SGPropertyNode* rhs) cons | ||||
t | ||||
{ | ||||
return SGPropertyNode::compare(*lhs, *rhs); | ||||
} | ||||
bool operator()(const SGPropertyNode* lhs, SGPropertyNode_ptr rhs) cons | ||||
t | ||||
{ | ||||
return SGPropertyNode::compare(*lhs, *rhs); | ||||
} | ||||
bool operator()(SGPropertyNode_ptr lhs, SGPropertyNode_ptr rhs) const | ||||
{ | ||||
return SGPropertyNode::compare(*lhs, *rhs); | ||||
} | ||||
}; | ||||
struct Hash | ||||
{ | ||||
size_t operator()(const SGPropertyNode* node) const | ||||
{ | ||||
return hash_value(*node); | ||||
} | ||||
size_t operator()(SGPropertyNode_ptr node) const | ||||
{ | ||||
return hash_value(*node); | ||||
} | ||||
}; | ||||
} | ||||
} | ||||
/** Convenience class for change listener callbacks without | ||||
* creating a derived class implementing a "valueChanged" method. | ||||
* Also removes listener on destruction automatically. | ||||
*/ | ||||
template<class T> | ||||
class SGPropertyChangeCallback | ||||
: public SGPropertyChangeListener | ||||
{ | ||||
public: | ||||
SGPropertyChangeCallback(T* obj, void (T::*method)(SGPropertyNode*), | ||||
SGPropertyNode_ptr property,bool initial=false | ||||
) | ||||
: _obj(obj), _callback(method), _property(property) | ||||
{ | ||||
_property->addChangeListener(this,initial); | ||||
} | ||||
virtual ~SGPropertyChangeCallback() | ||||
{ | ||||
_property->removeChangeListener(this); | ||||
} | ||||
void valueChanged (SGPropertyNode * node) | ||||
{ | ||||
(_obj->*_callback)(node); | ||||
} | ||||
private: | ||||
T* _obj; | ||||
void (T::*_callback)(SGPropertyNode*); | ||||
SGPropertyNode_ptr _property; | ||||
}; | }; | |||
#endif // __PROPS_HXX | #endif // __PROPS_HXX | |||
// end of props.hxx | // end of props.hxx | |||
End of changes. 105 change blocks. | ||||
181 lines changed or deleted | 1021 lines changed or added | |||
props_io.hxx | props_io.hxx | |||
---|---|---|---|---|
/** | /** | |||
* \file props_io.hxx | * \file props_io.hxx | |||
* Interface definition for property list io. | * Interface definition for property list io. | |||
* Started Fall 2000 by David Megginson, david@megginson.com | * Started Fall 2000 by David Megginson, david@megginson.com | |||
* This code is released into the Public Domain. | * This code is released into the Public Domain. | |||
* | * | |||
* See props.html for documentation [replace with URL when available]. | * See props.html for documentation [replace with URL when available]. | |||
* | * | |||
* $Id: props_io.hxx,v 1.3 2005-12-17 15:11:37 ehofman Exp $ | * $Id$ | |||
*/ | */ | |||
#ifndef __PROPS_IO_HXX | #ifndef __PROPS_IO_HXX | |||
#define __PROPS_IO_HXX | #define __PROPS_IO_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <stdio.h> | #include <string> | |||
#include <iosfwd> | ||||
#include STL_STRING | ||||
#include <vector> | ||||
#include <map> | ||||
#include STL_IOSTREAM | ||||
SG_USING_STD(string); | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(map); | ||||
SG_USING_STD(istream); | ||||
SG_USING_STD(ostream); | ||||
/** | /** | |||
* Read properties from an XML input stream. | * Read properties from an XML input stream. | |||
*/ | */ | |||
void readProperties (istream &input, SGPropertyNode * start_node, | void readProperties (std::istream &input, SGPropertyNode * start_node, | |||
const string &base = "", int default_mode = 0); | const std::string &base = "", int default_mode = 0, | |||
bool extended = false); | ||||
/** | /** | |||
* Read properties from an XML file. | * Read properties from an XML file. | |||
*/ | */ | |||
void readProperties (const string &file, SGPropertyNode * start_node, | void readProperties (const std::string &file, SGPropertyNode * start_node, | |||
int default_mode = 0); | int default_mode = 0, bool extended = false); | |||
/** | /** | |||
* Read properties from an in-memory buffer. | * Read properties from an in-memory buffer. | |||
*/ | */ | |||
void readProperties (const char *buf, const int size, | void readProperties (const char *buf, const int size, | |||
SGPropertyNode * start_node, int default_mode = 0); | SGPropertyNode * start_node, int default_mode = 0, | |||
bool extended = false); | ||||
/** | /** | |||
* Write properties to an XML output stream. | * Write properties to an XML output stream. | |||
*/ | */ | |||
void writeProperties (ostream &output, const SGPropertyNode * start_node, | void writeProperties (std::ostream &output, const SGPropertyNode * start_no de, | |||
bool write_all = false, | bool write_all = false, | |||
SGPropertyNode::Attribute archive_flag = SGPropertyNod e::ARCHIVE); | SGPropertyNode::Attribute archive_flag = SGPropertyNod e::ARCHIVE); | |||
/** | /** | |||
* Write properties to an XML file. | * Write properties to an XML file. | |||
*/ | */ | |||
void writeProperties (const string &file, const SGPropertyNode * start_node | void writeProperties (const std::string &file, | |||
, | const SGPropertyNode * start_node, | |||
bool write_all = false, | bool write_all = false, | |||
SGPropertyNode::Attribute archive_flag = SGPropertyNod e::ARCHIVE); | SGPropertyNode::Attribute archive_flag = SGPropertyNod e::ARCHIVE); | |||
/** | /** | |||
* Copy properties from one node to another. | * Copy properties from one node to another. | |||
*/ | */ | |||
bool copyProperties (const SGPropertyNode *in, SGPropertyNode *out); | bool copyProperties (const SGPropertyNode *in, SGPropertyNode *out, | |||
int attr_value=0, int attr_mask=0); | ||||
#endif // __PROPS_IO_HXX | #endif // __PROPS_IO_HXX | |||
// end of props_io.hxx | // end of props_io.hxx | |||
End of changes. 8 change blocks. | ||||
22 lines changed or deleted | 15 lines changed or added | |||
pt_lights.hxx | pt_lights.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: pt_lights.hxx,v 1.9 2006-07-21 15:45:01 curt Exp $ | // $Id$ | |||
#ifndef _SG_PT_LIGHTS_HXX | #ifndef _SG_PT_LIGHTS_HXX | |||
#define _SG_PT_LIGHTS_HXX | #define _SG_PT_LIGHTS_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <vector> // STL | #include <vector> // STL | |||
#include <plib/sg.h> | #include <osg/Drawable> | |||
#include <plib/ssg.h> // plib include | #include <osg/Node> | |||
#include <osg/Point> | ||||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
#include <simgear/scene/material/matlib.hxx> | #include <simgear/scene/material/matlib.hxx> | |||
#include <simgear/scene/util/SGSceneFeatures.hxx> | ||||
SG_USING_STD(string); | #include "SGLightBin.hxx" | |||
SG_USING_STD(vector); | #include "SGDirectionalLightBin.hxx" | |||
typedef vector < int > int_list; | namespace simgear | |||
typedef int_list::iterator int_list_iterator; | { | |||
typedef int_list::const_iterator int_point_list_iterator; | class Effect; | |||
} | ||||
// Generate a directional light. This routines creates a | ||||
// 'directional' light that can only be viewed from within 90 degrees | ||||
// of the specified dir vector. | ||||
// To accomplish this, he routine creates a triangle with the 1st | ||||
// point coincident with the specified pt and the 2nd and 3rd points | ||||
// extending upward. The 1st point is created with an 'alpha' value | ||||
// of 1 while the 2nd and 3rd points are created with an 'alpha' of | ||||
// 0.0. | ||||
// If the triangle is drawn in glPolygonMode(GL_FRONT, GL_POINT) mode, | ||||
// then two important things happen: | ||||
// 1) Only the 3 vertex points are drawn, the 2nd two with an alpha of | ||||
// 0 so actually only the desired point is rendered. | ||||
// 2) since we are drawing a triangle, back face culling takes care of | ||||
// eliminating this poing when the view angle relative to dir is | ||||
// greater than 90 degrees. | ||||
// The final piece of this puzzle is that if we now use environment | ||||
// mapping on this point, via an appropriate texture we can then | ||||
// control the intensity and color of the point based on the view | ||||
// angle relative to 'dir' the optimal view direction of the light | ||||
// (i.e. the direction the light is pointing.) | ||||
// Yes this get's to be long and convoluted. If you can suggest a | ||||
// simpler way, please do! :-) | ||||
ssgLeaf *sgMakeDirectionalLight( sgVec3 pt, sgVec3 dir, sgVec3 up ); | ||||
ssgBranch *sgMakeDirectionalLights( const point_list &nodes, | ||||
const point_list &normals, | ||||
const int_list &pnt_i, | ||||
const int_list &nml_i, | ||||
SGMaterialLib *matlib, | ||||
const string &material, | ||||
sgdVec3 dup ); | ||||
// Specify the way we want to draw directional point lights (assuming the | // Specify the way we want to draw directional point lights (assuming the | |||
// appropriate extensions are available.) | // appropriate extensions are available.) | |||
void sgConfigureDirectionalLights( bool use_point_sprites, | inline void SGConfigureDirectionalLights( bool use_point_sprites, | |||
bool enhanced_lighting, | bool enhanced_lighting, | |||
bool distance_attenuation ); | bool distance_attenuation ) { | |||
static SGSceneFeatures* sceneFeatures = SGSceneFeatures::instance(); | ||||
sceneFeatures->setEnablePointSpriteLights(use_point_sprites); | ||||
sceneFeatures->setEnableDistanceAttenuationLights(distance_attenuation); | ||||
} | ||||
class SGLightFactory { | ||||
public: | ||||
static osg::Drawable* | ||||
getLightDrawable(const SGLightBin::Light& light); | ||||
static osg::Drawable* | ||||
getLightDrawable(const SGDirectionalLightBin::Light& light); | ||||
/** | ||||
* Return a drawable for a very simple point light that isn't | ||||
* distance scaled. | ||||
*/ | ||||
static osg::Drawable* | ||||
getLights(const SGLightBin& lights, unsigned inc = 1, float alphaOff = 0) | ||||
; | ||||
static osg::Drawable* | ||||
getLights(const SGDirectionalLightBin& lights); | ||||
static osg::Drawable* | ||||
getVasi(const SGVec3f& up, const SGDirectionalLightBin& lights, | ||||
const SGVec4f& red, const SGVec4f& white); | ||||
static osg::Node* | ||||
getSequenced(const SGDirectionalLightBin& lights); | ||||
static osg::Node* | ||||
getOdal(const SGLightBin& lights); | ||||
static osg::Node* | ||||
getHoldShort(const SGDirectionalLightBin& lights); | ||||
static osg::Node* | ||||
getGuard(const SGDirectionalLightBin& lights); | ||||
}; | ||||
simgear::Effect* getLightEffect(float size, const osg::Vec3& attenuation, | ||||
float minSize, float maxSize, bool directio | ||||
nal); | ||||
#endif // _SG_PT_LIGHTS_HXX | #endif // _SG_PT_LIGHTS_HXX | |||
End of changes. 9 change blocks. | ||||
50 lines changed or deleted | 58 lines changed or added | |||
sample_openal.hxx | sample_openal.hxx | |||
---|---|---|---|---|
// sample.hxx -- Sound sample encapsulation class | // sample_openal.hxx -- Audio sample encapsulation class | |||
// | // | |||
// Written by Curtis Olson, started April 2004. | // Written by Curtis Olson, started April 2004. | |||
// Modified to match the new SoundSystem by Erik Hofman, October 2009 | ||||
// | // | |||
// Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt | // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt | |||
// Copyright (C) 2009 Erik Hofman <erik@ehofman.com> | ||||
// | // | |||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License as | // modify it under the terms of the GNU General Public License as | |||
// published by the Free Software Foundation; either version 2 of the | // published by the Free Software Foundation; either version 2 of the | |||
// License, or (at your option) any later version. | // License, or (at your option) any later version. | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software Foundation, | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 | // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
1, USA. | ||||
// | // | |||
// $Id: sample_openal.hxx,v 1.17.2.1 2007-07-07 18:37:58 mfranz Exp $ | // $Id$ | |||
/** | /** | |||
* \file sample.hxx | * \file audio sample.hxx | |||
* Provides a sound sample encapsulation | * Provides a audio sample encapsulation | |||
*/ | */ | |||
#ifndef _SG_SAMPLE_HXX | #ifndef _SG_SAMPLE_HXX | |||
#define _SG_SAMPLE_HXX 1 | #define _SG_SAMPLE_HXX 1 | |||
#ifndef __cplusplus | #include <string> | |||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | ||||
#include <simgear/debug/logstream.hxx> | ||||
#include <simgear/structure/SGReferenced.hxx> | #include <simgear/structure/SGReferenced.hxx> | |||
#include <simgear/structure/SGSharedPtr.hxx> | #include <simgear/structure/SGSharedPtr.hxx> | |||
#include <simgear/math/SGMath.hxx> | ||||
#include <plib/sg.h> | class SGPath; | |||
#if defined(__APPLE__) | #ifndef AL_FORMAT_MONO8 | |||
# define AL_ILLEGAL_ENUM AL_INVALID_ENUM | #define AL_FORMAT_MONO8 0x1100 | |||
# define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION | ||||
# include <OpenAL/al.h> | ||||
# include <OpenAL/alut.h> | ||||
#else | ||||
# include <AL/al.h> | ||||
# include <AL/alut.h> | ||||
#endif | #endif | |||
#ifndef HAVE_WINDOWS_H | ||||
#ifdef AL_VERSION_1_2 | ||||
#define USE_OPEN_AL_DOPPLER should work | ||||
#else | ||||
#define USE_OPEN_AL_DOPPLER_WITH_FIXED_LISTENER better than nothing | ||||
#endif | ||||
#else | ||||
//the Open_AL Doppler calculation seem to be buggy on windows | ||||
#define USE_SOFTWARE_DOPPLER seem to be necessary | ||||
#endif | ||||
SG_USING_STD(string); | ||||
/** | /** | |||
* manages everything we need to know for an individual sound sample | * manages everything we need to know for an individual audio sample | |||
*/ | */ | |||
class SGSoundSample : public SGReferenced { | class SGSoundSample : public SGReferenced { | |||
private: | ||||
string sample_name; | ||||
// Buffers hold sound data. | ||||
ALuint buffer; | ||||
// Sources are points emitting sound. | ||||
ALuint source; | ||||
// Position of the source sound. | ||||
ALfloat source_pos[3]; | ||||
// A constant offset to be applied to the final source_pos | ||||
ALfloat offset_pos[3]; | ||||
// The orientation of the sound (direction and cut-off angles) | ||||
ALfloat direction[3]; | ||||
ALfloat inner, outer, outergain; | ||||
// Velocity of the source sound. | ||||
ALfloat source_vel[3]; | ||||
// configuration values | ||||
ALenum format; | ||||
ALsizei size; | ||||
ALsizei freq; | ||||
double pitch; | ||||
double volume; | ||||
#ifdef USE_SOFTWARE_DOPPLER | ||||
double doppler_pitch_factor; | ||||
double doppler_volume_factor; | ||||
#endif | ||||
double reference_dist; | ||||
double max_dist; | ||||
ALboolean loop; | ||||
bool playing; | ||||
bool bind_source(); | ||||
bool no_Doppler_effect; | ||||
public: | public: | |||
/** | /** | |||
* Empty constructor, can be used to read data to the systems | * Empty constructor, can be used to read data to the systems | |||
* memory and not to the driver. | * memory and not to the driver. | |||
*/ | */ | |||
SGSoundSample(); | SGSoundSample(); | |||
/** | /** | |||
* Constructor | * Constructor | |||
* @param path Path name to sound | ||||
* @param file File name of sound | * @param file File name of sound | |||
should usually be true unless you want to manipulate the data | Buffer data is freed by the sample group | |||
later.) | ||||
*/ | */ | |||
SGSoundSample( const char *path, const char *file, bool no_Doppler_effe ct = true ); | SGSoundSample(const char *file, const SGPath& currentDir); | |||
/** | /** | |||
* Constructor. | * Constructor. | |||
* @param _data Pointer to a memory buffer containing the sample data | * @param data Pointer to a memory buffer containing this audio sample | |||
the application is responsible for freeing the buffer data. | data | |||
The application may free the data by calling free_data(), otherwise | ||||
it | ||||
will be resident until the class is destroyed. This pointer will be | ||||
set to NULL after calling this function. | ||||
* @param len Byte length of array | * @param len Byte length of array | |||
* @param _freq Frequency of the provided data (bytes per second) | * @param freq Frequency of the provided data (bytes per second) | |||
should usually be true unless you want to manipulate the data | * @param format OpenAL format id of the data | |||
later.) | */ | |||
SGSoundSample( void** data, int len, int freq, int format=AL_FORMAT_MON | ||||
O8 ); | ||||
SGSoundSample( const unsigned char** data, int len, int freq, | ||||
int format = AL_FORMAT_MONO8 ); | ||||
/** | ||||
* Destructor | ||||
*/ | ||||
virtual ~SGSoundSample (); | ||||
/** | ||||
* Detect whether this audio sample holds the information of a sound fi | ||||
le. | ||||
* @return Return true if this audio sample is to be constructed from a | ||||
file. | ||||
*/ | ||||
inline bool is_file() const { return _is_file; } | ||||
SGPath file_path() const; | ||||
/** | ||||
* Test if this audio sample configuration has changed since the last c | ||||
all. | ||||
* Calling this function will reset the flag so calling it a second | ||||
* time in a row will return false. | ||||
* @return Return true is the configuration has changed in the mean tim | ||||
e. | ||||
*/ | ||||
bool has_changed() { | ||||
bool b = _changed; _changed = false; return b; | ||||
} | ||||
/** | ||||
* Test if static data of audio sample configuration has changed. | ||||
* Calling this function will reset the flag so calling it a second | ||||
* time in a row will return false. | ||||
* @return Return true is the static data has changed in the mean time. | ||||
*/ | */ | |||
SGSoundSample( unsigned char *_data, int len, int _freq, bool no_Dopple | bool has_static_data_changed() { | |||
r_effect = true ); | bool b = _static_changed; _static_changed = false; return b; | |||
} | ||||
~SGSoundSample(); | /** | |||
* Schedule this audio sample for playing. Actual playing will only sta | ||||
rt | ||||
* at the next call op SoundGroup::update() | ||||
* @param _loop Define whether this sound should be played in a loop. | ||||
*/ | ||||
void play( bool loop = false ) { | ||||
_playing = true; _loop = loop; _changed = true; _static_changed = t | ||||
rue; | ||||
} | ||||
/** | /** | |||
* Start playing this sample. | * Check if this audio sample is set to be continuous looping. | |||
* | * @return Return true if this audio sample is set to looping. | |||
* @param _loop Define wether the sound should be played in a loop. | ||||
*/ | */ | |||
void play( bool _loop ); | inline bool is_looping() { return _loop; } | |||
/** | /** | |||
* Stop playing this sample. | * Schedule this audio sample to stop playing. | |||
* | ||||
* @param sched A pointer to the appropriate scheduler. | ||||
*/ | */ | |||
void stop(); | virtual void stop() { | |||
_playing = false; _changed = true; | ||||
} | ||||
/** | /** | |||
* Play this sample once. | * Schedule this audio sample to play once. | |||
* @see #play | * @see #play | |||
*/ | */ | |||
inline void play_once() { play(false); } | inline void play_once() { play(false); } | |||
/** | /** | |||
* Play this sample looped. | * Schedule this audio sample to play looped. | |||
* @see #play | * @see #play | |||
*/ | */ | |||
inline void play_looped() { play(true); } | inline void play_looped() { play(true); } | |||
/** | /** | |||
* Test if a sample is curretnly playing. | * Test if a audio sample is scheduled for playing. | |||
* @return true if is is playing, false otherwise. | * @return true if this audio sample is playing, false otherwise. | |||
*/ | */ | |||
bool is_playing( ); | inline bool is_playing() { return _playing; } | |||
/** | /** | |||
* Get the current pitch setting of this sample. | * Set this sample to out-of-range (or not) and | |||
* Schedule this audio sample to stop (or start) playing. | ||||
*/ | */ | |||
inline double get_pitch() const { return pitch; } | inline void set_out_of_range(bool oor = true) { | |||
_out_of_range = oor; _playing = (!oor && _loop); _changed = true; | ||||
} | ||||
/** | ||||
* Test if this sample to out-of-range or not. | ||||
*/ | ||||
inline bool test_out_of_range() { | ||||
return _out_of_range; | ||||
} | ||||
/** | ||||
* Set the data associated with this audio sample | ||||
* @param data Pointer to a memory block containg this audio sample dat | ||||
a. | ||||
This pointer will be set to NULL after calling this function. | ||||
*/ | ||||
inline void set_data( const unsigned char **data ) { | ||||
_data = (unsigned char*)*data; *data = NULL; | ||||
} | ||||
inline void set_data( const void **data ) { | ||||
_data = (unsigned char*)*data; *data = NULL; | ||||
} | ||||
/** | ||||
* Return the data associated with this audio sample. | ||||
* @return A pointer to this sound data of this audio sample. | ||||
*/ | ||||
inline void* get_data() const { return _data; } | ||||
/** | ||||
* Free the data associated with this audio sample | ||||
*/ | ||||
void free_data(); | ||||
/** | ||||
* Set the source id of this source | ||||
* @param sid OpenAL source-id | ||||
*/ | ||||
virtual void set_source(unsigned int sid) { | ||||
_source = sid; _valid_source = true; _changed = true; | ||||
} | ||||
/** | /** | |||
* Set the pitch of this sample. | * Get the OpenAL source id of this source | |||
* @return OpenAL source-id | ||||
*/ | */ | |||
void set_pitch( double p ); | virtual unsigned int get_source() { return _source; } | |||
/** | /** | |||
* Get the current volume setting of this sample. | * Test if the source-id of this audio sample may be passed to OpenAL. | |||
* @return true if the source-id is valid | ||||
*/ | */ | |||
inline double get_volume() const { return volume; } | virtual bool is_valid_source() const { return _valid_source; } | |||
/** | /** | |||
* Set the volume of this sample. | * Set the source-id of this audio sample to invalid. | |||
*/ | */ | |||
void set_volume( double v ); | virtual void no_valid_source() { _valid_source = false; } | |||
/** | /** | |||
* Returns the size of the sounds sample | * Set the OpenAL buffer-id of this source | |||
* @param bid OpenAL buffer-id | ||||
*/ | */ | |||
inline int get_size() { | inline void set_buffer(unsigned int bid) { | |||
return size; | _buffer = bid; _valid_buffer = true; _changed = true; | |||
} | } | |||
/** | /** | |||
* Set position of sound source (uses same coordinate system as opengl) | * Get the OpenAL buffer-id of this source | |||
* @return OpenAL buffer-id | ||||
*/ | */ | |||
void set_source_pos( ALfloat *pos ); | inline unsigned int get_buffer() { return _buffer; } | |||
/** | ||||
* Test if the buffer-id of this audio sample may be passed to OpenAL. | ||||
* @return true if the buffer-id is valid | ||||
*/ | ||||
inline bool is_valid_buffer() const { return _valid_buffer; } | ||||
/** | ||||
* Set the buffer-id of this audio sample to invalid. | ||||
*/ | ||||
inline void no_valid_buffer() { _valid_buffer = false; } | ||||
/** | ||||
* Set the playback pitch of this audio sample. | ||||
* Should be between 0.0 and 2.0 for maximum compatibility. | ||||
* @param p Pitch | ||||
*/ | ||||
inline void set_pitch( float p ) { | ||||
if (p > 2.0) p = 2.0; else if (p < 0.01) p = 0.01; | ||||
_pitch = p; _changed = true; | ||||
} | ||||
/** | ||||
* Get the current pitch value of this audio sample. | ||||
* @return Pitch | ||||
*/ | ||||
inline float get_pitch() { return _pitch; } | ||||
/** | ||||
* Set the master volume of this sample. Should be between 0.0 and 1.0. | ||||
* The final volume is calculated by multiplying the master and audio s | ||||
ample | ||||
* volume. | ||||
* @param v Volume | ||||
*/ | ||||
inline void set_master_volume( float v ) { | ||||
if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0; | ||||
_master_volume = v; _changed = true; | ||||
} | ||||
/** | ||||
* Set the volume of this audio sample. Should be between 0.0 and 1.0. | ||||
* The final volume is calculated by multiplying the master and audio s | ||||
ample | ||||
* volume. | ||||
* @param v Volume | ||||
*/ | ||||
inline void set_volume( float v ) { | ||||
if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0; | ||||
_volume = v; _changed = true; | ||||
} | ||||
/** | /** | |||
* Set "constant" offset position of sound source (uses same | * Get the final volume value of this audio sample. | |||
* coordinate system as opengl) | * @return Volume | |||
*/ | */ | |||
void set_offset_pos( ALfloat *pos ); | inline float get_volume() { return _volume * _master_volume; } | |||
/** | /** | |||
* Set the orientation of the sound source, both for direction | * Set the OpenAL format of this audio sample. | |||
* and audio cut-off angles. | * @param format OpenAL format-id | |||
*/ | */ | |||
void set_orientation( ALfloat *dir, ALfloat inner_angle=360.0, | inline void set_format( int format ) { _format = format; } | |||
ALfloat outer_angle=360.0, | ||||
ALfloat outer_gain=0.0); | ||||
/** | /** | |||
* Set velocity of sound source (uses same coordinate system as opengl) | * Returns the format of this audio sample. | |||
* @return OpenAL format-id | ||||
*/ | */ | |||
void set_source_vel( ALfloat *vel, ALfloat *listener_vel ); | inline int get_format() { return _format; } | |||
/** | /** | |||
* Set reference distance of sound (the distance where the gain | * Set the frequency (in Herz) of this audio sample. | |||
* will be half.) | * @param freq Frequency | |||
*/ | */ | |||
void set_reference_dist( ALfloat dist ); | inline void set_frequency( int freq ) { _freq = freq; } | |||
/** | /** | |||
* Set maximume distance of sound (the distance where the sound is | * Returns the frequency (in Herz) of this audio sample. | |||
* no longer audible. | * @return Frequency | |||
*/ | */ | |||
void set_max_dist( ALfloat dist ); | inline int get_frequency() { return _freq; } | |||
/** | /** | |||
* Load a sound file into a memory buffer only. | * Sets the size (in bytes) of this audio sample. | |||
* @param size Data size | ||||
*/ | */ | |||
ALvoid* load_file(const char *path, const char *file); | inline void set_size( size_t size ) { _size = size; } | |||
/** | ||||
* Returns the size (in bytes) of this audio sample. | ||||
* @return Data size | ||||
*/ | ||||
inline size_t get_size() const { return _size; } | ||||
/** | ||||
* Set the position of this sound relative to the base position. | ||||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht. | ||||
* @param pos Relative position of this sound | ||||
*/ | ||||
inline void set_relative_position( const SGVec3f& pos ) { | ||||
_relative_pos = toVec3d(pos); _changed = true; | ||||
} | ||||
/** | ||||
* Set the base position in Cartesian coordinates | ||||
* @param pos position in Cartesian coordinates | ||||
*/ | ||||
inline void set_position( const SGVec3d& pos ) { | ||||
_base_pos = pos; _changed = true; | ||||
} | ||||
/** | ||||
* Get the absolute position of this sound. | ||||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht. | ||||
* @return Absolute position | ||||
*/ | ||||
SGVec3d& get_position() { return _absolute_pos; } | ||||
/** | ||||
* Set the orientation of this sound. | ||||
* @param ori Quaternation containing the orientation information | ||||
*/ | ||||
inline void set_orientation( const SGQuatd& ori ) { | ||||
_orientation = ori; _changed = true; | ||||
} | ||||
inline void set_rotation( const SGQuatd& ec2body ) { | ||||
_rotation = ec2body; _changed = true; | ||||
} | ||||
/** | ||||
* Set direction of this sound relative to the orientation. | ||||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht | ||||
* @param dir Sound emission direction | ||||
*/ | ||||
inline void set_direction( const SGVec3f& dir ) { | ||||
_direction = toVec3d(dir); _static_changed = true; | ||||
} | ||||
/** | ||||
* Define the audio cone parameters for directional audio. | ||||
* Note: setting it to 2 degree will result in 1 degree to both sides. | ||||
* @param inner Inner cone angle (0 - 360 degrees) | ||||
* @param outer Outer cone angle (0 - 360 degrees) | ||||
* @param gain Remaining gain at the edge of the outer cone (0.0 - 1.0) | ||||
*/ | ||||
void set_audio_cone( float inner, float outer, float gain ) { | ||||
_inner_angle = inner; _outer_angle = outer; _outer_gain = gain; | ||||
_static_changed = true; | ||||
} | ||||
/** | ||||
* Get the orientation vector of this sound. | ||||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht | ||||
* @return Orientaton vector | ||||
*/ | ||||
SGVec3f& get_orientation() { return _orivec; } | ||||
/** | ||||
* Get the inner angle of the audio cone. | ||||
* @return Inner angle in degrees | ||||
*/ | ||||
float get_innerangle() { return _inner_angle; } | ||||
/** | ||||
* Get the outer angle of the audio cone. | ||||
* @return Outer angle in degrees | ||||
*/ | ||||
float get_outerangle() { return _outer_angle; } | ||||
/** | ||||
* Get the remaining gain at the edge of the outer cone. | ||||
* @return Gain | ||||
*/ | ||||
float get_outergain() { return _outer_gain; } | ||||
/** | ||||
* Set the velocity vector (in meters per second) of this sound. | ||||
* This is in the local frame coordinate system; x=north, y=east, z=dow | ||||
n | ||||
* @param Velocity vector | ||||
*/ | ||||
inline void set_velocity( const SGVec3f& vel ) { | ||||
_velocity = vel; _changed = true; | ||||
} | ||||
/** | ||||
* Get velocity vector (in meters per second) of this sound. | ||||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht | ||||
* @return Velocity vector | ||||
*/ | ||||
SGVec3f& get_velocity() { return _velocity; } | ||||
/** | ||||
* Set reference distance (in meters) of this sound. | ||||
* This is the distance where the gain will be half. | ||||
* @param dist Reference distance | ||||
*/ | ||||
inline void set_reference_dist( float dist ) { | ||||
_reference_dist = dist; _static_changed = true; | ||||
} | ||||
/** | ||||
* Get reference distance ((in meters) of this sound. | ||||
* This is the distance where the gain will be half. | ||||
* @return Reference distance | ||||
*/ | ||||
inline float get_reference_dist() { return _reference_dist; } | ||||
/** | ||||
* Set maximum distance (in meters) of this sound. | ||||
* This is the distance where this sound is no longer audible. | ||||
* @param dist Maximum distance | ||||
*/ | ||||
inline void set_max_dist( float dist ) { | ||||
_max_dist = dist; _static_changed = true; | ||||
} | ||||
/** | ||||
* Get maximum distance (in meters) of this sound. | ||||
* This is the distance where this sound is no longer audible. | ||||
* @return dist Maximum distance | ||||
*/ | ||||
inline float get_max_dist() { return _max_dist; } | ||||
/** | ||||
* Get the reference name of this audio sample. | ||||
* @return Sample name | ||||
*/ | ||||
inline std::string get_sample_name() const { return _refname; } | ||||
inline virtual bool is_queue() const { return false; } | ||||
void update_pos_and_orientation(); | ||||
protected: | ||||
int _format; | ||||
size_t _size; | ||||
int _freq; | ||||
bool _changed; | ||||
// Sources are points emitting sound. | ||||
bool _valid_source; | ||||
unsigned int _source; | ||||
private: | ||||
// Position of the source sound. | ||||
SGVec3d _absolute_pos; // absolute position | ||||
SGVec3d _relative_pos; // position relative to the base position | ||||
SGVec3d _direction; // orientation offset | ||||
SGVec3f _velocity; // Velocity of the source sound. | ||||
// The position and orientation of this sound | ||||
SGQuatd _orientation; // base orientation | ||||
SGVec3f _orivec; // orientation vector for OpenAL | ||||
SGVec3d _base_pos; // base position | ||||
SGQuatd _rotation; | ||||
std::string _refname; // name or file path | ||||
unsigned char* _data; | ||||
// configuration values | ||||
// Buffers hold sound data. | ||||
bool _valid_buffer; | ||||
unsigned int _buffer; | ||||
// The orientation of this sound (direction and cut-off angles) | ||||
float _inner_angle; | ||||
float _outer_angle; | ||||
float _outer_gain; | ||||
float _pitch; | ||||
float _volume; | ||||
float _master_volume; | ||||
float _reference_dist; | ||||
float _max_dist; | ||||
bool _loop; | ||||
bool _playing; | ||||
bool _static_changed; | ||||
bool _out_of_range; | ||||
bool _is_file; | ||||
std::string random_string(); | ||||
}; | }; | |||
#endif // _SG_SAMPLE_HXX | #endif // _SG_SAMPLE_HXX | |||
End of changes. 53 change blocks. | ||||
136 lines changed or deleted | 420 lines changed or added | |||
saturn.hxx | saturn.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: saturn.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _SATURN_HXX_ | #ifndef _SATURN_HXX_ | |||
#define _SATURN_HXX_ | #define _SATURN_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Saturn : public CelestialBody | class Saturn : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
screen-dump.hxx | screen-dump.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: screen-dump.hxx,v 1.5 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef SG_SCREEN_DUMP_HXX | ||||
#define SG_SCREEN_DUMP_HXX | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include SG_GL_H | #include <osg/GL> | |||
/** | /** | |||
* Dump the screen buffer to a ppm file. | * Dump the screen buffer to a PNG file. | |||
* @param filename name of file | * @param filename name of file | |||
* @param win_width width of our opengl window | * @param win_width width of our opengl window | |||
* @param win_height height of our opengl window | * @param win_height height of our opengl window | |||
*/ | */ | |||
bool sg_glDumpWindow( const char *filename, int win_width, int win_height ) ; | bool sg_glDumpWindow( const char *filename, int win_width, int win_height ) ; | |||
/** | /** | |||
* Given a GLubyte *buffer, write it out to a ppm file. | * Given a GLubyte *buffer, write it out to a ppm file. | |||
* @param filename name of file | * @param filename name of file | |||
* @param buffer pointer to opengl buffer | * @param buffer pointer to opengl buffer | |||
* @param win_width width of buffer | * @param win_width width of buffer | |||
* @param win_height height of buffer | * @param win_height height of buffer | |||
* @param mode one of GL_RGBA, GL_RGB, etc. | * @param mode one of GL_RGBA, GL_RGB, etc. | |||
*/ | */ | |||
bool sg_glWritePPMFile( const char *filename, GLubyte *buffer, int win_widt h, | bool sg_glWritePPMFile( const char *filename, GLubyte *buffer, int win_widt h, | |||
int win_height, int mode); | int win_height, int mode); | |||
#endif // of SG_SCREEN_DUMP_HXX | ||||
End of changes. 4 change blocks. | ||||
3 lines changed or deleted | 6 lines changed or added | |||
serial.hxx | serial.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: serial.hxx,v 1.5 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SERIAL_HXX | #ifndef _SERIAL_HXX | |||
#define _SERIAL_HXX | #define _SERIAL_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ ) | #ifdef _WIN32 | |||
# include <windows.h> | # include <windows.h> | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
SG_USING_STD(string); | using std::string; | |||
// if someone know how to do this all with C++ streams let me know | // if someone know how to do this all with C++ streams let me know | |||
// #include <stdio.h> | // #include <stdio.h> | |||
/** | /** | |||
* A class to encapsulate low level serial port IO. | * A class to encapsulate low level serial port IO. | |||
*/ | */ | |||
class SGSerialPort | class SGSerialPort | |||
{ | { | |||
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ ) | #ifdef _WIN32 | |||
typedef HANDLE fd_type; | typedef HANDLE fd_type; | |||
#else | #else | |||
typedef int fd_type; | typedef int fd_type; | |||
#endif | #endif | |||
private: | private: | |||
fd_type fd; | fd_type fd; | |||
bool dev_open; | bool dev_open; | |||
End of changes. 4 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added | |||
sg_binobj.hxx | sg_binobj.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, | // This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | // GNU General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_binobj.hxx,v 1.6 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_BINOBJ_HXX | #ifndef _SG_BINOBJ_HXX | |||
#define _SG_BINOBJ_HXX | #define _SG_BINOBJ_HXX | |||
#include <plib/sg.h> | #include <zlib.h> // for gzFile | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/constants.h> | #include <simgear/constants.h> | |||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
#include <simgear/bucket/newbucket.hxx> | #include <simgear/math/SGMath.hxx> | |||
#include <stdio.h> | #include <vector> | |||
#include <time.h> | #include <string> | |||
#include <list> | ||||
#include STL_STRING | ||||
/** STL Structure used to store object information */ | /** STL Structure used to store object information */ | |||
typedef vector < int_list > group_list; | typedef std::vector < int_list > group_list; | |||
typedef group_list::iterator group_list_iterator; | typedef group_list::iterator group_list_iterator; | |||
typedef group_list::const_iterator const_group_list_iterator; | typedef group_list::const_iterator const_group_list_iterator; | |||
/** Magic Number for our file format */ | // forward decls | |||
#define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION ) | class SGBucket; | |||
class SGPath; | ||||
/** | /** | |||
* A class to manipulate the simgear 3d object format. | * A class to manipulate the simgear 3d object format. | |||
* This class provides functionality to both read and write the binary form at. | * This class provides functionality to both read and write the binary form at. | |||
* | * | |||
* Here is a really quick overview of the file syntax: | * Here is a really quick overview of the file syntax: | |||
* | * | |||
* - scenery-file: magic, nobjects, object+ | * - scenery-file: magic, nobjects, object+ | |||
* | * | |||
* - magic: "TG" + version | * - magic: "TG" + version | |||
skipping to change at line 71 | skipping to change at line 69 | |||
* | * | |||
* - element: nbytes, BYTE+ | * - element: nbytes, BYTE+ | |||
* | * | |||
* - property: prop_typecode, nbytes, BYTE+ | * - property: prop_typecode, nbytes, BYTE+ | |||
* | * | |||
* - obj_typecode: bounding sphere | vertices | normals | texcoords | | * - obj_typecode: bounding sphere | vertices | normals | texcoords | | |||
* points | triangles | fans | strips | * points | triangles | fans | strips | |||
* | * | |||
* - prop_typecode: material_name | ??? | * - prop_typecode: material_name | ??? | |||
* | * | |||
* - nelements: SHORT (Gives us 65536 which ought to be enough, right?) | * - nelements: USHORT (Gives us 65536 which ought to be enough, right?) | |||
* | * | |||
* - nproperties: SHORT | * - nproperties: USHORT | |||
* | * | |||
* - *_typecode: CHAR | * - *_typecode: CHAR | |||
* | * | |||
* - nbytes: INTEGER (If we used short here that would mean 65536 bytes = 1 6384 | * - nbytes: INTEGER (If we used short here that would mean 65536 bytes = 1 6384 | |||
* floats = 5461 vertices which is not enough for future | * floats = 5461 vertices which is not enough for future | |||
* growth) | * growth) | |||
* | * | |||
* - vertex: FLOAT, FLOAT, FLOAT | * - vertex: FLOAT, FLOAT, FLOAT | |||
*/ | */ | |||
class SGBinObject { | class SGBinObject { | |||
private: | ||||
unsigned short version; | unsigned short version; | |||
Point3D gbs_center; | SGVec3d gbs_center; | |||
float gbs_radius; | float gbs_radius; | |||
point_list wgs84_nodes; // vertex list | std::vector<SGVec3d> wgs84_nodes; // vertex list | |||
point_list colors; // color list | std::vector<SGVec4f> colors; // color list | |||
point_list normals; // normal list | std::vector<SGVec3f> normals; // normal list | |||
point_list texcoords; // texture coordinate list | std::vector<SGVec2f> texcoords; // texture coordinate list | |||
group_list pts_v; // points vertex index | group_list pts_v; // points vertex index | |||
group_list pts_n; // points normal index | group_list pts_n; // points normal index | |||
group_list pts_c; // points color index | group_list pts_c; // points color index | |||
group_list pts_tc; // points texture coordinate index | group_list pts_tc; // points texture coordinate index | |||
string_list pt_materials; // points materials | string_list pt_materials; // points materials | |||
group_list tris_v; // triangles vertex index | group_list tris_v; // triangles vertex index | |||
group_list tris_n; // triangles normal index | group_list tris_n; // triangles normal index | |||
group_list tris_c; // triangles color index | group_list tris_c; // triangles color index | |||
skipping to change at line 118 | skipping to change at line 117 | |||
group_list strips_c; // tristrips color index | group_list strips_c; // tristrips color index | |||
group_list strips_tc; // tristrips texture coordinate index | group_list strips_tc; // tristrips texture coordinate index | |||
string_list strip_materials;// tristrips materials | string_list strip_materials;// tristrips materials | |||
group_list fans_v; // fans vertex index | group_list fans_v; // fans vertex index | |||
group_list fans_n; // fans normal index | group_list fans_n; // fans normal index | |||
group_list fans_c; // fans color index | group_list fans_c; // fans color index | |||
group_list fans_tc; // fans texture coordinate index | group_list fans_tc; // fans texture coordinate index | |||
string_list fan_materials; // fans materials | string_list fan_materials; // fans materials | |||
void read_properties(gzFile fp, int nproperties); | ||||
void read_object( gzFile fp, | ||||
int obj_type, | ||||
int nproperties, | ||||
int nelements, | ||||
group_list& vertices, | ||||
group_list& normals, | ||||
group_list& colors, | ||||
group_list& texCoords, | ||||
string_list& materials); | ||||
void write_header(gzFile fp, int type, int nProps, int nElements); | ||||
void write_objects(gzFile fp, int type, const group_list& verts, | ||||
const group_list& normals, const group_list& colors, | ||||
const group_list& texCoords, const string_list& materials); | ||||
unsigned int count_objects(const string_list& materials); | ||||
public: | public: | |||
inline unsigned short get_version() const { return version; } | inline unsigned short get_version() const { return version; } | |||
inline const Point3D& get_gbs_center() const { return gbs_center; } | inline const SGVec3d& get_gbs_center() const { return gbs_center; } | |||
inline void set_gbs_center( const Point3D& p ) { gbs_center = p; } | inline void set_gbs_center( const SGVec3d& p ) { gbs_center = p; } | |||
inline float get_gbs_radius() const { return gbs_radius; } | inline float get_gbs_radius() const { return gbs_radius; } | |||
inline void set_gbs_radius( float r ) { gbs_radius = r; } | inline void set_gbs_radius( float r ) { gbs_radius = r; } | |||
inline const point_list& get_wgs84_nodes() const { return wgs84_nodes; | inline const std::vector<SGVec3d>& get_wgs84_nodes() const | |||
} | { return wgs84_nodes; } | |||
inline void set_wgs84_nodes( const point_list& n ) { wgs84_nodes = n; } | inline void set_wgs84_nodes( const std::vector<SGVec3d>& n ) | |||
{ wgs84_nodes = n; } | ||||
inline const point_list& get_colors() const { return colors; } | inline const std::vector<SGVec4f>& get_colors() const { return colors; | |||
inline void set_colors( const point_list& c ) { colors = c; } | } | |||
inline void set_colors( const std::vector<SGVec4f>& c ) { colors = c; } | ||||
inline const point_list& get_normals() const { return normals; } | inline const std::vector<SGVec3f>& get_normals() const { return normals | |||
inline void set_normals( const point_list& n ) { normals = n; } | ; } | |||
inline void set_normals( const std::vector<SGVec3f>& n ) { normals = n; | ||||
} | ||||
inline const point_list& get_texcoords() const { return texcoords; } | inline const std::vector<SGVec2f>& get_texcoords() const { return texco | |||
inline void set_texcoords( const point_list& t ) { texcoords = t; } | ords; } | |||
inline void set_texcoords( const std::vector<SGVec2f>& t ) { texcoords | ||||
= t; } | ||||
inline const group_list& get_pts_v() const { return pts_v; } | inline const group_list& get_pts_v() const { return pts_v; } | |||
inline void set_pts_v( const group_list& g ) { pts_v = g; } | inline void set_pts_v( const group_list& g ) { pts_v = g; } | |||
inline const group_list& get_pts_n() const { return pts_n; } | inline const group_list& get_pts_n() const { return pts_n; } | |||
inline void set_pts_n( const group_list& g ) { pts_n = g; } | inline void set_pts_n( const group_list& g ) { pts_n = g; } | |||
inline const group_list& get_pts_c() const { return pts_c; } | inline const group_list& get_pts_c() const { return pts_c; } | |||
inline void set_pts_c( const group_list& g ) { pts_c = g; } | inline void set_pts_c( const group_list& g ) { pts_c = g; } | |||
inline const group_list& get_pts_tc() const { return pts_tc; } | inline const group_list& get_pts_tc() const { return pts_tc; } | |||
inline void set_pts_tc( const group_list& g ) { pts_tc = g; } | inline void set_pts_tc( const group_list& g ) { pts_tc = g; } | |||
inline const string_list& get_pt_materials() const { return pt_material s; } | inline const string_list& get_pt_materials() const { return pt_material s; } | |||
skipping to change at line 191 | skipping to change at line 210 | |||
inline const group_list& get_fans_tc() const { return fans_tc; } | inline const group_list& get_fans_tc() const { return fans_tc; } | |||
inline void set_fans_tc( const group_list& g ) { fans_tc = g; } | inline void set_fans_tc( const group_list& g ) { fans_tc = g; } | |||
inline const string_list& get_fan_materials() const { return fan_materi als; } | inline const string_list& get_fan_materials() const { return fan_materi als; } | |||
inline void set_fan_materials( const string_list& s ) { fan_materials = s; } | inline void set_fan_materials( const string_list& s ) { fan_materials = s; } | |||
/** | /** | |||
* Read a binary file object and populate the provided structures. | * Read a binary file object and populate the provided structures. | |||
* @param file input file name | * @param file input file name | |||
* @return result of read | * @return result of read | |||
*/ | */ | |||
bool read_bin( const string& file ); | bool read_bin( const std::string& file ); | |||
/** | /** | |||
* Write out the structures to a binary file. We assume that the | * Write out the structures to a binary file. We assume that the | |||
* groups come to us sorted by material property. If not, things | * groups come to us sorted by material property. If not, things | |||
* don't break, but the result won't be as optimal. | * don't break, but the result won't be as optimal. | |||
* @param base name of output path | * @param base name of output path | |||
* @param name name of output file | * @param name name of output file | |||
* @param b bucket for object location | * @param b bucket for object location | |||
* @return result of write | * @return result of write | |||
*/ | */ | |||
bool write_bin( const string& base, const string& name, const SGBucket& | bool write_bin( const std::string& base, const std::string& name, const | |||
b ); | SGBucket& b ); | |||
bool write_bin_file(const SGPath& file); | ||||
/** | /** | |||
* Write out the structures to an ASCII file. We assume that the | * Write out the structures to an ASCII file. We assume that the | |||
* groups come to us sorted by material property. If not, things | * groups come to us sorted by material property. If not, things | |||
* don't break, but the result won't be as optimal. | * don't break, but the result won't be as optimal. | |||
* @param base name of output path | * @param base name of output path | |||
* @param name name of output file | * @param name name of output file | |||
* @param b bucket for object location | * @param b bucket for object location | |||
* @return result of write | * @return result of write | |||
*/ | */ | |||
bool write_ascii( const string& base, const string& name, | bool write_ascii( const std::string& base, const std::string& name, | |||
const SGBucket& b ); | const SGBucket& b ); | |||
}; | }; | |||
/** | ||||
* \relates SGBinObject | ||||
* Calculate the center of a list of points, by taking the halfway | ||||
* point between the min and max points. | ||||
* @param wgs84_nodes list of points in wgs84 coordinates | ||||
* @return center point | ||||
*/ | ||||
Point3D sgCalcCenter( point_list& wgs84_nodes ); | ||||
/** | ||||
* \relates SGBinObject | ||||
* Calculate the bounding sphere of a set of nodes. | ||||
* Center is the center of the tile and zero elevation. | ||||
* @param center center of our bounding radius | ||||
* @param wgs84_nodes list of points in wgs84 coordinates | ||||
* @return radius | ||||
*/ | ||||
double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ); | ||||
#endif // _SG_BINOBJ_HXX | #endif // _SG_BINOBJ_HXX | |||
End of changes. 21 change blocks. | ||||
52 lines changed or deleted | 58 lines changed or added | |||
sg_file.hxx | sg_file.hxx | |||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_file.hxx,v 1.6 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_FILE_HXX | #ifndef _SG_FILE_HXX | |||
#define _SG_FILE_HXX | #define _SG_FILE_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <string> | #include <string> | |||
#include <sys/types.h> // for open(), read(), write(), close() | ||||
#include <sys/stat.h> // for open(), read(), write(), close() | ||||
#include <fcntl.h> // for open(), read(), write(), close() | ||||
#if !defined( _MSC_VER ) | ||||
# include <unistd.h> // for open(), read(), write(), close() | ||||
#endif | ||||
#include "iochannel.hxx" | #include "iochannel.hxx" | |||
SG_USING_STD(string); | ||||
/** | /** | |||
* A file I/O class based on SGIOChannel. | * A file I/O class based on SGIOChannel. | |||
*/ | */ | |||
class SGFile : public SGIOChannel { | class SGFile : public SGIOChannel { | |||
string file_name; | std::string file_name; | |||
int fp; | int fp; | |||
bool eof_flag; | bool eof_flag; | |||
// Number of repetitions to play. -1 means loop infinitely. | ||||
const int repeat; | ||||
int iteration; // number of current repetition, | ||||
// starting at 0 | ||||
public: | public: | |||
/** | /** | |||
* Create an instance of SGFile. | * Create an instance of SGFile. | |||
* When calling the constructor you need to provide a file | * When calling the constructor you need to provide a file | |||
* name. This file is not opened immediately, but instead will be | * name. This file is not opened immediately, but instead will be | |||
* opened when the open() method is called. | * opened when the open() method is called. | |||
* @param file name of file to open | * @param file name of file to open | |||
* @param repeat On eof restart at the beginning of the file | ||||
*/ | ||||
SGFile( const std::string& file, int repeat_ = 1 ); | ||||
/** | ||||
* Create an SGFile from an existing, open file-descriptor | ||||
*/ | */ | |||
SGFile( const string& file ); | SGFile( int existingFd ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGFile(); | ~SGFile(); | |||
// open the file based on specified direction | // open the file based on specified direction | |||
bool open( const SGProtocolDir dir ); | bool open( const SGProtocolDir dir ); | |||
// read a block of data of specified size | // read a block of data of specified size | |||
int read( char *buf, int length ); | int read( char *buf, int length ); | |||
skipping to change at line 89 | skipping to change at line 86 | |||
// write data to a file | // write data to a file | |||
int write( const char *buf, const int length ); | int write( const char *buf, const int length ); | |||
// write null terminated string to a file | // write null terminated string to a file | |||
int writestring( const char *str ); | int writestring( const char *str ); | |||
// close file | // close file | |||
bool close(); | bool close(); | |||
/** @return the name of the file being manipulated. */ | /** @return the name of the file being manipulated. */ | |||
inline string get_file_name() const { return file_name; } | inline std::string get_file_name() const { return file_name; } | |||
/** @return true of eof conditions exists */ | /** @return true of eof conditions exists */ | |||
inline bool eof() const { return eof_flag; }; | virtual bool eof() const { return eof_flag; }; | |||
}; | }; | |||
#endif // _SG_FILE_HXX | #endif // _SG_FILE_HXX | |||
End of changes. 10 change blocks. | ||||
18 lines changed or deleted | 15 lines changed or added | |||
sg_geodesy.hxx | sg_geodesy.hxx | |||
---|---|---|---|---|
#ifndef _SG_GEODESY_HXX | #ifndef _SG_GEODESY_HXX | |||
#define _SG_GEODESY_HXX | #define _SG_GEODESY_HXX | |||
#include <simgear/math/point3d.hxx> | ||||
#include "SGMath.hxx" | #include "SGMath.hxx" | |||
/** | // Compatibility header. | |||
* Convert from geocentric coordinates to geodetic coordinates | // Please use the SGGeodesy and SGMath functions directly. | |||
* @param lat_geoc (in) Geocentric latitude, radians, + = North | ||||
* @param radius (in) C.G. radius to earth center (meters) | ||||
* @param lat_geod (out) Geodetic latitude, radians, + = North | ||||
* @param alt (out) C.G. altitude above mean sea level (meters) | ||||
* @param sea_level_r (out) radius from earth center to sea level at | ||||
* local vertical (surface normal) of C.G. (meters) | ||||
*/ | ||||
inline void sgGeocToGeod(double lat_geoc, double radius, | ||||
double *lat_geod, double *alt, double *sea_level_r | ||||
) | ||||
{ | ||||
SGVec3<double> cart; | ||||
SGGeodesy::SGGeocToCart(SGGeoc::fromRadM(0, lat_geoc, radius), cart); | ||||
SGGeod geod; | ||||
SGGeodesy::SGCartToGeod(cart, geod); | ||||
*lat_geod = geod.getLatitudeRad(); | ||||
*alt = geod.getElevationM(); | ||||
*sea_level_r = SGGeodesy::SGGeodToSeaLevelRadius(geod); | ||||
} | ||||
/** | /** | |||
* Convert from geodetic coordinates to geocentric coordinates. | * Convert from geodetic coordinates to geocentric coordinates. | |||
* WARNING: this function is non-reversible. Due to the fact that | * WARNING: this function is non-reversible. Due to the fact that | |||
* "up" is a different direction for geocentric and geodetic frames, | * "up" is a different direction for geocentric and geodetic frames, | |||
* you can not simply add your "alt" parameter to the "sl_radius" | * you can not simply add your "alt" parameter to the "sl_radius" | |||
* result and get back (via sgGeodToGeoc()) to the coordinates you | * result and get back (via sgGeodToGeoc()) to the coordinates you | |||
* started with. The error under normal conditions will be of | * started with. The error under normal conditions will be of | |||
* centimeter order; whether that is important or not is application | * centimeter order; whether that is important or not is application | |||
* dependent. Consider using sgGeodToCart() instead. | * dependent. Consider using sgGeodToCart() instead. | |||
skipping to change at line 73 | skipping to change at line 54 | |||
inline void sgCartToGeod(const double* xyz, double* lat, double* lon, doubl e* alt) | inline void sgCartToGeod(const double* xyz, double* lat, double* lon, doubl e* alt) | |||
{ | { | |||
SGGeod geod; | SGGeod geod; | |||
SGGeodesy::SGCartToGeod(SGVec3<double>(xyz), geod); | SGGeodesy::SGCartToGeod(SGVec3<double>(xyz), geod); | |||
*lat = geod.getLatitudeRad(); | *lat = geod.getLatitudeRad(); | |||
*lon = geod.getLongitudeRad(); | *lon = geod.getLongitudeRad(); | |||
*alt = geod.getElevationM(); | *alt = geod.getElevationM(); | |||
} | } | |||
/** | /** | |||
* Convert a cartesian point to a geodetic lat/lon/altitude. | ||||
* Alternate form using Point3D objects. | ||||
* | ||||
* @param cartesian point | ||||
* @return geodetic point | ||||
*/ | ||||
inline Point3D sgCartToGeod(const Point3D& p) | ||||
{ | ||||
SGGeod geod; | ||||
SGGeodesy::SGCartToGeod(SGVec3<double>(p.x(), p.y(), p.z()), geod); | ||||
return Point3D::fromSGGeod(geod); | ||||
} | ||||
/** | ||||
* Convert a geodetic lat/lon/altitude to a cartesian point. | * Convert a geodetic lat/lon/altitude to a cartesian point. | |||
* | * | |||
* @param lat (in) Latitude, in radians | * @param lat (in) Latitude, in radians | |||
* @param lon (in) Longitude, in radians | * @param lon (in) Longitude, in radians | |||
* @param alt (in) Altitude, in meters above the WGS84 ellipsoid | * @param alt (in) Altitude, in meters above the WGS84 ellipsoid | |||
* @param xyz (out) Pointer to cartesian point. | * @param xyz (out) Pointer to cartesian point. | |||
*/ | */ | |||
inline void sgGeodToCart(double lat, double lon, double alt, double* xyz) | inline void sgGeodToCart(double lat, double lon, double alt, double* xyz) | |||
{ | { | |||
SGVec3<double> cart; | SGVec3<double> cart; | |||
SGGeodesy::SGGeodToCart(SGGeod::fromRadM(lon, lat, alt), cart); | SGGeodesy::SGGeodToCart(SGGeod::fromRadM(lon, lat, alt), cart); | |||
xyz[0] = cart(0); | xyz[0] = cart(0); | |||
xyz[1] = cart(1); | xyz[1] = cart(1); | |||
xyz[2] = cart(2); | xyz[2] = cart(2); | |||
} | } | |||
/** | /** | |||
* Convert a geodetic lat/lon/altitude to a cartesian point. | ||||
* Alternate form using Point3D objects. | ||||
* | ||||
* @param geodetic point | ||||
* @return cartesian point | ||||
*/ | ||||
inline Point3D sgGeodToCart(const Point3D& geod) | ||||
{ | ||||
SGVec3<double> cart; | ||||
SGGeodesy::SGGeodToCart(SGGeod::fromRadM(geod.lon(), geod.lat(), geod.ele | ||||
v()), cart); | ||||
return Point3D::fromSGVec3(cart); | ||||
} | ||||
/** | ||||
* Given a starting position and an offset radial and distance, | * Given a starting position and an offset radial and distance, | |||
* calculate an ending positon on a wgs84 ellipsoid. | * calculate an ending positon on a wgs84 ellipsoid. | |||
* @param alt (in) meters (unused) | * @param alt (in) meters (unused) | |||
* @param lat1 (in) degrees | * @param lat1 (in) degrees | |||
* @param lon1 (in) degrees | * @param lon1 (in) degrees | |||
* @param az1 (in) degrees | * @param az1 (in) degrees | |||
* @param s (in) distance in meters | * @param s (in) distance in meters | |||
* @param lat2 (out) degrees | * @param lat2 (out) degrees | |||
* @param lon2 (out) degrees | * @param lon2 (out) degrees | |||
* @param az2 (out) return course in degrees | * @param az2 (out) return course in degrees | |||
*/ | */ | |||
int geo_direct_wgs_84 ( double lat1, double lon1, double az1, | inline int geo_direct_wgs_84 ( double lat1, double lon1, double az1, | |||
double s, double *lat2, double *lon2, | double s, double *lat2, double *lon2, | |||
double *az2 ); | double *az2 ) | |||
{ | ||||
SGGeod p2; | ||||
if (!SGGeodesy::direct(SGGeod::fromDeg(lon1, lat1), az1, s, p2, *az2)) | ||||
return 1; | ||||
*lat2 = p2.getLatitudeDeg(); | ||||
*lon2 = p2.getLongitudeDeg(); | ||||
return 0; | ||||
} | ||||
inline int geo_direct_wgs_84 ( double alt, double lat1, | inline int geo_direct_wgs_84 ( double alt, double lat1, | |||
double lon1, double az1, | double lon1, double az1, | |||
double s, double *lat2, double *lon2, | double s, double *lat2, double *lon2, | |||
double *az2 ) | double *az2 ) | |||
{ return geo_direct_wgs_84(lat1, lon1, az1, s, lat2, lon2, az2); } | { return geo_direct_wgs_84(lat1, lon1, az1, s, lat2, lon2, az2); } | |||
/** | /** | |||
* Given a starting position and an offset radial and distance, | * Given a starting position and an offset radial and distance, | |||
* calculate an ending positon on a wgs84 ellipsoid. | * calculate an ending positon on a wgs84 ellipsoid. | |||
* @param p1 (in) geodetic position | * @param p1 (in) geodetic position | |||
* @param az1 (in) degrees | * @param az1 (in) degrees | |||
* @param s (in) distance in meters | * @param s (in) distance in meters | |||
* @param p2 (out) geodetic position | * @param p2 (out) geodetic position | |||
* @param az2 (out) return course in degrees | * @param az2 (out) return course in degrees | |||
*/ | */ | |||
inline int geo_direct_wgs_84(const SGGeod& p1, double az1, | inline int geo_direct_wgs_84(const SGGeod& p1, double az1, | |||
double s, SGGeod& p2, double *az2 ) | double s, SGGeod& p2, double *az2 ) | |||
{ | { | |||
double lat2, lon2; | return !SGGeodesy::direct(p1, az1, s, p2, *az2); | |||
int ret = geo_direct_wgs_84(p1.getLatitudeDeg(), p1.getLongitudeDeg(), | ||||
az1, s, &lat2, &lon2, az2); | ||||
p2.setLatitudeDeg(lat2); | ||||
p2.setLongitudeDeg(lon2); | ||||
return ret; | ||||
} | } | |||
/** | /** | |||
* Given an altitude and two sets of (lat, lon) calculate great circle | * Given an altitude and two sets of (lat, lon) calculate great circle | |||
* distance between them as well as the starting and ending azimuths. | * distance between them as well as the starting and ending azimuths. | |||
* @param alt (in) meters (unused) | * @param alt (in) meters (unused) | |||
* @param lat1 (in) degrees | * @param lat1 (in) degrees | |||
* @param lon1 (in) degrees | * @param lon1 (in) degrees | |||
* @param lat2 (in) degrees | * @param lat2 (in) degrees | |||
* @param lon2 (in) degrees | * @param lon2 (in) degrees | |||
* @param az1 (out) start heading degrees | * @param az1 (out) start heading degrees | |||
* @param az2 (out) end heading degrees | * @param az2 (out) end heading degrees | |||
* @param s (out) distance meters | * @param s (out) distance meters | |||
*/ | */ | |||
int geo_inverse_wgs_84( double lat1, double lon1, double lat2, | inline int geo_inverse_wgs_84( double lat1, double lon1, double lat2, | |||
double lon2, double *az1, double *az2, | double lon2, double *az1, double *az2, | |||
double *s ); | double *s ) | |||
{ | ||||
return !SGGeodesy::inverse(SGGeod::fromDeg(lon1, lat1), | ||||
SGGeod::fromDeg(lon2, lat2), *az1, *az2, *s); | ||||
} | ||||
inline int geo_inverse_wgs_84( double alt, double lat1, | inline int geo_inverse_wgs_84( double alt, double lat1, | |||
double lon1, double lat2, | double lon1, double lat2, | |||
double lon2, double *az1, double *az2, | double lon2, double *az1, double *az2, | |||
double *s ) | double *s ) | |||
{ return geo_inverse_wgs_84(lat1, lon1, lat2, lon2, az1, az2, s); } | { return geo_inverse_wgs_84(lat1, lon1, lat2, lon2, az1, az2, s); } | |||
/** | /** | |||
* Given an altitude and two sets of (lat, lon) calculate great circle | * Given an altitude and two sets of (lat, lon) calculate great circle | |||
* distance between them as well as the starting and ending azimuths. | * distance between them as well as the starting and ending azimuths. | |||
* @param p1 (in) first position | * @param p1 (in) first position | |||
* @param p2 (in) fsecond position | * @param p2 (in) fsecond position | |||
* @param az1 (out) start heading degrees | * @param az1 (out) start heading degrees | |||
* @param az2 (out) end heading degrees | * @param az2 (out) end heading degrees | |||
* @param s (out) distance meters | * @param s (out) distance meters | |||
*/ | */ | |||
inline int geo_inverse_wgs_84(const SGGeod& p1, const SGGeod& p2, | inline int geo_inverse_wgs_84(const SGGeod& p1, const SGGeod& p2, | |||
double *az1, double *az2, double *s ) | double *az1, double *az2, double *s ) | |||
{ | { | |||
return geo_inverse_wgs_84(p1.getLatitudeDeg(), p1.getLongitudeDeg(), | return !SGGeodesy::inverse(p1, p2, *az1, *az2, *s); | |||
p2.getLatitudeDeg(), p2.getLongitudeDeg(), | ||||
az1, az2, s); | ||||
} | } | |||
#endif // _SG_GEODESY_HXX | #endif // _SG_GEODESY_HXX | |||
End of changes. 8 change blocks. | ||||
66 lines changed or deleted | 22 lines changed or added | |||
sg_inlines.h | sg_inlines.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_inlines.h,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_INLINES_H | #ifndef _SG_INLINES_H | |||
#define _SG_INLINES_H | #define _SG_INLINES_H | |||
// return the sign of a value | // return the sign of a value | |||
template <class T> | template <class T> | |||
inline int SG_SIGN(const T x) { | inline int SG_SIGN(const T x) { | |||
return x < T(0) ? -1 : 1; | return x < T(0) ? -1 : 1; | |||
} | } | |||
skipping to change at line 100 | skipping to change at line 100 | |||
if ( x < min ) { x = min; } | if ( x < min ) { x = min; } | |||
if ( x > max ) { x = max; } | if ( x > max ) { x = max; } | |||
} | } | |||
// normalize a value to lie between min and max | // normalize a value to lie between min and max | |||
template <class T> | template <class T> | |||
inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) { | inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) { | |||
T step = max - min; | T step = max - min; | |||
while( val >= max ) val -= step; | while( val >= max ) val -= step; | |||
while( val < min ) val += step; | while( val < min ) val += step; | |||
}; | } | |||
// avoid an 'unused parameter' compiler warning. | ||||
#define SG_UNUSED(x) (void)x | ||||
// easy way to disable the copy constructor and assignment operator | ||||
// on an object | ||||
#define SG_DISABLE_COPY(Class) \ | ||||
Class(const Class &); \ | ||||
Class &operator=(const Class &); | ||||
#endif // _SG_INLINES_H | #endif // _SG_INLINES_H | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 11 lines changed or added | |||
sg_path.hxx | sg_path.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_path.hxx,v 1.11 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_PATH_HXX | #ifndef _SG_PATH_HXX | |||
#define _SG_PATH_HXX | #define _SG_PATH_HXX | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <ctime> | ||||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
SG_USING_STD(string); | ||||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
typedef int mode_t; | typedef int mode_t; | |||
#endif | #endif | |||
/** | /** | |||
* A class to hide path separator difference across platforms and assist | * A class to hide path separator difference across platforms and assist | |||
* in managing file system path names. | * in managing file system path names. | |||
* | * | |||
* Paths can be input in any platform format and will be converted | * Paths can be input in any platform format and will be converted | |||
* automatically to the proper format. | * automatically to the proper format. | |||
*/ | */ | |||
class SGPath { | class SGPath { | |||
private: | ||||
string path; | ||||
public: | public: | |||
/** Default constructor */ | /** Default constructor */ | |||
SGPath(); | SGPath(); | |||
/** Copy contructor */ | ||||
SGPath(const SGPath& p); | ||||
SGPath& operator=(const SGPath& p); | ||||
/** | /** | |||
* Construct a path based on the starting path provided. | * Construct a path based on the starting path provided. | |||
* @param p initial path | * @param p initial path | |||
*/ | */ | |||
SGPath( const string& p ); | SGPath( const std::string& p ); | |||
/** | ||||
* Construct a path based on the starting path provided and a relative | ||||
subpath | ||||
* @param p initial path | ||||
* @param r relative subpath | ||||
*/ | ||||
SGPath( const SGPath& p, const std::string& r ); | ||||
/** Destructor */ | /** Destructor */ | |||
~SGPath(); | ~SGPath(); | |||
/** | /** | |||
* Set path to a new value | * Set path to a new value | |||
* @param p new path | * @param p new path | |||
*/ | */ | |||
void set( const string& p ); | void set( const std::string& p ); | |||
SGPath& operator= ( const char* p ) { this->set(p); return *this; } | SGPath& operator= ( const char* p ) { this->set(p); return *this; } | |||
bool operator==(const SGPath& other) const; | ||||
bool operator!=(const SGPath& other) const; | ||||
/** | ||||
* Set if file information (exists, type, mod-time) is cached or | ||||
* retrieved each time it is queried. Caching is enabled by default | ||||
*/ | ||||
void set_cached(bool cached); | ||||
/** | /** | |||
* Append another piece to the existing path. Inserts a path | * Append another piece to the existing path. Inserts a path | |||
* separator between the existing component and the new component. | * separator between the existing component and the new component. | |||
* @param p additional path component */ | * @param p additional path component */ | |||
void append( const string& p ); | void append( const std::string& p ); | |||
/** | ||||
* Get a copy of this path with another piece appended. | ||||
* | ||||
* @param p additional path component | ||||
*/ | ||||
SGPath operator/( const std::string& p ) const; | ||||
/** | /** | |||
* Append a new piece to the existing path. Inserts a search path | * Append a new piece to the existing path. Inserts a search path | |||
* separator to the existing path and the new patch component. | * separator to the existing path and the new patch component. | |||
* @param p additional path component */ | * @param p additional path component */ | |||
void add( const string& p ); | void add( const std::string& p ); | |||
/** | /** | |||
* Concatenate a string to the end of the path without inserting a | * Concatenate a string to the end of the path without inserting a | |||
* path separator. | * path separator. | |||
* @param p addtional path suffix | * @param p additional path suffix | |||
*/ | ||||
void concat( const std::string& p ); | ||||
/** | ||||
* Returns a string with the absolute pathname that names the same file | ||||
, whose | ||||
* resolution does not involve '.', '..', or symbolic links. | ||||
*/ | */ | |||
void concat( const string& p ); | std::string realpath() const; | |||
/** | /** | |||
* Get the file part of the path (everything after the last path sep) | * Get the file part of the path (everything after the last path sep) | |||
* @return file string | * @return file string | |||
*/ | */ | |||
string file() const; | std::string file() const; | |||
/** | /** | |||
* Get the directory part of the path. | * Get the directory part of the path. | |||
* @return directory string | * @return directory string | |||
*/ | */ | |||
string dir() const; | std::string dir() const; | |||
/** | /** | |||
* Get the base part of the path (everything but the extension.) | * Get the base part of the path (everything but the final extension.) | |||
* @return the base string | * @return the base string | |||
*/ | */ | |||
string base() const; | std::string base() const; | |||
/** | ||||
* Get the base part of the filename (everything before the first '.') | ||||
* @return the base filename | ||||
*/ | ||||
std::string file_base() const; | ||||
/** | ||||
* Get the extension part of the path (everything after the final ".") | ||||
* @return the extension string | ||||
*/ | ||||
std::string extension() const; | ||||
/** | ||||
* Get the extension part of the path (everything after the final ".") | ||||
* converted to lowercase | ||||
* @return the extension string | ||||
*/ | ||||
std::string lower_extension() const; | ||||
/** | /** | |||
* Get the extention part of the path (everything after the final ".") | * Get the complete extension part of the path (everything after the fi | |||
* @return the extention string | rst ".") | |||
* this might look like 'tar.gz' or 'txt.Z', or might be identical to ' | ||||
extension' above | ||||
* the extension is converted to lowercase. | ||||
* @return the extension string | ||||
*/ | */ | |||
string extension() const; | std::string complete_lower_extension() const; | |||
/** | /** | |||
* Get the path string | * Get the path string | |||
* @return path string | * @return path string | |||
*/ | */ | |||
string str() const { return path; } | std::string str() const { return path; } | |||
/** | /** | |||
* Get the path string | * Get the path string | |||
* @return path in "C" string (ptr to char array) form. | * @return path in "C" string (ptr to char array) form. | |||
*/ | */ | |||
const char* c_str() { return path.c_str(); } | const char* c_str() const { return path.c_str(); } | |||
/** | ||||
* Get the path string in OS native form | ||||
*/ | ||||
std::string str_native() const; | ||||
/** | /** | |||
* Determine if file exists by attempting to fopen it. | * Determine if file exists by attempting to fopen it. | |||
* @return true if file exists, otherwise returns false. | * @return true if file exists, otherwise returns false. | |||
*/ | */ | |||
bool exists() const; | bool exists() const; | |||
/** | /** | |||
* Create the designated directory. | * Create the designated directory. | |||
* @return 0 on success, or <0 on failure. | ||||
*/ | */ | |||
void create_dir(mode_t mode); | int create_dir(mode_t mode); | |||
bool isFile() const; | ||||
bool isDir() const; | ||||
/** | ||||
* Opposite sense to isAbsolute | ||||
*/ | ||||
bool isRelative() const { return !isAbsolute(); } | ||||
/** | ||||
* Is this an absolute path? | ||||
* I.e starts with a directory seperator, or a single character + colon | ||||
*/ | ||||
bool isAbsolute() const; | ||||
/** | ||||
* check for default constructed path | ||||
*/ | ||||
bool isNull() const; | ||||
/** | ||||
* delete the file, if possible | ||||
*/ | ||||
bool remove(); | ||||
/** | ||||
* modification time of the file | ||||
*/ | ||||
time_t modTime() const; | ||||
/** | ||||
* rename the file / directory we point at, to a new name | ||||
* this may fail if the new location is on a different volume / share, | ||||
* or if the destination already exists, or is not writeable | ||||
*/ | ||||
bool rename(const SGPath& newName); | ||||
/** | ||||
* Get a path stored in the environment variable with the given \a name | ||||
. | ||||
* | ||||
* @param name Name of the environment variable | ||||
* @param def Default path to return if the environment variable does | ||||
not | ||||
* exist or is empty. | ||||
*/ | ||||
static SGPath fromEnv(const char* name, const SGPath& def = SGPath()); | ||||
/** | ||||
* Get path to user's home directory | ||||
*/ | ||||
static SGPath home(); | ||||
/** | ||||
* Get path to the user's desktop directory | ||||
*/ | ||||
static SGPath desktop(); | ||||
private: | private: | |||
void fix(); | void fix(); | |||
void validate() const; | ||||
std::string path; | ||||
mutable bool _cached : 1; | ||||
bool _cacheEnabled : 1; ///< cacheing can be disbled if required | ||||
mutable bool _exists : 1; | ||||
mutable bool _isDir : 1; | ||||
mutable bool _isFile : 1; | ||||
mutable time_t _modTime; | ||||
}; | }; | |||
/// Output to an ostream | ||||
template<typename char_type, typename traits_type> | ||||
inline | ||||
std::basic_ostream<char_type, traits_type>& | ||||
operator<<(std::basic_ostream<char_type, traits_type>& s, const SGPath& p) | ||||
{ return s << "Path \"" << p.str() << "\""; } | ||||
/** | /** | |||
* Split a directory string into a list of it's parent directories. | * Split a directory string into a list of it's parent directories. | |||
*/ | */ | |||
string_list sgPathBranchSplit( const string &path ); | string_list sgPathBranchSplit( const std::string &path ); | |||
/** | /** | |||
* Split a directory search path into a vector of individual paths | * Split a directory search path into a vector of individual paths | |||
*/ | */ | |||
string_list sgPathSplit( const string &search_path ); | string_list sgPathSplit( const std::string &search_path ); | |||
#endif // _SG_PATH_HXX | #endif // _SG_PATH_HXX | |||
End of changes. 26 change blocks. | ||||
26 lines changed or deleted | 160 lines changed or added | |||
sg_random.h | sg_random.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_random.h,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_RANDOM_H | #ifndef _SG_RANDOM_H | |||
#define _SG_RANDOM_H | #define _SG_RANDOM_H | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
#define MT_N 624 | ||||
#define MT_M 397 | ||||
/** | ||||
* Structure to hold MT algorithm state to easily allow independant | ||||
* sets of random numbers with different seeds. | ||||
*/ | ||||
typedef struct {unsigned int array[MT_N]; int index; } mt; | ||||
/** | ||||
* Initialize a new MT state with a given seed. | ||||
*/ | ||||
void mt_init(mt *mt, unsigned int seed); | ||||
/** | ||||
* Initialize a new MT state with a seed that only | ||||
* changes every 10 minutes. Used to synchronize | ||||
* multi-process deployments. | ||||
*/ | ||||
void mt_init_time_10(mt *mt); | ||||
/** | ||||
* Generate a new 32-bit random number based on the given MT state. | ||||
*/ | ||||
unsigned int mt_rand32( mt *mt); | ||||
/** | ||||
* Generate a new random number between [0.0, 1.0) based | ||||
* on the given MT state. | ||||
*/ | ||||
double mt_rand(mt *mt); | ||||
/** | /** | |||
* Seed the random number generater with time() so we don't see the | * Seed the random number generater with time() so we don't see the | |||
* same sequence every time. | * same sequence every time. | |||
*/ | */ | |||
void sg_srandom_time(); | void sg_srandom_time(); | |||
/** | /** | |||
* Seed the random number generater with time() in 10 minute intervals | * Seed the random number generater with time() in 10 minute intervals | |||
* so we get the same sequence within 10 minutes interval. | * so we get the same sequence within 10 minutes interval. | |||
* This is useful for synchronizing two display systems. | * This is useful for synchronizing two display systems. | |||
*/ | */ | |||
void sg_srandom_time_10(); | void sg_srandom_time_10(); | |||
/** | /** | |||
* Seed the random number generater with your own seed so can set up | * Seed the random number generater with your own seed so can set up | |||
* repeatable randomization. | * repeatable randomization. | |||
* @param seed random number generator seed | * @param seed random number generator seed | |||
*/ | */ | |||
void sg_srandom( unsigned int seed ); | void sg_srandom(unsigned int seed ); | |||
/** | /** | |||
* Return a random number between [0.0, 1.0) | * Return a random number between [0.0, 1.0) | |||
* @return next "random" number in the "random" sequence | * @return next "random" number in the "random" sequence | |||
*/ | */ | |||
double sg_random(); | double sg_random(); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 34 lines changed or added | |||
sg_serial.hxx | sg_serial.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_serial.hxx,v 1.6 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_SERIAL_HXX | #ifndef _SG_SERIAL_HXX | |||
#define _SG_SERIAL_HXX | #define _SG_SERIAL_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <string> | #include <string> | |||
// #ifdef SG_HAVE_STD_INCLUDES | ||||
// # include <ctime> | ||||
// #else | ||||
// # include <time.h> | ||||
// #endif | ||||
#include <simgear/serial/serial.hxx> | #include <simgear/serial/serial.hxx> | |||
#include "iochannel.hxx" | #include "iochannel.hxx" | |||
SG_USING_STD(string); | ||||
/** | /** | |||
* A serial I/O class based on SGIOChannel. | * A serial I/O class based on SGIOChannel. | |||
*/ | */ | |||
class SGSerial : public SGIOChannel { | class SGSerial : public SGIOChannel { | |||
string device; | std::string device; | |||
string baud; | std::string baud; | |||
SGSerialPort port; | SGSerialPort port; | |||
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | |||
int save_len; | int save_len; | |||
public: | public: | |||
/** | /** | |||
* Create an instance of SGSerial. | * Create an instance of SGSerial. | |||
* This creates an instance of the SGSerial class. You need to | * This creates an instance of the SGSerial class. You need to | |||
* provide the serial device name and desired baud rate. For Unix | * provide the serial device name and desired baud rate. For Unix | |||
* style systems, device names will be similar to | * style systems, device names will be similar to | |||
* ``/dev/ttyS0''. For DOS style systems you may want to use | * ``/dev/ttyS0''. For DOS style systems you may want to use | |||
* something similar to ``COM1:''. As with the SGFile class, | * something similar to ``COM1:''. As with the SGFile class, | |||
* device is not opened immediately, but instead will be opened | * device is not opened immediately, but instead will be opened | |||
* when the open() method is called. | * when the open() method is called. | |||
* @param device_name name of serial device | * @param device_name name of serial device | |||
* @param baud_rate speed of communication | * @param baud_rate speed of communication | |||
*/ | */ | |||
SGSerial( const string& device_name, const string& baud_rate ); | SGSerial( const std::string& device_name, const std::string& baud_rate ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGSerial(); | ~SGSerial(); | |||
// open the serial port based on specified direction | // open the serial port based on specified direction | |||
bool open( const SGProtocolDir d ); | bool open( const SGProtocolDir d ); | |||
// read a block of data of specified size | // read a block of data of specified size | |||
int read( char *buf, int length ); | int read( char *buf, int length ); | |||
End of changes. 5 change blocks. | ||||
12 lines changed or deleted | 4 lines changed or added | |||
sg_socket.hxx | sg_socket.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_socket.hxx,v 1.6 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_SOCKET_HXX | #ifndef _SG_SOCKET_HXX | |||
#define _SG_SOCKET_HXX | #define _SG_SOCKET_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
#include <simgear/io/iochannel.hxx> | #include <simgear/io/iochannel.hxx> | |||
#include <simgear/io/raw_socket.hxx> | ||||
#include <plib/netSocket.h> | ||||
SG_USING_STD(string); | ||||
#define SG_MAX_SOCKET_QUEUE 32 | #define SG_MAX_SOCKET_QUEUE 32 | |||
/** | /** | |||
* A socket I/O class based on SGIOChannel. | * A socket I/O class based on SGIOChannel. | |||
*/ | */ | |||
class SGSocket : public SGIOChannel { | class SGSocket : public SGIOChannel { | |||
public: | public: | |||
private: | private: | |||
string hostname; | std::string hostname; | |||
string port_str; | std::string port_str; | |||
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | |||
int save_len; | int save_len; | |||
netSocket sock; | simgear::Socket sock; | |||
netSocket* client; | simgear::Socket* client; | |||
unsigned short port; | unsigned short port; | |||
bool is_tcp; | bool is_tcp; | |||
bool is_server; | bool is_server; | |||
bool first_read; | bool first_read; | |||
int timeout; | int timeout; | |||
static bool init; | static bool init; | |||
// make a server (master listening) socket | // make a server (master listening) socket | |||
bool make_server_socket(); | bool make_server_socket(); | |||
skipping to change at line 126 | skipping to change at line 119 | |||
* efficient. UDP packets are good for sending positional | * efficient. UDP packets are good for sending positional | |||
* information to synchronize two applications. In this case, you | * information to synchronize two applications. In this case, you | |||
* want the information to arrive as quickly as possible, and if | * want the information to arrive as quickly as possible, and if | |||
* you lose a packet, you'd rather get new updated information | * you lose a packet, you'd rather get new updated information | |||
* rather than have the system waste time resending a packet that | * rather than have the system waste time resending a packet that | |||
* is becoming older and older with every retry. | * is becoming older and older with every retry. | |||
* @param host name of host if direction is SG_IO_OUT or SG_IO_BI | * @param host name of host if direction is SG_IO_OUT or SG_IO_BI | |||
* @param port port number if we care to choose one. | * @param port port number if we care to choose one. | |||
* @param style specify "udp" or "tcp" | * @param style specify "udp" or "tcp" | |||
*/ | */ | |||
SGSocket( const string& host, const string& port, const string& style ) ; | SGSocket( const std::string& host, const std::string& port, const std:: string& style ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGSocket(); | ~SGSocket(); | |||
// If specified as a server (in direction for now) open the master | // If specified as a server (in direction for now) open the master | |||
// listening socket. If specified as a client (out direction), | // listening socket. If specified as a client (out direction), | |||
// open a connection to a server. | // open a connection to a server. | |||
bool open( const SGProtocolDir d ); | bool open( const SGProtocolDir d ); | |||
// read data from socket | // read data from socket | |||
skipping to change at line 161 | skipping to change at line 154 | |||
/** | /** | |||
* Enable non-blocking mode. | * Enable non-blocking mode. | |||
* @return success/failure | * @return success/failure | |||
*/ | */ | |||
bool nonblock(); | bool nonblock(); | |||
// set timeout (default: 0) | // set timeout (default: 0) | |||
inline void set_timeout(int i) { timeout = i; } | inline void set_timeout(int i) { timeout = i; } | |||
/** @return the remote host name */ | /** @return the remote host name */ | |||
inline string get_hostname() const { return hostname; } | inline std::string get_hostname() const { return hostname; } | |||
/** @return the port number (in string form) */ | /** @return the port number (in string form) */ | |||
inline string get_port_str() const { return port_str; } | inline std::string get_port_str() const { return port_str; } | |||
}; | }; | |||
#endif // _SG_SOCKET_HXX | #endif // _SG_SOCKET_HXX | |||
End of changes. 9 change blocks. | ||||
17 lines changed or deleted | 10 lines changed or added | |||
sg_socket_udp.hxx | sg_socket_udp.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_socket_udp.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_SOCKET_UDP_HXX | #ifndef _SG_SOCKET_UDP_HXX | |||
#define _SG_SOCKET_UDP_HXX | #define _SG_SOCKET_UDP_HXX | |||
#ifndef __cplusplus | ||||
# error This library requires C++ | ||||
#endif | ||||
#include <plib/netSocket.h> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
#include <simgear/io/iochannel.hxx> | #include <simgear/io/iochannel.hxx> | |||
#include <simgear/io/raw_socket.hxx> | ||||
SG_USING_STD(string); | ||||
/** | /** | |||
* A UDP socket I/O class based on SGIOChannel and plib/net. | * A UDP socket I/O class based on SGIOChannel and plib/net. | |||
*/ | */ | |||
class SGSocketUDP : public SGIOChannel { | class SGSocketUDP : public SGIOChannel { | |||
private: | private: | |||
netSocket sock; | simgear::Socket sock; | |||
string hostname; | std::string hostname; | |||
string port_str; | std::string port_str; | |||
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ]; | |||
int save_len; | int save_len; | |||
short unsigned int port; | short unsigned int port; | |||
public: | public: | |||
/** | /** | |||
* Create an instance of SGSocketUDP. | * Create an instance of SGSocketUDP. | |||
skipping to change at line 97 | skipping to change at line 90 | |||
* lack of error checking, UDP packets are much faster and | * lack of error checking, UDP packets are much faster and | |||
* efficient. UDP packets are good for sending positional | * efficient. UDP packets are good for sending positional | |||
* information to synchronize two applications. In this case, you | * information to synchronize two applications. In this case, you | |||
* want the information to arrive as quickly as possible, and if | * want the information to arrive as quickly as possible, and if | |||
* you lose a packet, you'd rather get new updated information | * you lose a packet, you'd rather get new updated information | |||
* rather than have the system waste time resending a packet that | * rather than have the system waste time resending a packet that | |||
* is becoming older and older with every retry. | * is becoming older and older with every retry. | |||
* @param host name of host if direction is SG_IO_OUT or SG_IO_BI | * @param host name of host if direction is SG_IO_OUT or SG_IO_BI | |||
* @param port port number if we care to choose one. | * @param port port number if we care to choose one. | |||
* @param style specify "udp" or "tcp" */ | * @param style specify "udp" or "tcp" */ | |||
SGSocketUDP( const string& host, const string& port ); | SGSocketUDP( const std::string& host, const std::string& port ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGSocketUDP(); | ~SGSocketUDP(); | |||
// If specified as a server (in direction for now) open the master | // If specified as a server (in direction for now) open the master | |||
// listening socket. If specified as a client (out direction), | // listening socket. If specified as a client (out direction), | |||
// open a connection to a server. | // open a connection to a server. | |||
bool open( const SGProtocolDir d ); | bool open( const SGProtocolDir d ); | |||
// read data from socket | // read data from socket | |||
skipping to change at line 129 | skipping to change at line 122 | |||
// close file | // close file | |||
bool close(); | bool close(); | |||
/** | /** | |||
* Set blocking true or false | * Set blocking true or false | |||
* @return success/failure | * @return success/failure | |||
*/ | */ | |||
bool setBlocking( bool value ); | bool setBlocking( bool value ); | |||
/** @return the remote host name */ | /** @return the remote host name */ | |||
inline string get_hostname() const { return hostname; } | inline std::string get_hostname() const { return hostname; } | |||
/** @return the port number (in string form) */ | /** @return the port number (in string form) */ | |||
inline string get_port_str() const { return port_str; } | inline std::string get_port_str() const { return port_str; } | |||
}; | }; | |||
#endif // _SG_SOCKET_UDP_HXX | #endif // _SG_SOCKET_UDP_HXX | |||
End of changes. 9 change blocks. | ||||
16 lines changed or deleted | 9 lines changed or added | |||
sg_time.hxx | sg_time.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_time.hxx,v 1.9.2.1 2007-10-13 08:16:50 durk Exp $ | // $Id$ | |||
#ifndef _SG_TIME_HXX | #ifndef _SG_TIME_HXX | |||
#define _SG_TIME_HXX | #define _SG_TIME_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#ifdef SG_HAVE_STD_INCLUDES | #include <ctime> | |||
# include <ctime> | #include <memory> // for std::auto_ptr | |||
#else | #include <string> | |||
# include <time.h> | ||||
#endif | // forward decls | |||
class SGPath; | ||||
#include <simgear/timing/timezone.h> | class SGGeod; | |||
/** | /** | |||
* A class to calculate and manage a variety of time parameters. | * A class to calculate and manage a variety of time parameters. | |||
* The SGTime class provides many real-world time values. It | * The SGTime class provides many real-world time values. It | |||
* calculates current time in seconds, GMT time, local time zone, | * calculates current time in seconds, GMT time, local time zone, | |||
* local offset in seconds from GMT, Julian date, and sidereal | * local offset in seconds from GMT, Julian date, and sidereal | |||
* time. All of these operate with seconds as their granularity so | * time. All of these operate with seconds as their granularity so | |||
* this class is not intended for timing sub-second events. These | * this class is not intended for timing sub-second events. These | |||
* values are intended as input to things like real world lighting | * values are intended as input to things like real world lighting | |||
* calculations and real astronomical object placement. | * calculations and real astronomical object placement. | |||
skipping to change at line 66 | skipping to change at line 66 | |||
* method. Optionally, if you care about updating time zone | * method. Optionally, if you care about updating time zone | |||
* information based on your latitude and longitude, you can call the | * information based on your latitude and longitude, you can call the | |||
* updateLocal() method periodically as your position changes by | * updateLocal() method periodically as your position changes by | |||
* significant amounts. | * significant amounts. | |||
*/ | */ | |||
class SGTime { | class SGTime { | |||
private: | private: | |||
// tzContainer stores all the current Timezone control points/ | ||||
SGTimeZoneContainer* tzContainer; | ||||
// Points to the current local timezone name; | // Points to the current local timezone name; | |||
string zonename; | std::string zonename; | |||
// Unix "calendar" time in seconds | // Unix "calendar" time in seconds | |||
time_t cur_time; | time_t cur_time; | |||
// Break down of equivalent GMT time | // Break down of equivalent GMT time | |||
#if defined(_MSC_VER) || defined(__MINGW32__) | ||||
struct tm m_gmt; // copy of system gmtime(&time_t) structure | struct tm m_gmt; // copy of system gmtime(&time_t) structure | |||
#else | ||||
struct tm *gmt; | ||||
#endif | ||||
// offset of local time relative to GMT | // offset of local time relative to GMT | |||
time_t local_offset; | time_t local_offset; | |||
// Julian date | // Julian date | |||
double jd; | double jd; | |||
// modified Julian date | // modified Julian date | |||
double mjd; | double mjd; | |||
skipping to change at line 103 | skipping to change at line 97 | |||
// local sidereal time | // local sidereal time | |||
double lst; | double lst; | |||
// the difference between the precise / expensive sidereal time | // the difference between the precise / expensive sidereal time | |||
// algorithm result and the quick course result. course_gst + | // algorithm result and the quick course result. course_gst + | |||
// gst_diff has pretty good accuracy over the span of a couple hours | // gst_diff has pretty good accuracy over the span of a couple hours | |||
double gst_diff; | double gst_diff; | |||
/** init common constructor code */ | /** init common constructor code */ | |||
void init( double lon_rad, double lat_rad, const string& root, | void init( const SGGeod& location, const SGPath& root, | |||
time_t init_time ); | time_t init_time ); | |||
public: | public: | |||
/** Default constructor */ | /** Default constructor */ | |||
SGTime(); | SGTime(); | |||
/** | /** | |||
* Create an instance based on a specified position and data file path. | * Create an instance based on a specified position and data file path. | |||
* This creates an instance of the SGTime object. When calling the | * This creates an instance of the SGTime object. When calling the | |||
skipping to change at line 127 | skipping to change at line 121 | |||
* latitude in radians. | * latitude in radians. | |||
* | * | |||
* If you don't know your position when you call the SGTime | * If you don't know your position when you call the SGTime | |||
* constructor, you can just use the first form (which assumes 0, | * constructor, you can just use the first form (which assumes 0, | |||
* 0). | * 0). | |||
* @param lon_rad current longitude (radians) | * @param lon_rad current longitude (radians) | |||
* @param lat_rad current latitude (radians) | * @param lat_rad current latitude (radians) | |||
* @param root root path point to data file location (timezone, etc.) | * @param root root path point to data file location (timezone, etc.) | |||
* @param init_time provide an initialization time, 0 means use | * @param init_time provide an initialization time, 0 means use | |||
current clock time */ | current clock time */ | |||
SGTime( double lon_rad, double lat_rad, const string& root, | SGTime( const SGGeod& location, const SGPath& root, | |||
time_t init_time ); | time_t init_time ); | |||
/** | /** | |||
* Create an instance given a data file path. | * Create an instance given a data file path. | |||
* @param root root path point to data file location (timezone, etc.) | * @param root root path point to data file location (timezone, etc.) | |||
*/ | */ | |||
SGTime( const string& root ); | SGTime( const SGPath& root ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGTime(); | ~SGTime(); | |||
/** | /** | |||
* Update the time related variables. | * Update the time related variables. | |||
* The update() method requires you to pass in your position and | * The update() method requires you to pass in your position and | |||
* an optional time offset in seconds. The offset (or warp) allows | * an optional time offset in seconds. The offset (or warp) allows | |||
* you to offset "sim" time relative to "real" time. The update() | * you to offset "sim" time relative to "real" time. The update() | |||
* method is designed to be called by the host application before | * method is designed to be called by the host application before | |||
* every frame. | * every frame. | |||
* @param lon_rad current longitude (radians) | * @param lon_rad current longitude (radians) | |||
* @param lat_rad current latitude (radians) | * @param lat_rad current latitude (radians) | |||
* @param ct specify a unix time, otherwise specify 0 to use current | * @param ct specify a unix time, otherwise specify 0 to use current | |||
clock time | clock time | |||
* @param warp an optional time offset specified in seconds. This | * @param warp an optional time offset specified in seconds. This | |||
* allows us to advance or rewind "time" if we choose to. */ | * allows us to advance or rewind "time" if we choose to. */ | |||
void update( double lon_rad, double lat_rad, time_t ct, long int warp ) | void update( const SGGeod& location, time_t ct, long int warp ); | |||
; | ||||
/** Deprecated method. To be removed after the next release... */ | ||||
void update( double lon_rad, double lat_rad, time_t ct, long int warp ) | ||||
DEPRECATED; | ||||
/** | /** | |||
* Given lon/lat, update timezone information and local_offset | * Given lon/lat, update timezone information and local_offset | |||
* The updateLocal() method is intended to be called less | * The updateLocal() method is intended to be called less | |||
* frequently - only when your position is likely to be changed | * frequently - only when your position is likely to be changed | |||
* enough that your timezone may have changed as well. In the | * enough that your timezone may have changed as well. In the | |||
* FlightGear project we call updateLocal() every few minutes from | * FlightGear project we call updateLocal() every few minutes from | |||
* our periodic event manager. | * our periodic event manager. | |||
* @param lon_rad current longitude (radians) | * @param lon_rad current longitude (radians) | |||
* @param lat_rad current latitude (radians) | * @param lat_rad current latitude (radians) | |||
* @param root base path containing time zone directory */ | * @param root base path containing time zone directory */ | |||
void updateLocal( double lon_rad, double lat_rad, const string& root ); | void updateLocal( const SGGeod& location, const std::string& root ); | |||
/** @return current system/unix time in seconds */ | /** @return current system/unix time in seconds */ | |||
inline time_t get_cur_time() const { return cur_time; }; | inline time_t get_cur_time() const { return cur_time; }; | |||
/** @return time zone name for your current position*/ | /** @return time zone name for your current position*/ | |||
inline const char * get_zonename() const { return zonename.c_str(); } | inline const char * get_zonename() const { return zonename.c_str(); } | |||
/** @return GMT in a "brokent down" tm structure */ | /** @return GMT in a "brokent down" tm structure */ | |||
#if defined(_MSC_VER) || defined(__MINGW32__) | ||||
inline struct tm* getGmt()const { return (struct tm *)&m_gmt; }; | inline struct tm* getGmt()const { return (struct tm *)&m_gmt; }; | |||
#else | ||||
inline struct tm* getGmt()const { return gmt; }; | ||||
#endif | ||||
/** @return julian date */ | /** @return julian date */ | |||
inline double getJD() const { return jd; }; | inline double getJD() const { return jd; }; | |||
/** @return modified julian date */ | /** @return modified julian date */ | |||
inline double getMjd() const { return mjd; }; | inline double getMjd() const { return mjd; }; | |||
/** @return local side real time */ | /** @return local side real time */ | |||
inline double getLst() const { return lst; }; | inline double getLst() const { return lst; }; | |||
skipping to change at line 265 | skipping to change at line 258 | |||
* @return greenwich mean sidereal time (gst) */ | * @return greenwich mean sidereal time (gst) */ | |||
double sgTimeCalcGST( double mjd ); | double sgTimeCalcGST( double mjd ); | |||
/** | /** | |||
* \relates SGTime | * \relates SGTime | |||
* Format time in a pretty form | * Format time in a pretty form | |||
* @param p time specified in a tm struct | * @param p time specified in a tm struct | |||
* @param buf buffer space to contain the result | * @param buf buffer space to contain the result | |||
* @return pointer to character array containt the result | * @return pointer to character array containt the result | |||
*/ | */ | |||
char* sgTimeFormatTime( const struct tm* p, char* buf , int size); | char* sgTimeFormatTime( const struct tm* p, char* buf ); | |||
#endif // _SG_TIME_HXX | #endif // _SG_TIME_HXX | |||
End of changes. 14 change blocks. | ||||
27 lines changed or deleted | 20 lines changed or added | |||
sg_types.hxx | sg_types.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sg_types.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_TYPES_HXX | #ifndef _SG_TYPES_HXX | |||
#define _SG_TYPES_HXX | #define _SG_TYPES_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <vector> | #include <vector> | |||
#include <simgear/math/point3d.hxx> | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(string); | ||||
/** STL vector list of ints */ | /** STL vector list of ints */ | |||
typedef vector < int > int_list; | typedef std::vector < int > int_list; | |||
typedef int_list::iterator int_list_iterator; | typedef int_list::iterator int_list_iterator; | |||
typedef int_list::const_iterator const_int_list_iterator; | typedef int_list::const_iterator const_int_list_iterator; | |||
/** STL vector list of doubles */ | /** STL vector list of doubles */ | |||
typedef vector < double > double_list; | typedef std::vector < double > double_list; | |||
typedef double_list::iterator double_list_iterator; | typedef double_list::iterator double_list_iterator; | |||
typedef double_list::const_iterator const_double_list_iterator; | typedef double_list::const_iterator const_double_list_iterator; | |||
/** STL vector list of Point3D */ | ||||
typedef vector < Point3D > point_list; | ||||
typedef point_list::iterator point_list_iterator; | ||||
typedef point_list::const_iterator const_point_list_iterator; | ||||
/** STL vector list of strings */ | /** STL vector list of strings */ | |||
typedef vector < string > string_list; | typedef std::vector < std::string > string_list; | |||
typedef string_list::iterator string_list_iterator; | typedef string_list::iterator string_list_iterator; | |||
typedef string_list::const_iterator const_string_list_iterator; | typedef string_list::const_iterator const_string_list_iterator; | |||
/** | ||||
* Simple 2d point class where members can be accessed as x, dist, or lon | ||||
* and y, theta, or lat | ||||
*/ | ||||
class point2d { | ||||
public: | ||||
union { | ||||
double x; | ||||
double dist; | ||||
double lon; | ||||
}; | ||||
union { | ||||
double y; | ||||
double theta; | ||||
double lat; | ||||
}; | ||||
}; | ||||
#endif // _SG_TYPES_HXX | #endif // _SG_TYPES_HXX | |||
End of changes. 8 change blocks. | ||||
33 lines changed or deleted | 5 lines changed or added | |||
sgstream.hxx | sgstream.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sgstream.hxx,v 1.3 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SGSTREAM_HXX | #ifndef _SGSTREAM_HXX | |||
#define _SGSTREAM_HXX | #define _SGSTREAM_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#if defined( SG_HAVE_STD_INCLUDES ) | ||||
# include <istream> | # include <istream> | |||
#elif defined ( __BORLANDC__ ) | # include <ostream> | |||
# include <iostream> | ||||
#else | ||||
# include <istream.h> | ||||
#endif | ||||
#include STL_STRING | #include <string> | |||
#include <simgear/misc/zfstream.hxx> | #include <simgear/misc/zfstream.hxx> | |||
SG_USING_STD(string); | ||||
SG_USING_STD(istream); | ||||
/** | /** | |||
* An envelope class for gzifstream. | * An envelope class for gzifstream. | |||
*/ | */ | |||
class sg_gzifstream : private gzifstream_base, public istream | class sg_gzifstream : private gzifstream_base, public std::istream | |||
{ | { | |||
public: | public: | |||
/** Default constructor */ | /** Default constructor */ | |||
sg_gzifstream(); | sg_gzifstream(); | |||
/** | /** | |||
* Constructor that attempt to open a file with and without | * Constructor that attempt to open a file with and without | |||
* ".gz" extension. | * ".gz" extension. | |||
* @param name name of file | * @param name name of file | |||
* @param io_mode file open mode(s) "or'd" together | * @param io_mode file open mode(s) "or'd" together | |||
*/ | */ | |||
sg_gzifstream( const string& name, | sg_gzifstream( const std::string& name, | |||
ios_openmode io_mode = ios_in | ios_binary ); | ios_openmode io_mode = ios_in | ios_binary ); | |||
/** | /** | |||
* Constructor that attaches itself to an existing file descriptor. | * Constructor that attaches itself to an existing file descriptor. | |||
* @param fd file descriptor | * @param fd file descriptor | |||
* @param io_mode file open mode(s) "or'd" together | * @param io_mode file open mode(s) "or'd" together | |||
*/ | */ | |||
sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary ); | sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary ); | |||
/** | /** | |||
* Attempt to open a file with and without ".gz" extension. | * Attempt to open a file with and without ".gz" extension. | |||
* @param name name of file | * @param name name of file | |||
* @param io_mode file open mode(s) "or'd" together | * @param io_mode file open mode(s) "or'd" together | |||
*/ | */ | |||
void open( const string& name, | void open( const std::string& name, | |||
ios_openmode io_mode = ios_in|ios_binary ); | ios_openmode io_mode = ios_in|ios_binary ); | |||
/** | /** | |||
* Attach to an existing file descriptor. | * Attach to an existing file descriptor. | |||
* @param fd file descriptor | * @param fd file descriptor | |||
* @param io_mode file open mode(s) "or'd" together | * @param io_mode file open mode(s) "or'd" together | |||
*/ | */ | |||
void attach( int fd, ios_openmode io_mode = ios_in|ios_binary ); | void attach( int fd, ios_openmode io_mode = ios_in|ios_binary ); | |||
/** | /** | |||
skipping to change at line 109 | skipping to change at line 101 | |||
// Not defined! | // Not defined! | |||
sg_gzifstream( const sg_gzifstream& ); | sg_gzifstream( const sg_gzifstream& ); | |||
void operator= ( const sg_gzifstream& ); | void operator= ( const sg_gzifstream& ); | |||
}; | }; | |||
/** | /** | |||
* \relates sg_gzifstream | * \relates sg_gzifstream | |||
* An istream manipulator that skips to end of line. | * An istream manipulator that skips to end of line. | |||
* @param in input stream | * @param in input stream | |||
*/ | */ | |||
istream& skipeol( istream& in ); | std::istream& skipeol( std::istream& in ); | |||
/** | /** | |||
* \relates sg_gzifstream | * \relates sg_gzifstream | |||
* An istream manipulator that skips over white space. | * An istream manipulator that skips over white space. | |||
* @param in input stream | * @param in input stream | |||
*/ | */ | |||
istream& skipws( istream& in ); | std::istream& skipws( std::istream& in ); | |||
/** | /** | |||
* \relates sg_gzifstream | * \relates sg_gzifstream | |||
* An istream manipulator that skips comments and white space. | * An istream manipulator that skips comments and white space. | |||
* Ignores comments that start with '#'. | * Ignores comments that start with '#'. | |||
* @param in input stream | * @param in input stream | |||
*/ | */ | |||
istream& skipcomment( istream& in ); | std::istream& skipcomment( std::istream& in ); | |||
/** | ||||
* An envelope class for gzofstream. | ||||
*/ | ||||
class sg_gzofstream : private gzofstream_base, public std::ostream | ||||
{ | ||||
public: | ||||
/** Default constructor */ | ||||
sg_gzofstream(); | ||||
/** | ||||
* Constructor to open a file for writing. | ||||
* @param name name of file | ||||
* @param io_mode file open mode(s) "or'd" together | ||||
*/ | ||||
sg_gzofstream( const std::string& name, | ||||
ios_openmode io_mode = ios_out | ios_binary ); | ||||
/** | ||||
* Constructor that attaches itself to an existing file descriptor. | ||||
* @param fd file descriptor | ||||
* @param io_mode file open mode(s) "or'd" together | ||||
*/ | ||||
sg_gzofstream( int fd, ios_openmode io_mode = ios_out|ios_binary ); | ||||
/** | ||||
* Attempt to open a file for writing. | ||||
* @param name name of file | ||||
* @param io_mode file open mode(s) "or'd" together | ||||
*/ | ||||
void open( const std::string& name, | ||||
ios_openmode io_mode = ios_out|ios_binary ); | ||||
/** | ||||
* Attach to an existing file descriptor. | ||||
* @param fd file descriptor | ||||
* @param io_mode file open mode(s) "or'd" together | ||||
*/ | ||||
void attach( int fd, ios_openmode io_mode = ios_out|ios_binary ); | ||||
/** | ||||
* Close the stream. | ||||
*/ | ||||
void close() { gzbuf.close(); } | ||||
/** @return true if the file is successfully opened, false otherwise. * | ||||
/ | ||||
bool is_open() { return gzbuf.is_open(); } | ||||
private: | ||||
// Not defined! | ||||
sg_gzofstream( const sg_gzofstream& ); | ||||
void operator= ( const sg_gzofstream& ); | ||||
}; | ||||
#endif /* _SGSTREAM_HXX */ | #endif /* _SGSTREAM_HXX */ | |||
End of changes. 11 change blocks. | ||||
17 lines changed or deleted | 63 lines changed or added | |||
sky.hxx | sky.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sky.hxx,v 1.18 2006-07-27 05:15:20 durk Exp $ | // $Id$ | |||
#ifndef _SG_SKY_HXX | #ifndef _SG_SKY_HXX | |||
#define _SG_SKY_HXX | #define _SG_SKY_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <plib/ssg.h> // plib include | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/math/sg_random.h> | ||||
#include <simgear/misc/sg_path.hxx> | #include <simgear/misc/sg_path.hxx> | |||
#include <simgear/props/props.hxx> | #include <simgear/props/props.hxx> | |||
#include <vector> | #include <vector> | |||
#include <osg/ref_ptr> | ||||
#include <osg/MatrixTransform> | ||||
#include <osg/Node> | ||||
#include <osg/Switch> | ||||
#include <simgear/ephemeris/ephemeris.hxx> | ||||
#include <simgear/math/SGMath.hxx> | ||||
#include <simgear/scene/sky/cloud.hxx> | #include <simgear/scene/sky/cloud.hxx> | |||
#include <simgear/scene/sky/dome.hxx> | #include <simgear/scene/sky/dome.hxx> | |||
#include <simgear/scene/sky/moon.hxx> | #include <simgear/scene/sky/moon.hxx> | |||
#include <simgear/scene/sky/oursun.hxx> | #include <simgear/scene/sky/oursun.hxx> | |||
#include <simgear/scene/sky/stars.hxx> | #include <simgear/scene/sky/stars.hxx> | |||
SG_USING_STD(vector); | namespace simgear { | |||
class SGReaderWriterOptions; | ||||
typedef vector < SGCloudLayer* > layer_list_type; | } | |||
typedef layer_list_type::iterator layer_list_iterator; | ||||
typedef layer_list_type::const_iterator layer_list_const_iterator; | ||||
typedef struct { | typedef struct { | |||
float *view_pos, *zero_elev, *view_up; | SGVec3d pos; | |||
double lon, lat, alt, spin; | SGGeod pos_geod; | |||
SGQuatd ori; | ||||
double spin; | ||||
double gst; | double gst; | |||
double sun_ra, sun_dec, sun_dist; | double sun_dist; | |||
double moon_ra, moon_dec, moon_dist; | double moon_dist; | |||
double sun_angle; | double sun_angle; | |||
} SGSkyState; | } SGSkyState; | |||
typedef struct { | typedef struct { | |||
float *sky_color, *fog_color, *cloud_color; | SGVec3f sky_color; | |||
SGVec3f adj_sky_color; | ||||
SGVec3f fog_color; | ||||
SGVec3f cloud_color; | ||||
double sun_angle, moon_angle; | double sun_angle, moon_angle; | |||
int nplanets, nstars; | ||||
sgdVec3 *planet_data, *star_data; | ||||
} SGSkyColor; | } SGSkyColor; | |||
/** | /** | |||
* A class to model a realistic (time/date/position) based sky. | * A class to model a realistic (time/date/position) based sky. | |||
* | * | |||
* Introduction | * Introduction | |||
* | * | |||
* The SGSky class models a blended sky dome, a haloed sun, a textured | * The SGSky class models a blended sky dome, a haloed sun, a textured | |||
* moon with phase that properly matches the date, stars and planets, | * moon with phase that properly matches the date, stars and planets, | |||
* and cloud layers. SGSky is designed to be dropped into existing | * and cloud layers. SGSky is designed to be dropped into existing | |||
skipping to change at line 204 | skipping to change at line 212 | |||
* are a couple accessor methods you can use such as get_num_layers() | * are a couple accessor methods you can use such as get_num_layers() | |||
* to return the number of cloud layers, get_cloud_layer(i) to return | * to return the number of cloud layers, get_cloud_layer(i) to return | |||
* cloud layer number i, get_visibility() to return the actual | * cloud layer number i, get_visibility() to return the actual | |||
* visibility as modified by the sky/cloud model. | * visibility as modified by the sky/cloud model. | |||
*/ | */ | |||
class SGSky { | class SGSky { | |||
private: | private: | |||
typedef std::vector<SGSharedPtr<SGCloudLayer> > layer_list_type; | ||||
typedef layer_list_type::iterator layer_list_iterator; | ||||
typedef layer_list_type::const_iterator layer_list_const_iterator; | ||||
// components of the sky | // components of the sky | |||
SGSkyDome *dome; | SGSharedPtr<SGSkyDome> dome; | |||
SGSun *oursun; | SGSharedPtr<SGSun> oursun; | |||
SGMoon *moon; | SGSharedPtr<SGMoon> moon; | |||
SGStars *planets; | SGSharedPtr<SGStars> planets; | |||
SGStars *stars; | SGSharedPtr<SGStars> stars; | |||
layer_list_type cloud_layers; | layer_list_type cloud_layers; | |||
ssgRoot *pre_root, *post_root; | osg::ref_ptr<osg::Group> pre_root, cloud_root; | |||
osg::ref_ptr<osg::Switch> pre_selector; | ||||
osg::ref_ptr<osg::Group> pre_transform; | ||||
ssgSelector *pre_selector, *post_selector; | osg::ref_ptr<osg::MatrixTransform> _ephTransform; | |||
ssgTransform *pre_transform, *post_transform; | ||||
SGPath tex_path; | SGPath tex_path; | |||
// visibility | // visibility | |||
float visibility; | float visibility; | |||
float effective_visibility; | float effective_visibility; | |||
float minimum_sky_visibility; | ||||
int in_cloud; | int in_cloud; | |||
int cur_layer_pos; | int cur_layer_pos; | |||
// near cloud visibility state variables | // near cloud visibility state variables | |||
bool in_puff; | bool in_puff; | |||
double puff_length; // in seconds | double puff_length; // in seconds | |||
double puff_progression; // in seconds | double puff_progression; // in seconds | |||
double ramp_up; // in seconds | double ramp_up; // in seconds | |||
double ramp_down; // in seconds | double ramp_down; // in seconds | |||
// 3D clouds enabled | ||||
bool clouds_3d_enabled; | ||||
// 3D cloud density | ||||
double clouds_3d_density; | ||||
// RNG seed | ||||
mt seed; | ||||
public: | public: | |||
/** Constructor */ | /** Constructor */ | |||
SGSky( void ); | SGSky( void ); | |||
/** Destructor */ | /** Destructor */ | |||
~SGSky( void ); | ~SGSky( void ); | |||
/** | /** | |||
* Initialize the sky and connect the components to the scene | * Initialize the sky and connect the components to the scene | |||
skipping to change at line 259 | skipping to change at line 281 | |||
* @param moon_size size of moon | * @param moon_size size of moon | |||
* @param nplanets number of planets | * @param nplanets number of planets | |||
* @param planet_data an array of planet right ascensions, declinations , | * @param planet_data an array of planet right ascensions, declinations , | |||
* and magnitudes | * and magnitudes | |||
* @param nstars number of stars | * @param nstars number of stars | |||
* @param star_data an array of star right ascensions, declinations, | * @param star_data an array of star right ascensions, declinations, | |||
* and magnitudes | * and magnitudes | |||
*/ | */ | |||
void build( double h_radius_m, double v_radius_m, | void build( double h_radius_m, double v_radius_m, | |||
double sun_size, double moon_size, | double sun_size, double moon_size, | |||
int nplanets, sgdVec3 *planet_data, | const SGEphemeris& eph, SGPropertyNode *property_tree_node, | |||
int nstars, sgdVec3 *star_data, SGPropertyNode *property_tre | simgear::SGReaderWriterOptions* options); | |||
e_node ); | ||||
/** | /** | |||
* Repaint the sky components based on current value of sun_angle, | * Repaint the sky components based on current value of sun_angle, | |||
* sky, and fog colors. You can also specify new star and planet | * sky, and fog colors. You can also specify new star and planet | |||
* data so that we can optionally change the magnitude of these | * data so that we can optionally change the magnitude of these | |||
* (for day/night transitions.) See discussion in detailed | * (for day/night transitions.) See discussion in detailed | |||
* class description. | * class description. | |||
* | * | |||
* Sun and moon angles are specified in degrees relative to local up | * Sun and moon angles are specified in degrees relative to local up | |||
* <li> 0 degrees = high noon | * <li> 0 degrees = high noon | |||
skipping to change at line 286 | skipping to change at line 308 | |||
* effects) | * effects) | |||
* @param moon_angle the moon angle (so we can make it more yellow | * @param moon_angle the moon angle (so we can make it more yellow | |||
* at the horizon) | * at the horizon) | |||
* @param nplanets number of planets | * @param nplanets number of planets | |||
* @param planet_data an array of planet right ascensions, declinations , | * @param planet_data an array of planet right ascensions, declinations , | |||
* and magnitudes | * and magnitudes | |||
* @param nstars number of stars | * @param nstars number of stars | |||
* @param star_data an array of star right ascensions, declinations, | * @param star_data an array of star right ascensions, declinations, | |||
* and magnitudes | * and magnitudes | |||
*/ | */ | |||
bool repaint( const SGSkyColor &sc ); | bool repaint( const SGSkyColor &sc, const SGEphemeris& eph ); | |||
/** | /** | |||
* Reposition the sky at the specified origin and orientation | * Reposition the sky at the specified origin and orientation | |||
* | * | |||
* lon specifies a rotation about the Z axis | * lon specifies a rotation about the Z axis | |||
* lat specifies a rotation about the new Y axis | * lat specifies a rotation about the new Y axis | |||
* 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 | * additional orientation for the sunrise/set effects and is used | |||
* by the skydome and perhaps clouds. See discussion in detailed | * by the skydome and perhaps clouds. See discussion in detailed | |||
* class description. | * class description. | |||
skipping to change at line 316 | skipping to change at line 338 | |||
* sun position so sunset and sunrise effects look correct. | * sun position so sunset and sunrise effects look correct. | |||
* @param gst GMT side real time | * @param gst GMT side real time | |||
* @param sun_ra the sun's current right ascension | * @param sun_ra the sun's current right ascension | |||
* @param sun_dec the sun's current declination | * @param sun_dec the sun's current declination | |||
* @param sun_dist the sun's distance from the current view point | * @param sun_dist the sun's distance from the current view point | |||
* (to keep it inside your view volume.) | * (to keep it inside your view volume.) | |||
* @param moon_ra the moon's current right ascension | * @param moon_ra the moon's current right ascension | |||
* @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, double dt = 0.0 ); | bool reposition( const SGSkyState &st, const SGEphemeris& eph, double d t = 0.0 ); | |||
/** | /** | |||
* Modify the given visibility based on cloud layers, thickness, | * Modify the given visibility based on cloud layers, thickness, | |||
* transition range, and simulated "puffs". See discussion in detailed | * transition range, and simulated "puffs". See discussion in detailed | |||
* class description. | * class description. | |||
* @param alt current altitude | * @param alt current altitude | |||
* @param time_factor amount of time since modify_vis() last called so | * @param time_factor amount of time since modify_vis() last called so | |||
* we can scale effect rates properly despite variable frame rat es. | * we can scale effect rates properly despite variable frame rat es. | |||
*/ | */ | |||
void modify_vis( float alt, float time_factor ); | void modify_vis( float alt, float time_factor ); | |||
/** | osg::Node* getPreRoot() { return pre_root.get(); } | |||
* Draw background portions of the sky ... do this before you draw | osg::Node* getCloudRoot() { return cloud_root.get(); } | |||
* the rest of your scene. See discussion in detailed | ||||
* class description. | ||||
* @param alt current altitude | ||||
*/ | ||||
void preDraw( float alt, float fog_exp2_density ); | ||||
/** | ||||
* Draw upper translucent clouds ... do this before you've drawn | ||||
* all the translucent elements of your scene. See discussion in | ||||
* detailed class description. | ||||
* @param fog_exp2_density fog density of the current cloud layer | ||||
*/ | ||||
void drawUpperClouds(); | ||||
/** | ||||
* Draw lower translucent clouds ... do this after you've drawn | ||||
* all the opaque elements of your scene. See discussion in detailed | ||||
* class description. | ||||
*/ | ||||
void drawLowerClouds(); | ||||
/** | /** | |||
* Specify the texture path (optional, defaults to current directory) | * Specify the texture path (optional, defaults to current directory) | |||
* @param path base path to texture locations | * @param path base path to texture locations | |||
*/ | */ | |||
inline void texture_path( const string& path ) { | void texture_path( const string& path ); | |||
tex_path = SGPath( path ); | ||||
} | ||||
/** Enable drawing of the sky. */ | /** Enable drawing of the sky. */ | |||
inline void enable() { | inline void enable() { | |||
pre_selector->select( 1 ); | pre_selector->setValue(0, 1); | |||
post_selector->select( 1 ); | ||||
} | } | |||
/** | /** | |||
* Disable drawing of the sky in the scene graph. The leaf node is sti ll | * Disable drawing of the sky in the scene graph. The leaf node is sti ll | |||
* there, how ever it won't be traversed on by ssgCullandRender() | * there, how ever it won't be traversed on by ssgCullandRender() | |||
*/ | */ | |||
inline void disable() { | inline void disable() { | |||
pre_selector->select( 0 ); | pre_selector->setValue(0, 0); | |||
post_selector->select( 0 ); | ||||
} | } | |||
/** | /** | |||
* Get the current sun color | * Get the current sun color | |||
*/ | */ | |||
inline float *get_sun_color() { return oursun->get_color(); } | inline SGVec4f get_sun_color() { return oursun->get_color(); } | |||
/** | /** | |||
* Get the sun halo texture handle | * Get the current scene color | |||
*/ | */ | |||
inline GLuint get_sun_texture_id() { return oursun->get_texture_id(); } | inline SGVec4f get_scene_color() { return oursun->get_scene_color(); } | |||
/** | /** | |||
* Add a cloud layer. | * Add a cloud layer. | |||
* | * | |||
* Transfer pointer ownership to this object. | * Transfer pointer ownership to this object. | |||
* | * | |||
* @param layer The new cloud layer to add. | * @param layer The new cloud layer to add. | |||
*/ | */ | |||
void add_cloud_layer (SGCloudLayer * layer); | void add_cloud_layer (SGCloudLayer * layer); | |||
skipping to change at line 429 | skipping to change at line 427 | |||
/** @return current effective visibility */ | /** @return current effective visibility */ | |||
inline float get_visibility() const { return effective_visibility; } | inline float get_visibility() const { return effective_visibility; } | |||
/** Set desired clear air visibility. | /** Set desired clear air visibility. | |||
* @param v visibility in meters | * @param v visibility in meters | |||
*/ | */ | |||
inline void set_visibility( float v ) { | inline void set_visibility( float v ) { | |||
effective_visibility = visibility = (v <= 25.0) ? 25.0 : v; | effective_visibility = visibility = (v <= 25.0) ? 25.0 : v; | |||
} | } | |||
}; | ||||
/** Get 3D cloud density */ | ||||
double get_3dCloudDensity() const; | ||||
/** Set 3D cloud density | ||||
* @param density 3D cloud density | ||||
*/ | ||||
void set_3dCloudDensity(double density); | ||||
/** Get 3D cloud visibility range*/ | ||||
float get_3dCloudVisRange() const; | ||||
/** Set 3D cloud visibility range | ||||
* @param density 3D cloud visibility range | ||||
*/ | ||||
void set_3dCloudVisRange(float vis); | ||||
/** Get 3D cloud impostor distance*/ | ||||
float get_3dCloudImpostorDistance() const; | ||||
/** Set 3D cloud impostor distance | ||||
* @param density 3D cloud impostor distance | ||||
*/ | ||||
void set_3dCloudImpostorDistance(float vis); | ||||
/** Get 3D cloud LoD1 Range*/ | ||||
float get_3dCloudLoD1Range() const; | ||||
/** Set 3D cloud LoD1 Range | ||||
* @param vis LoD1 Range | ||||
*/ | ||||
void set_3dCloudLoD1Range(float vis); | ||||
/** Get 3D cloud LoD2 Range*/ | ||||
float get_3dCloudLoD2Range() const; | ||||
/** Set 3D cloud LoD2 Range | ||||
* @param vis LoD2 Range | ||||
*/ | ||||
void set_3dCloudLoD2Range(float vis); | ||||
/** Get 3D cloud impostor usage */ | ||||
bool get_3dCloudUseImpostors() const; | ||||
/** Set 3D cloud impostor usage | ||||
* @param wrap whether use impostors for 3D clouds | ||||
*/ | ||||
void set_3dCloudUseImpostors(bool imp); | ||||
/** Get 3D cloud wrapping */ | ||||
bool get_3dCloudWrap() const; | ||||
/** Set 3D cloud wrapping | ||||
* @param wrap whether to wrap 3D clouds | ||||
*/ | ||||
void set_3dCloudWrap(bool wrap); | ||||
/** Get minimum sky visibility */ | ||||
float get_minimum_sky_visibility() const; | ||||
/** Set minimum sky visibility */ | ||||
void set_minimum_sky_visibility( float value ); | ||||
}; | ||||
#endif // _SG_SKY_HXX | #endif // _SG_SKY_HXX | |||
End of changes. 27 change blocks. | ||||
61 lines changed or deleted | 119 lines changed or added | |||
soundmgr_openal.hxx | soundmgr_openal.hxx | |||
---|---|---|---|---|
// soundmgr.hxx -- Sound effect management class | // soundmgr.hxx -- Sound effect management class | |||
// | // | |||
// Sound manager initially written by David Findlay | // Sound manager initially written by David Findlay | |||
// <david_j_findlay@yahoo.com.au> 2001 | // <david_j_findlay@yahoo.com.au> 2001 | |||
// | // | |||
// C++-ified by Curtis Olson, started March 2001. | // C++-ified by Curtis Olson, started March 2001. | |||
// Modified for the new SoundSystem by Erik Hofman, October 2009 | ||||
// | // | |||
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt | // Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt | |||
// Copyright (C) 2009 Erik Hofman <erik@ehofman.com> | ||||
// | // | |||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License as | // modify it under the terms of the GNU General Public License as | |||
// published by the Free Software Foundation; either version 2 of the | // published by the Free Software Foundation; either version 2 of the | |||
// License, or (at your option) any later version. | // License, or (at your option) any later version. | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software Foundation, | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 | // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
1, USA. | ||||
// | // | |||
// $Id: soundmgr_openal.hxx,v 1.8.2.1 2007-07-07 18:37:58 mfranz Exp $ | // $Id$ | |||
/** | /** | |||
* \file soundmgr.hxx | * \file soundmgr.hxx | |||
* Provides a sound manager class to keep track of | * Provides a sound manager class to keep track of | |||
* multiple sounds and manage playing them with different effects and | * multiple sounds and manage playing them with different effects and | |||
* timings. | * timings. | |||
*/ | */ | |||
#ifndef _SG_SOUNDMGR_OPENAL_HXX | #ifndef _SG_SOUNDMGR_OPENAL_HXX | |||
#define _SG_SOUNDMGR_OPENAL_HXX 1 | #define _SG_SOUNDMGR_OPENAL_HXX 1 | |||
#ifndef __cplusplus | #include <string> | |||
# error This library requires C++ | #include <vector> | |||
#endif | #include <map> | |||
#include <memory> // for std::auto_ptr | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/structure/subsystem_mgr.hxx> | ||||
#include <simgear/math/SGMath.hxx> | ||||
#include STL_STRING | // forward decls | |||
#include <map> | class SGSampleGroup; | |||
class SGSoundSample; | ||||
#if defined( __APPLE__ ) | ||||
# include <OpenAL/al.h> | ||||
# include <OpenAL/alc.h> | ||||
#else | ||||
# include <AL/al.h> | ||||
# include <AL/alc.h> | ||||
#endif | ||||
#include "sample_openal.hxx" | ||||
SG_USING_STD(map); | ||||
SG_USING_STD(string); | ||||
typedef map < string, SGSharedPtr<SGSoundSample> > sample_map; | ||||
typedef sample_map::iterator sample_map_iterator; | ||||
typedef sample_map::const_iterator const_sample_map_iterator; | ||||
/** | /** | |||
* Manage a collection of SGSoundSample instances | * Manage a collection of SGSampleGroup instances | |||
*/ | */ | |||
class SGSoundMgr | class SGSoundMgr : public SGSubsystem | |||
{ | { | |||
public: | ||||
ALCdevice *dev; | SGSoundMgr(); | |||
ALCcontext *context; | ~SGSoundMgr(); | |||
// Position of the listener. | void init(); | |||
ALfloat listener_pos[3]; | void update(double dt); | |||
// Velocity of the listener. | void suspend(); | |||
ALfloat listener_vel[3]; | void resume(); | |||
void stop(); | ||||
// Orientation of the listener. (first 3 elements are "at", second | void reinit(); | |||
// 3 are "up") | ||||
ALfloat listener_ori[6]; | ||||
sample_map samples; | /** | |||
* Select a specific sound device. | ||||
* Requires a init/reinit call before sound is actually switched. | ||||
*/ | ||||
inline void select_device(const char* devname) {_device_name = devname; | ||||
} | ||||
bool working; | /** | |||
double safety; | * Test is the sound manager is in a working condition. | |||
* @return true is the sound manager is working | ||||
*/ | ||||
bool is_working() const; | ||||
public: | /** | |||
* Set the sound manager to a working condition. | ||||
*/ | ||||
void activate(); | ||||
SGSoundMgr(); | /** | |||
~SGSoundMgr(); | * Test is the sound manager is in an active and working condition. | |||
* @return true is the sound manager is active | ||||
*/ | ||||
inline bool is_active() const { return _active; } | ||||
/** | /** | |||
* (re) initialize the sound manager. | * Register a sample group to the sound manager. | |||
* @param sgrp Pointer to a sample group to add | ||||
* @param refname Reference name of the sample group | ||||
* @return true if successful, false otherwise | ||||
*/ | */ | |||
void init(); | bool add( SGSampleGroup *sgrp, const std::string& refname ); | |||
/** | /** | |||
* Bind properties for the sound manager. | * Remove a sample group from the sound manager. | |||
* @param refname Reference name of the sample group to remove | ||||
* @return true if successful, false otherwise | ||||
*/ | */ | |||
void bind(); | bool remove( const std::string& refname ); | |||
/** | /** | |||
* Unbind properties for the sound manager. | * Test if a specified sample group is registered at the sound manager | |||
* @param refname Reference name of the sample group test for | ||||
* @return true if the specified sample group exists | ||||
*/ | */ | |||
void unbind(); | bool exists( const std::string& refname ); | |||
/** | /** | |||
* Run the audio scheduler. | * Find a specified sample group in the sound manager | |||
* @param refname Reference name of the sample group to find | ||||
* @return A pointer to the SGSampleGroup | ||||
*/ | */ | |||
void update(double dt); | SGSampleGroup *find( const std::string& refname, bool create = false ); | |||
/** | /** | |||
* Pause all sounds. | * Set the Cartesian position of the sound manager. | |||
* @param pos OpenAL listener position | ||||
*/ | */ | |||
void pause(); | void set_position( const SGVec3d& pos, const SGGeod& pos_geod ); | |||
void set_position_offset( const SGVec3d& pos ) { | ||||
_offset_pos = pos; _changed = true; | ||||
} | ||||
/** | /** | |||
* Resume all sounds. | * Get the position of the sound manager. | |||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht | ||||
* @return OpenAL listener position | ||||
*/ | */ | |||
void resume(); | const SGVec3d& get_position() const; | |||
/** | /** | |||
* is audio working? | * Set the velocity vector (in meters per second) of the sound manager | |||
* This is the horizontal local frame; x=north, y=east, z=down | ||||
* @param Velocity vector | ||||
*/ | */ | |||
inline bool is_working() const { return working; } | void set_velocity( const SGVec3d& vel ) { | |||
_velocity = vel; _changed = true; | ||||
} | ||||
/** | /** | |||
* reinitialize the sound manager | * Get the velocity vector of the sound manager | |||
* This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | ||||
ht. | ||||
* @return Velocity vector of the OpenAL listener | ||||
*/ | */ | |||
inline void reinit() { init(); } | inline SGVec3f get_velocity() { return toVec3f(_velocity); } | |||
/** | /** | |||
* add a sound effect, return true if successful | * Set the orientation of the sound manager | |||
* @param ori Quaternation containing the orientation information | ||||
*/ | */ | |||
bool add( SGSoundSample *sound, const string& refname); | void set_orientation( const SGQuatd& ori ); | |||
/** | /** | |||
* remove a sound effect, return true if successful | * Get the orientation of the sound manager | |||
* @return Quaternation containing the orientation information | ||||
*/ | */ | |||
bool remove( const string& refname ); | const SGQuatd& get_orientation() const; | |||
/** | /** | |||
* return true of the specified sound exists in the sound manager syste | * Get the direction vector of the sound manager | |||
m | * This is in the same coordinate system as OpenGL; y=up, z=back, x=rig | |||
ht. | ||||
* @return Look-at direction of the OpenAL listener | ||||
*/ | */ | |||
bool exists( const string& refname ); | SGVec3f get_direction() const; | |||
enum { | ||||
NO_SOURCE = (unsigned int)-1, | ||||
NO_BUFFER = (unsigned int)-1, | ||||
FAILED_BUFFER = (unsigned int)-2 | ||||
}; | ||||
/** | /** | |||
* return a pointer to the SGSoundSample if the specified sound | * Set the master volume. | |||
* exists in the sound manager system, otherwise return NULL | * @param vol Volume (must be between 0.0 and 1.0) | |||
*/ | */ | |||
SGSoundSample *find( const string& refname ); | void set_volume( float vol ); | |||
/** | /** | |||
* tell the scheduler to play the indexed sample in a continuous | * Get the master volume. | |||
* loop | * @return Volume (must be between 0.0 and 1.0) | |||
*/ | */ | |||
bool play_looped( const string& refname ); | inline float get_volume() { return _volume; } | |||
/** | /** | |||
* tell the scheduler to play the indexed sample once | * Get a free OpenAL source-id | |||
* @return NO_SOURCE if no source is available | ||||
*/ | */ | |||
bool play_once( const string& refname ); | unsigned int request_source(); | |||
/** | /** | |||
* return true of the specified sound is currently being played | * Free an OpenAL source-id for future use | |||
* @param source OpenAL source-id to free | ||||
*/ | */ | |||
bool is_playing( const string& refname ); | void release_source( unsigned int source ); | |||
/** | /** | |||
* immediate stop playing the sound | * Get a free OpenAL buffer-id | |||
* The buffer-id will be assigned to the sample by calling this functio | ||||
n. | ||||
* @param sample Pointer to an audio sample to assign the buffer-id to | ||||
* @return NO_BUFFER if loading of the buffer failed. | ||||
*/ | */ | |||
bool stop( const string& refname ); | unsigned int request_buffer(SGSoundSample *sample); | |||
/** | /** | |||
* set overall volume for the application. | * Free an OpenAL buffer-id for this sample | |||
* @param vol 1.0 is default, must be greater than 0 | * @param sample Pointer to an audio sample for which to free the buffe | |||
r | ||||
*/ | */ | |||
inline void set_volume( const ALfloat vol ) { | void release_buffer( SGSoundSample *sample ); | |||
if ( vol > 0.0 ) { | ||||
alListenerf( AL_GAIN, vol ); | ||||
} | ||||
} | ||||
/** | /** | |||
* set the position of the listener (in opengl coordinates) | * Test if the position of the sound manager has changed. | |||
* The value will be set to false upon the next call to update_late() | ||||
* @return true if the position has changed | ||||
*/ | */ | |||
inline void set_listener_pos( ALfloat *pos ) { | inline bool has_changed() { return _changed; } | |||
listener_pos[0] = pos[0]; | ||||
listener_pos[1] = pos[1]; | ||||
listener_pos[2] = pos[2]; | ||||
alListenerfv( AL_POSITION, listener_pos ); | ||||
} | ||||
/** | /** | |||
* set the velocity of the listener (in opengl coordinates) | * Some implementations seem to need the velocity multiplied by a | |||
* factor of 100 to make them distinct. I've not found if this is | ||||
* a problem in the implementation or in out code. Until then | ||||
* this function is used to detect the problematic implementations. | ||||
*/ | */ | |||
inline void set_listener_vel( ALfloat *vel ) { | inline bool bad_doppler_effect() { return _bad_doppler; } | |||
listener_vel[0] = vel[0]; | ||||
listener_vel[1] = vel[1]; | ||||
listener_vel[2] = vel[2]; | ||||
#ifdef USE_OPEN_AL_DOPPLER | ||||
alListenerfv( AL_VELOCITY, listener_vel ); | ||||
#endif | ||||
} | ||||
/** | /** | |||
* set the orientation of the listener (in opengl coordinates) | * Load a sample file and return it's configuration and data. | |||
* | * @param samplepath Path to the file to load | |||
* Description: ORIENTATION is a pair of 3-tuples representing the | * @param data Pointer to a variable that points to the allocated data | |||
* 'at' direction vector and 'up' direction of the Object in | * @param format Pointer to a vairable that gets the OpenAL format | |||
* Cartesian space. AL expects two vectors that are orthogonal to | * @param size Pointer to a vairable that gets the sample size in bytes | |||
* each other. These vectors are not expected to be normalized. If | * @param freq Pointer to a vairable that gets the sample frequency in | |||
* one or more vectors have zero length, implementation behavior | Herz | |||
* is undefined. If the two vectors are linearly dependent, | * @return true if succesful, false on error | |||
* behavior is undefined. | */ | |||
*/ | bool load(const std::string &samplepath, void **data, int *format, | |||
inline void set_listener_orientation( ALfloat *ori ) { | size_t *size, int *freq ); | |||
listener_ori[0] = ori[0]; | ||||
listener_ori[1] = ori[1]; | ||||
listener_ori[2] = ori[2]; | ||||
listener_ori[3] = ori[3]; | ||||
listener_ori[4] = ori[4]; | ||||
listener_ori[5] = ori[5]; | ||||
alListenerfv( AL_ORIENTATION, listener_ori ); | ||||
} | ||||
/** | /** | |||
* set the positions of all managaged sound sources | * Get a list of available playback devices. | |||
*/ | */ | |||
void set_source_pos_all( ALfloat *pos ); | std::vector<const char*> get_available_devices(); | |||
/** | /** | |||
* set the velocities of all managaged sound sources | * Get the current OpenAL vendor or rendering backend. | |||
*/ | */ | |||
void set_source_vel_all( ALfloat *pos ); | const std::string& get_vendor() { return _vendor; } | |||
const std::string& get_renderer() { return _renderer; } | ||||
private: | ||||
class SoundManagerPrivate; | ||||
/// private implementation object | ||||
std::auto_ptr<SoundManagerPrivate> d; | ||||
bool _active; | ||||
bool _changed; | ||||
float _volume; | ||||
// Position of the listener. | ||||
SGVec3d _offset_pos; | ||||
SGGeod _geod_pos; | ||||
// Velocity of the listener. | ||||
SGVec3d _velocity; | ||||
bool _bad_doppler; | ||||
std::string _renderer; | ||||
std::string _vendor; | ||||
std::string _device_name; | ||||
bool testForALError(std::string s); | ||||
bool testForALCError(std::string s); | ||||
bool testForError(void *p, std::string s); | ||||
void update_sample_config( SGSampleGroup *sound ); | ||||
}; | }; | |||
#endif // _SG_SOUNDMGR_OPENAL_HXX | #endif // _SG_SOUNDMGR_OPENAL_HXX | |||
End of changes. 61 change blocks. | ||||
124 lines changed or deleted | 176 lines changed or added | |||
sphere.hxx | sphere.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: sphere.hxx,v 1.2 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#include <plib/ssg.h> | #include <osg/Node> | |||
// return a sphere object as an ssgBranch (and connect in the | // return a sphere object as an ssgBranch (and connect in the | |||
// specified ssgSimpleState | // specified ssgSimpleState | |||
ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl, | osg::Node* SGMakeSphere(double radius, int slices, int stacks); | |||
double radius, int slices, int stacks, | ||||
ssgCallback predraw, ssgCallback postdraw ); | ||||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added | |||
star.hxx | star.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: star.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _STAR_HXX_ | #ifndef _STAR_HXX_ | |||
#define _STAR_HXX_ | #define _STAR_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
class Star : public CelestialBody | class Star : public CelestialBody | |||
{ | { | |||
private: | private: | |||
skipping to change at line 44 | skipping to change at line 44 | |||
double xs, ys; // the sun's rectangular geocentric coordinates | double xs, ys; // the sun's rectangular geocentric coordinates | |||
double ye, ze; // the sun's rectangularequatorial rectangular geoce ntric coordinates | double ye, ze; // the sun's rectangularequatorial rectangular geoce ntric coordinates | |||
double distance; // the sun's distance to the earth | double distance; // the sun's distance to the earth | |||
public: | public: | |||
Star (double mjd); | Star (double mjd); | |||
Star (); | Star (); | |||
~Star(); | ~Star(); | |||
void updatePosition(double mjd); | void updatePosition(double mjd); | |||
double getM(); | double getM() const; | |||
double getw(); | double getw() const; | |||
double getxs(); | double getxs() const; | |||
double getys(); | double getys() const; | |||
double getye(); | double getye() const; | |||
double getze(); | double getze() const; | |||
double getDistance(); | double getDistance() const; | |||
}; | }; | |||
inline double Star::getM() | inline double Star::getM() const | |||
{ | { | |||
return M; | return M; | |||
} | } | |||
inline double Star::getw() | inline double Star::getw() const | |||
{ | { | |||
return w; | return w; | |||
} | } | |||
inline double Star::getxs() | inline double Star::getxs() const | |||
{ | { | |||
return xs; | return xs; | |||
} | } | |||
inline double Star::getys() | inline double Star::getys() const | |||
{ | { | |||
return ys; | return ys; | |||
} | } | |||
inline double Star::getye() | inline double Star::getye() const | |||
{ | { | |||
return ye; | return ye; | |||
} | } | |||
inline double Star::getze() | inline double Star::getze() const | |||
{ | { | |||
return ze; | return ze; | |||
} | } | |||
inline double Star::getDistance() | inline double Star::getDistance() const | |||
{ | { | |||
return distance; | return distance; | |||
} | } | |||
#endif // _STAR_HXX_ | #endif // _STAR_HXX_ | |||
End of changes. 9 change blocks. | ||||
15 lines changed or deleted | 15 lines changed or added | |||
stardata.hxx | stardata.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: stardata.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_STARDATA_HXX | #ifndef _SG_STARDATA_HXX | |||
#define _SG_STARDATA_HXX | #define _SG_STARDATA_HXX | |||
#include <plib/sg.h> | #include <vector> | |||
#include <simgear/math/SGMath.hxx> | ||||
#include <simgear/misc/sg_path.hxx> | class SGPath; | |||
#define SG_MAX_STARS 850 | ||||
class SGStarData { | class SGStarData { | |||
int nstars; | ||||
sgdVec3 *stars; | ||||
SGPath data_path; | ||||
public: | public: | |||
// Constructor | // Constructor | |||
SGStarData(); | SGStarData( const SGPath& path ); | |||
SGStarData( SGPath path ); | ||||
// Destructor | // Destructor | |||
~SGStarData(); | ~SGStarData(); | |||
// load the stars database | // load the stars database | |||
bool load(); | bool load( const SGPath& path ); | |||
// stars | // stars | |||
inline int getNumStars() const { return nstars; } | inline int getNumStars() const { return _stars.size(); } | |||
inline sgdVec3 *getStars() { return stars; } | inline SGVec3d *getStars() { return &(_stars[0]); } | |||
private: | ||||
std::vector<SGVec3d> _stars; | ||||
}; | }; | |||
#endif // _SG_STARDATA_HXX | #endif // _SG_STARDATA_HXX | |||
End of changes. 8 change blocks. | ||||
17 lines changed or deleted | 11 lines changed or added | |||
stars.hxx | stars.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: stars.hxx,v 1.2 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_STARS_HXX_ | #ifndef _SG_STARS_HXX_ | |||
#define _SG_STARS_HXX_ | #define _SG_STARS_HXX_ | |||
#include <plib/ssg.h> | #include <osg/Array> | |||
class SGStars { | #include <simgear/math/SGMath.hxx> | |||
#include <simgear/structure/SGReferenced.hxx> | ||||
ssgTransform *stars_transform; | class SGStars : public SGReferenced { | |||
ssgSimpleState *state; | ||||
ssgColourArray *cl; | osg::ref_ptr<osg::Vec4Array> cl; | |||
ssgVertexArray *vl; | ||||
int old_phase; // data for optimization | int old_phase; // data for optimization | |||
public: | public: | |||
// Constructor | // Constructor | |||
SGStars( void ); | SGStars( void ); | |||
// Destructor | // Destructor | |||
~SGStars( void ); | ~SGStars( void ); | |||
// initialize the stars structure | // initialize the stars structure | |||
ssgBranch *build( int num, sgdVec3 *star_data, double star_dist ); | osg::Node* build( int num, const SGVec3d star_data[], double star_dist ); | |||
// repaint the planet magnitudes based on current value of | // repaint the planet magnitudes based on current value of | |||
// sun_angle in degrees relative to verticle (so we can make them | // sun_angle in degrees relative to verticle (so we can make them | |||
// relatively dimmer during dawn and dusk | // relatively dimmer during dawn and dusk | |||
// 0 degrees = high noon | // 0 degrees = high noon | |||
// 90 degrees = sun rise/set | // 90 degrees = sun rise/set | |||
// 180 degrees = darkest midnight | // 180 degrees = darkest midnight | |||
bool repaint( double sun_angle, int num, sgdVec3 *star_data ); | bool repaint( double sun_angle, int num, const SGVec3d star_data[] ); | |||
// reposition the stars for the specified time (GST rotation), | ||||
// offset by our current position (p) so that it appears fixed at | ||||
// a great distance from the viewer. | ||||
bool reposition( sgVec3 p, double angle ); | ||||
}; | }; | |||
#endif // _SG_STARS_HXX_ | #endif // _SG_STARS_HXX_ | |||
End of changes. 7 change blocks. | ||||
14 lines changed or deleted | 8 lines changed or added | |||
stdint.hxx | stdint.hxx | |||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
#ifndef _STDINT_HXX | #ifndef _STDINT_HXX | |||
#define _STDINT_HXX 1 | #define _STDINT_HXX 1 | |||
// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt | // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt | |||
// | // | |||
// Written by Curtis Olson - http://www.flightgear.org/~curt | // Written by Curtis Olson - http://www.flightgear.org/~curt | |||
// Started September 2001. | // Started September 2001. | |||
// | // | |||
// This file is in the Public Domain, and comes with no warranty. | // This file is in the Public Domain, and comes with no warranty. | |||
// | // | |||
// $Id: stdint.hxx,v 1.6 2005-11-13 09:42:38 ehofman Exp $ | // $Id$ | |||
////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////// | |||
// | // | |||
// There are many sick systems out there: | // There are many sick systems out there: | |||
// | // | |||
// check for sizeof(float) and sizeof(double) | // check for sizeof(float) and sizeof(double) | |||
// if sizeof(float) != 4 this code must be patched | // if sizeof(float) != 4 this code must be patched | |||
// if sizeof(double) != 8 this code must be patched | // if sizeof(double) != 8 this code must be patched | |||
// | // | |||
// Those are comments I fetched out of glibc source: | // Those are comments I fetched out of glibc source: | |||
skipping to change at line 83 | skipping to change at line 83 | |||
inline bool sgIsLittleEndian() { | inline bool sgIsLittleEndian() { | |||
static const int sgEndianTest = 1; | static const int sgEndianTest = 1; | |||
return (*((char *) &sgEndianTest ) != 0); | return (*((char *) &sgEndianTest ) != 0); | |||
} | } | |||
inline bool sgIsBigEndian() { | inline bool sgIsBigEndian() { | |||
static const int sgEndianTest = 1; | static const int sgEndianTest = 1; | |||
return (*((char *) &sgEndianTest ) == 0); | return (*((char *) &sgEndianTest ) == 0); | |||
} | } | |||
inline void sgEndianSwap(int32_t *x) { *x = (int32_t) sg_bswap_32((int32_t) | ||||
*x); } | ||||
inline void sgEndianSwap(float *x) { *x = (float) sg_bswap_32((float) *x); | ||||
} | ||||
inline void sgEndianSwap(uint16_t *x) { *x = sg_bswap_16(*x); } | inline void sgEndianSwap(uint16_t *x) { *x = sg_bswap_16(*x); } | |||
inline void sgEndianSwap(uint32_t *x) { *x = sg_bswap_32(*x); } | inline void sgEndianSwap(uint32_t *x) { *x = sg_bswap_32(*x); } | |||
inline void sgEndianSwap(uint64_t *x) { *x = sg_bswap_64(*x); } | inline void sgEndianSwap(uint64_t *x) { *x = sg_bswap_64(*x); } | |||
#endif // !_STDINT_HXX | #endif // !_STDINT_HXX | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 6 lines changed or added | |||
stopwatch.hxx | stopwatch.hxx | |||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
* Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | |||
* | * | |||
* Suggestions: blitz-suggest@cybervision.com | * Suggestions: blitz-suggest@cybervision.com | |||
* Bugs: blitz-bugs@cybervision.com | * Bugs: blitz-bugs@cybervision.com | |||
* | * | |||
* For more information, please see the Blitz++ Home Page: | * For more information, please see the Blitz++ Home Page: | |||
* http://seurat.uwaterloo.ca/blitz/ | * http://seurat.uwaterloo.ca/blitz/ | |||
*/ | */ | |||
/* | /* | |||
* $Id: stopwatch.hxx,v 1.3 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Library General Public | * modify it under the terms of the GNU Library General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2 of the License, or (at your option) any later version. | * version 2 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
strutils.hxx | strutils.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: strutils.hxx,v 1.2 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef STRUTILS_H | #ifndef STRUTILS_H | |||
#define STRUTILS_H | #define STRUTILS_H | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <string> | |||
#include <vector> | #include <vector> | |||
SG_USING_STD(vector); | #include <cstdlib> | |||
#ifdef SG_HAVE_STD_INCLUDES | ||||
# include <cstdlib> | ||||
#else | ||||
# include <stdlib.h> | ||||
#endif | ||||
SG_USING_STD(string); | typedef std::vector < std::string > string_list; | |||
namespace simgear { | namespace simgear { | |||
namespace strutils { | namespace strutils { | |||
// /** | // /** | |||
// * atof() wrapper for "string" type | // * atof() wrapper for "string" type | |||
// */ | // */ | |||
// inline double | // inline double | |||
// atof( const string& str ) | // atof( const string& str ) | |||
// { | // { | |||
// return ::atof( str.c_str() ); | // return ::atof( str.c_str() ); | |||
// } | // } | |||
skipping to change at line 70 | skipping to change at line 63 | |||
// atoi( const string& str ) | // atoi( const string& str ) | |||
// { | // { | |||
// return ::atoi( str.c_str() ); | // return ::atoi( str.c_str() ); | |||
// } | // } | |||
/** | /** | |||
* Strip leading and/or trailing whitespace from s. | * Strip leading and/or trailing whitespace from s. | |||
* @param s String to strip. | * @param s String to strip. | |||
* @return The stripped string. | * @return The stripped string. | |||
*/ | */ | |||
string lstrip( const string& s ); | std::string lstrip( const std::string& s ); | |||
string rstrip( const string& s ); | std::string rstrip( const std::string& s ); | |||
string strip( const string& s ); | std::string strip( const std::string& s ); | |||
/** | ||||
* Right-padding of a string to a given length | ||||
* @param s String to pad | ||||
* @param length The total length of the resulting string | ||||
* @param c The character to pad with | ||||
* @return The padded string | ||||
*/ | ||||
std::string rpad( const std::string & s, size_t length, char c ); | ||||
/** | ||||
* Left-padding of a string to a given length | ||||
* @param s String to pad | ||||
* @param length The total length of the resulting string | ||||
* @param c The character to pad with | ||||
* @return The padded string | ||||
*/ | ||||
std::string lpad( const std::string & s, size_t length, char c ); | ||||
/** | /** | |||
* Split a string into a words using 'sep' as the delimiter string. | * Split a string into a words using 'sep' as the delimiter string. | |||
* Produces a result similar to the perl and python functions of the | * Produces a result similar to the perl and python functions of the | |||
* same name. | * same name. | |||
* | * | |||
* @param s The string to split into words, | * @param s The string to split into words, | |||
* @param sep Word delimiters. If not specified then any whitespace is a separator, | * @param sep Word delimiters. If not specified then any whitespace is a separator, | |||
* @param maxsplit If given, splits at no more than maxsplit places, | * @param maxsplit If given, splits at no more than maxsplit places, | |||
* resulting in at most maxsplit+1 words. | * resulting in at most maxsplit+1 words. | |||
* @return Array of words. | * @return Array of words. | |||
*/ | */ | |||
vector<string> | string_list | |||
split( const string& s, | split( const std::string& s, | |||
const char* sep = 0, | const char* sep = 0, | |||
int maxsplit = 0 ); | int maxsplit = 0 ); | |||
} // end namespace strutils | /** | |||
* create a single string by joining the elements of a list with | ||||
* another string. | ||||
*/ | ||||
std::string join(const string_list& l, const std::string& joinWith = | ||||
""); | ||||
/** | ||||
* Test if a string starts with a string | ||||
* | ||||
* @param s The string to be tested | ||||
* @param substr The string to test | ||||
* @return True, if s starts with substr, False otherwise | ||||
*/ | ||||
bool starts_with( const std::string & s, const std::string & substr | ||||
); | ||||
/** | ||||
* Test if a string ends with a string | ||||
* | ||||
* @param s The string to be tested | ||||
* @param substr The string to test | ||||
* @return True, if s ends with substr, False otherwise | ||||
*/ | ||||
bool ends_with( const std::string & s, const std::string & substr ); | ||||
/** | ||||
* Strip all leading/trailing whitespace, and transform all interal | ||||
* whitespace into a single ' ' character - i.e newlines/carriage retur | ||||
ns/ | ||||
* tabs/multiple spaces will be condensed. | ||||
*/ | ||||
std::string simplify(const std::string& s); | ||||
/** | ||||
* convert a string representing a decimal number, to an int | ||||
*/ | ||||
int to_int(const std::string& s, int base = 10); | ||||
/** | ||||
* Like strcmp(), but for dotted versions strings NN.NN.NN | ||||
* any number of terms are support. | ||||
* @return 0 if versions match, -ve number if v1 is lower, +ve if v1 | ||||
* is greater | ||||
*/ | ||||
int compare_versions(const std::string& v1, const std::string& v2); | ||||
/** | ||||
* Convert a string to upper case. | ||||
* @return upper case string | ||||
*/ | ||||
std::string uppercase(const std::string &s); | ||||
/** | ||||
* convert a string in the local Windows 8-bit encoding to UTF-8 | ||||
* (no-op on other platforms) | ||||
*/ | ||||
std::string convertWindowsLocal8BitToUtf8(const std::string& a); | ||||
/** | ||||
* convert base-64 encoded data to raw bytes (possibly with embedded | ||||
* NULs). Throws an exception if input data is not base64, or is | ||||
* malformed | ||||
*/ | ||||
std::string decodeBase64(const std::string& a); | ||||
/** | ||||
* convert bytes to hexadecimal equivalent | ||||
*/ | ||||
std::string encodeHex(const std::string& bytes); | ||||
std::string encodeHex(const unsigned char* rawBytes, unsigned int lengt | ||||
h); | ||||
/** | ||||
* Unescape string. | ||||
* | ||||
* @param str String possibly containing escaped characters. | ||||
* @return string with escaped characters replaced by single character | ||||
* values. | ||||
*/ | ||||
std::string unescape(const char* str); | ||||
inline std::string unescape(const std::string& str) | ||||
{ return unescape(str.c_str()); } | ||||
} // end namespace strutils | ||||
} // end namespace simgear | } // end namespace simgear | |||
#endif // STRUTILS_H | #endif // STRUTILS_H | |||
End of changes. 8 change blocks. | ||||
18 lines changed or deleted | 115 lines changed or added | |||
subsystem_mgr.hxx | subsystem_mgr.hxx | |||
---|---|---|---|---|
// Written by David Megginson, started 2000-12 | // Written by David Megginson, started 2000-12 | |||
// | // | |||
// Copyright (C) 2000 David Megginson, david@megginson.com | // Copyright (C) 2000 David Megginson, david@megginson.com | |||
// | // | |||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License as | // modify it under the terms of the GNU General Public License as | |||
// published by the Free Software Foundation; either version 2 of the | // published by the Free Software Foundation; either version 2 of the | |||
// License, or (at your option) any later version. | // License, or (at your option) any later version. | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: subsystem_mgr.hxx,v 1.3.2.4 2007-11-17 09:18:35 durk Exp $ | // $Id$ | |||
#ifndef __SUBSYSTEM_MGR_HXX | #ifndef __SUBSYSTEM_MGR_HXX | |||
#define __SUBSYSTEM_MGR_HXX 1 | #define __SUBSYSTEM_MGR_HXX 1 | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#if 0 | ||||
#ifdef HAVE_WINDOWS_H | ||||
# include <windows.h> | ||||
# include <float.h> | ||||
#endif | ||||
#include STL_STRING | ||||
SG_USING_STD(string); | ||||
#include <vector> | ||||
SG_USING_STD(vector); | ||||
#endif | ||||
#include <string> | #include <string> | |||
#include <map> | #include <map> | |||
#include <vector> | #include <vector> | |||
SG_USING_STD(map); | ||||
SG_USING_STD(vector); | ||||
SG_USING_STD(string); | ||||
#include <simgear/props/props.hxx> | ||||
#include <simgear/timing/timestamp.hxx> | #include <simgear/timing/timestamp.hxx> | |||
#include "SGSmplstat.hxx" | #include <simgear/structure/SGSharedPtr.hxx> | |||
#include <simgear/misc/strutils.hxx> | ||||
class TimingInfo | class TimingInfo | |||
{ | { | |||
private: | private: | |||
string eventName; | std::string eventName; | |||
SGTimeStamp time; | SGTimeStamp time; | |||
public: | public: | |||
TimingInfo(string name, SGTimeStamp &t) { eventName = name; time = t;}; | TimingInfo(const std::string& name, const SGTimeStamp &t) : | |||
string getName() { return eventName; }; | eventName(name), time(t) | |||
SGTimeStamp getTime() { return time; }; | { } | |||
const std::string& getName() const { return eventName; } | ||||
const SGTimeStamp& getTime() const { return time; } | ||||
}; | }; | |||
typedef vector<TimingInfo> eventTimeVec; | class SampleStatistic; | |||
typedef vector<TimingInfo>::iterator eventTimeVecIterator; | ||||
typedef std::vector<TimingInfo> eventTimeVec; | ||||
typedef std::vector<TimingInfo>::iterator eventTimeVecIterator; | ||||
typedef void (*SGSubsystemTimingCb)(void* userData, const std::string& name | ||||
, SampleStatistic* pStatistic); | ||||
/** | /** | |||
* Basic interface for all FlightGear subsystems. | * Basic interface for all FlightGear subsystems. | |||
* | * | |||
* <p>This is an abstract interface that all FlightGear subsystems | * <p>This is an abstract interface that all FlightGear subsystems | |||
* will eventually implement. It defines the basic operations for | * will eventually implement. It defines the basic operations for | |||
* each subsystem: initialization, property binding and unbinding, and | * each subsystem: initialization, property binding and unbinding, and | |||
* updating. Interfaces may define additional methods, but the | * updating. Interfaces may define additional methods, but the | |||
* preferred way of exchanging information with other subsystems is | * preferred way of exchanging information with other subsystems is | |||
* through the property tree.</p> | * through the property tree.</p> | |||
* | * | |||
skipping to change at line 132 | skipping to change at line 123 | |||
* and the subsystem should <em>not</em> delete it in its destructor | * and the subsystem should <em>not</em> delete it in its destructor | |||
* (the pointer belongs to the property tree, not the subsystem).</p> | * (the pointer belongs to the property tree, not the subsystem).</p> | |||
* | * | |||
* <p>The program may ask the subsystem to suspend or resume | * <p>The program may ask the subsystem to suspend or resume | |||
* sim-time-dependent operations; by default, the suspend() and | * sim-time-dependent operations; by default, the suspend() and | |||
* resume() methods set the protected variable <var>_suspended</var>, | * resume() methods set the protected variable <var>_suspended</var>, | |||
* which the subsystem can reference in its update() method, but | * which the subsystem can reference in its update() method, but | |||
* subsystems may also override the suspend() and resume() methods to | * subsystems may also override the suspend() and resume() methods to | |||
* take different actions.</p> | * take different actions.</p> | |||
*/ | */ | |||
class SGSubsystem | class SGSubsystem : public SGReferenced | |||
{ | { | |||
public: | public: | |||
/** | /** | |||
* Default constructor. | * Default constructor. | |||
*/ | */ | |||
SGSubsystem (); | SGSubsystem (); | |||
/** | /** | |||
* Virtual destructor to ensure that subclass destructors are called. | * Virtual destructor to ensure that subclass destructors are called. | |||
skipping to change at line 157 | skipping to change at line 148 | |||
* Initialize the subsystem. | * Initialize the subsystem. | |||
* | * | |||
* <p>This method should set up the state of the subsystem, but | * <p>This method should set up the state of the subsystem, but | |||
* should not bind any properties. Note that any dependencies on | * should not bind any properties. Note that any dependencies on | |||
* the state of other subsystems should be placed here rather than | * the state of other subsystems should be placed here rather than | |||
* in the constructor, so that FlightGear can control the | * in the constructor, so that FlightGear can control the | |||
* initialization order.</p> | * initialization order.</p> | |||
*/ | */ | |||
virtual void init (); | virtual void init (); | |||
typedef enum | ||||
{ | ||||
INIT_DONE, ///< subsystem is fully initialised | ||||
INIT_CONTINUE ///< init should be called again | ||||
} InitStatus; | ||||
virtual InitStatus incrementalInit (); | ||||
/** | /** | |||
* Initialize parts that depend on other subsystems having been initializ ed. | * Initialize parts that depend on other subsystems having been initializ ed. | |||
* | * | |||
* <p>This method should set up all parts that depend on other | * <p>This method should set up all parts that depend on other | |||
* subsystems. One example is the scripting/Nasal subsystem, which | * subsystems. One example is the scripting/Nasal subsystem, which | |||
* is initialized last. So, if a subsystem wants to execute Nasal | * is initialized last. So, if a subsystem wants to execute Nasal | |||
* code in subsystem-specific configuration files, it has to do that | * code in subsystem-specific configuration files, it has to do that | |||
* in its postinit() method.</p> | * in its postinit() method.</p> | |||
*/ | */ | |||
virtual void postinit (); | virtual void postinit (); | |||
/** | /** | |||
* Reinitialize the subsystem. | * Reinitialize the subsystem. | |||
* | * | |||
* <p>This method should cause the subsystem to reinitialize itself, | * <p>This method should cause the subsystem to reinitialize itself, | |||
* and (normally) to reload any configuration files.</p> | * and (normally) to reload any configuration files.</p> | |||
*/ | */ | |||
virtual void reinit (); | virtual void reinit (); | |||
/** | /** | |||
* Shutdown the subsystem. | ||||
* | ||||
* <p>Release any state associated with subsystem. Shutdown happens in | ||||
* the reverse order to init(), so this is the correct place to do | ||||
* shutdown that depends on other subsystems. | ||||
* </p> | ||||
*/ | ||||
virtual void shutdown (); | ||||
/** | ||||
* Acquire the subsystem's property bindings. | * Acquire the subsystem's property bindings. | |||
* | * | |||
* <p>This method should bind all properties that the subsystem | * <p>This method should bind all properties that the subsystem | |||
* publishes. It will be invoked after init, but before any | * publishes. It will be invoked after init, but before any | |||
* invocations of update.</p> | * invocations of update.</p> | |||
*/ | */ | |||
virtual void bind (); | virtual void bind (); | |||
/** | /** | |||
* Release the subsystem's property bindings. | * Release the subsystem's property bindings. | |||
skipping to change at line 220 | skipping to change at line 229 | |||
* method will still be invoked so that the subsystem can take any | * method will still be invoked so that the subsystem can take any | |||
* non-time-dependent actions, such as updating the display.</p> | * non-time-dependent actions, such as updating the display.</p> | |||
* | * | |||
* <p>It is not an error for the suspend method to be invoked when | * <p>It is not an error for the suspend method to be invoked when | |||
* the subsystem is already suspended; the invocation should simply | * the subsystem is already suspended; the invocation should simply | |||
* be ignored.</p> | * be ignored.</p> | |||
*/ | */ | |||
virtual void suspend (); | virtual void suspend (); | |||
/** | /** | |||
* Suspend or resum operation of this subsystem. | * Suspend or resume operation of this subsystem. | |||
* | * | |||
* @param suspended true if the subsystem should be suspended, false | * @param suspended true if the subsystem should be suspended, false | |||
* otherwise. | * otherwise. | |||
*/ | */ | |||
virtual void suspend (bool suspended); | virtual void suspend (bool suspended); | |||
/** | /** | |||
* Resume operation of this subsystem. | * Resume operation of this subsystem. | |||
* | * | |||
* <p>This method instructs the subsystem to resume | * <p>This method instructs the subsystem to resume | |||
skipping to change at line 245 | skipping to change at line 254 | |||
virtual void resume (); | virtual void resume (); | |||
/** | /** | |||
* Test whether this subsystem is suspended. | * Test whether this subsystem is suspended. | |||
* | * | |||
* @return true if the subsystem is suspended, false if it is not. | * @return true if the subsystem is suspended, false if it is not. | |||
*/ | */ | |||
virtual bool is_suspended () const; | virtual bool is_suspended () const; | |||
/** | /** | |||
* Keep track of execution time. | * Trigger the callback to report timing information for all subsystems. | |||
* | ||||
* <p>This method keeps track of timing statistics for each subsystem.</p | ||||
> | ||||
* | ||||
* @param time execution time in ms of last call. | ||||
*/ | */ | |||
void updateExecutionTime(double time); | void reportTiming(void); | |||
/** | ||||
* Print details of execution time. | ||||
* | ||||
* <p>For debugging purposes, developers can place stamp() calls | ||||
* at strategic points in the update() function of each subsystem, which | ||||
* record the time between the successive calls to stamp. This method, | ||||
* printExecutionTime() is called after exectution of the subsystem | ||||
* update function itself to conduct a post-hoc analysis of excecution | ||||
* time</p> | ||||
*/ | ||||
void printTimingInformation(); | ||||
/** | /** | |||
* Place time stamps at strategic points in the execution of subsystems | * Place time stamps at strategic points in the execution of subsystems | |||
* update() member functions. Predominantly for debugging purposes. | * update() member functions. Predominantly for debugging purposes. | |||
*/ | */ | |||
void stamp(string name); | void stamp(const std::string& name); | |||
protected: | protected: | |||
bool _suspended; | bool _suspended; | |||
eventTimeVec timingInfo; | eventTimeVec timingInfo; | |||
//int test; | ||||
static SGSubsystemTimingCb reportTimingCb; | ||||
static void* reportTimingUserData; | ||||
}; | }; | |||
/** | /** | |||
* A group of FlightGear subsystems. | * A group of FlightGear subsystems. | |||
*/ | */ | |||
class SGSubsystemGroup : public SGSubsystem | class SGSubsystemGroup : public SGSubsystem | |||
{ | { | |||
public: | public: | |||
SGSubsystemGroup (); | SGSubsystemGroup (); | |||
virtual ~SGSubsystemGroup (); | virtual ~SGSubsystemGroup (); | |||
virtual void init (); | virtual void init(); | |||
virtual InitStatus incrementalInit (); | ||||
virtual void postinit (); | virtual void postinit (); | |||
virtual void reinit (); | virtual void reinit (); | |||
virtual void shutdown (); | ||||
virtual void bind (); | virtual void bind (); | |||
virtual void unbind (); | virtual void unbind (); | |||
virtual void update (double delta_time_sec); | virtual void update (double delta_time_sec); | |||
virtual void suspend (); | virtual void suspend (); | |||
virtual void resume (); | virtual void resume (); | |||
virtual bool is_suspended () const; | virtual bool is_suspended () const; | |||
virtual void set_subsystem (const string &name, | virtual void set_subsystem (const std::string &name, | |||
SGSubsystem * subsystem, | SGSubsystem * subsystem, | |||
double min_step_sec = 0); | double min_step_sec = 0); | |||
virtual SGSubsystem * get_subsystem (const string &name); | virtual SGSubsystem * get_subsystem (const std::string &name); | |||
virtual void remove_subsystem (const string &name); | virtual void remove_subsystem (const std::string &name); | |||
virtual bool has_subsystem (const string &name) const; | virtual bool has_subsystem (const std::string &name) const; | |||
void reportTiming(void); | ||||
/** | ||||
* | ||||
*/ | ||||
void set_fixed_update_time(double fixed_dt); | ||||
void collectDebugTiming(bool collect); | /** | |||
* retrive list of member subsystem names | ||||
*/ | ||||
string_list member_names() const; | ||||
private: | private: | |||
struct Member { | class Member; | |||
Member* get_member (const std::string &name, bool create = false); | ||||
Member (); | std::vector<Member *> _members; | |||
Member (const Member &member); | ||||
virtual ~Member (); | ||||
virtual void update (double delta_time_sec); | ||||
void printTimingInformation(double time); | ||||
void printTimingStatistics(); | ||||
void updateExecutionTime(double time); | ||||
double getTimeWarningThreshold(); | ||||
void collectDebugTiming (bool collect) { collectTimeStats = collect | ||||
; }; | ||||
SampleStatistic timeStat; | ||||
string name; | ||||
SGSubsystem * subsystem; | ||||
double min_step_sec; | ||||
double elapsed_sec; | ||||
bool collectTimeStats; | ||||
}; | ||||
Member * get_member (const string &name, bool create = false); | double _fixedUpdateTime; | |||
double _updateTimeRemainder; | ||||
vector<Member *> _members; | /// index of the member we are currently init-ing | |||
unsigned int _initPosition; | ||||
}; | }; | |||
/** | /** | |||
* Manage subsystems for FlightGear. | * Manage subsystems for FlightGear. | |||
* | * | |||
* This top-level subsystem will eventually manage all of the | * This top-level subsystem will eventually manage all of the | |||
* subsystems in FlightGear: it broadcasts its life-cycle events | * subsystems in FlightGear: it broadcasts its life-cycle events | |||
* (init, bind, etc.) to all of the subsystems it manages. Subsystems | * (init, bind, etc.) to all of the subsystems it manages. Subsystems | |||
* are grouped to guarantee order of initialization and execution -- | * are grouped to guarantee order of initialization and execution -- | |||
* currently, the only two groups are INIT and GENERAL, but others | * currently, the only two groups are INIT and GENERAL, but others | |||
* will appear in the future. | * will appear in the future. | |||
skipping to change at line 362 | skipping to change at line 354 | |||
class SGSubsystemMgr : public SGSubsystem | class SGSubsystemMgr : public SGSubsystem | |||
{ | { | |||
public: | public: | |||
/** | /** | |||
* Types of subsystem groups. | * Types of subsystem groups. | |||
*/ | */ | |||
enum GroupType { | enum GroupType { | |||
INIT = 0, | INIT = 0, | |||
GENERAL, | GENERAL, | |||
FDM, ///< flight model, autopilot, instruments that run coup | ||||
led | ||||
POST_FDM, ///< certain subsystems depend on FDM data | ||||
DISPLAY, ///< view, camera, rendering updates | ||||
SOUND/*I want to be last!*/, ///< needs to run AFTER display, to a | ||||
llow concurrent GPU/sound processing | ||||
MAX_GROUPS | MAX_GROUPS | |||
}; | }; | |||
SGSubsystemMgr (); | SGSubsystemMgr (); | |||
virtual ~SGSubsystemMgr (); | virtual ~SGSubsystemMgr (); | |||
virtual void init (); | virtual void init (); | |||
virtual InitStatus incrementalInit (); | ||||
virtual void postinit (); | virtual void postinit (); | |||
virtual void reinit (); | virtual void reinit (); | |||
virtual void shutdown (); | ||||
virtual void bind (); | virtual void bind (); | |||
virtual void unbind (); | virtual void unbind (); | |||
virtual void update (double delta_time_sec); | virtual void update (double delta_time_sec); | |||
virtual void suspend (); | virtual void suspend (); | |||
virtual void resume (); | virtual void resume (); | |||
virtual bool is_suspended () const; | virtual bool is_suspended () const; | |||
virtual void add (const char * name, | virtual void add (const char * name, | |||
SGSubsystem * subsystem, | SGSubsystem * subsystem, | |||
GroupType group = GENERAL, | GroupType group = GENERAL, | |||
double min_time_sec = 0); | double min_time_sec = 0); | |||
/** | ||||
* remove a subsystem, and return a pointer to it. | ||||
* returns NULL if the subsystem was not found. | ||||
*/ | ||||
virtual SGSubsystem* remove(const char* name); | ||||
virtual SGSubsystemGroup * get_group (GroupType group); | virtual SGSubsystemGroup * get_group (GroupType group); | |||
virtual SGSubsystem * get_subsystem(const string &name); | virtual SGSubsystem * get_subsystem(const std::string &name) const; | |||
void collectDebugTiming(bool collect); | void reportTiming(); | |||
void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTi | ||||
mingCb = cb;reportTimingUserData = userData;} | ||||
private: | private: | |||
SGSubsystemGroup* _groups[MAX_GROUPS]; | ||||
unsigned int _initPosition; | ||||
SGSubsystemGroup _groups[MAX_GROUPS]; | typedef std::map<std::string, SGSubsystem*> SubsystemDict; | |||
map<string,SGSubsystem *> _subsystem_map; | SubsystemDict _subsystem_map; | |||
}; | }; | |||
#endif // __SUBSYSTEM_MGR_HXX | #endif // __SUBSYSTEM_MGR_HXX | |||
End of changes. 35 change blocks. | ||||
81 lines changed or deleted | 89 lines changed or added | |||
tabbed_values.hxx | tabbed_values.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: tabbed_values.hxx,v 1.3 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef SG_TABBED_VALUES_HXX | #ifndef SG_TABBED_VALUES_HXX | |||
#define SG_TABBED_VALUES_HXX | #define SG_TABBED_VALUES_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <vector> | #include <vector> | |||
#include STL_STRING | #include <string> | |||
SG_USING_STD(vector); | using std::vector; | |||
SG_USING_STD(string); | using std::string; | |||
class SGTabbedValues | class SGTabbedValues | |||
{ | { | |||
public: | public: | |||
SGTabbedValues(const char* line); | SGTabbedValues(const char* line); | |||
string operator[](const unsigned int) const; | string operator[](const unsigned int) const; | |||
bool isValueAt(const unsigned int) const; | bool isValueAt(const unsigned int) const; | |||
double getDoubleAt(const unsigned int) const; | double getDoubleAt(const unsigned int) const; | |||
char getCharAt(const unsigned int) const; | char getCharAt(const unsigned int) const; | |||
long getLongAt(const unsigned int) const; | long getLongAt(const unsigned int) const; | |||
private: | private: | |||
const char* fieldAt(const unsigned int offset) const; | const char* fieldAt(const unsigned int offset) const; | |||
const char* _line; | ||||
/** this is first character of each field, if the field is empty | /** this is first character of each field, if the field is empty | |||
it will be the tab character. It is lazily built as needed, so | it will be the tab character. It is lazily built as needed, so | |||
if only the first field is accessed (which is a common case) we | if only the first field is accessed (which is a common case) we | |||
don't iterative over the whole line. */ | don't iterative over the whole line. */ | |||
mutable vector<char*> _fields; | mutable vector<char*> _fields; | |||
}; | }; | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
6 lines changed or deleted | 4 lines changed or added | |||
texcoord.hxx | texcoord.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: texcoord.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _TEXCOORD_HXX | #ifndef _TEXCOORD_HXX | |||
#define _TEXCOORD_HXX | #define _TEXCOORD_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <simgear/bucket/newbucket.hxx> | #include <simgear/bucket/newbucket.hxx> | |||
#include <simgear/math/sg_types.hxx> | #include <simgear/math/sg_types.hxx> | |||
#include <simgear/math/SGMathFwd.hxx> | ||||
#include <simgear/math/SGGeod.hxx> | ||||
#include <simgear/math/SGVec2.hxx> | ||||
/** | /** | |||
* Traverse the specified fan/strip/list of vertices and attempt to | * Traverse the specified fan/strip/list of vertices and attempt to | |||
* calculate "none stretching" texture coordinates. | * calculate "none stretching" texture coordinates. | |||
* @param b the bucket containing the structure | * @param b the bucket containing the structure | |||
* @param geod_nodes vertices in geodetic coordinates | * @param geod_nodes vertices in geodetic coordinates | |||
* @param fan integer list of indices pointing into the vertex list | * @param fan integer list of indices pointing into the vertex list | |||
* @param scale (default = 1.0) scaling factor | * @param scale (default = 1.0) scaling factor | |||
* @return list of texture coordinates | * @return list of texture coordinates | |||
*/ | */ | |||
point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes | std::vector<SGVec2f> sgCalcTexCoords( const SGBucket& b, const std::vector< | |||
, | SGGeod>& geod_nodes, | |||
const int_list& fan, double scale = 1.0 ); | ||||
std::vector<SGVec2f> sgCalcTexCoords( double centerLat, const std::vector<S | ||||
GGeod>& geod_nodes, | ||||
const int_list& fan, double scale = 1.0 ); | const int_list& fan, double scale = 1.0 ); | |||
#endif // _TEXCOORD_HXX | #endif // _TEXCOORD_HXX | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 11 lines changed or added | |||
timestamp.hxx | timestamp.hxx | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: timestamp.hxx,v 1.4 2006-03-08 18:16:10 mfranz Exp $ | // $Id$ | |||
#ifndef _TIMESTAMP_HXX | #ifndef _TIMESTAMP_HXX | |||
#define _TIMESTAMP_HXX | #define _TIMESTAMP_HXX | |||
#ifndef __cplusplus | #ifndef __cplusplus | |||
# error This library requires C++ | # error This library requires C++ | |||
#endif | #endif | |||
#include <iosfwd> | ||||
#include <iomanip> | ||||
#include <sstream> | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/math/SGCMath.hxx> | ||||
// MSVC++ 6.0 kuldge - Need forward declaration of friends. | ||||
class SGTimeStamp; | ||||
SGTimeStamp operator + (const SGTimeStamp& t, const long& m); | ||||
long operator - (const SGTimeStamp& a, const SGTimeStamp& b); | ||||
/** | /** | |||
* The SGTimeStamp class allows you to mark and compare time stamps | * The SGTimeStamp class allows you to mark and compare time stamps | |||
* with microsecond accuracy (if your system has support for this | * with nanosecond accuracy (if your system has support for this | |||
* level of accuracy.) | * level of accuracy). | |||
* | * | |||
* The SGTimeStamp is useful for tracking the elapsed time of various | * The SGTimeStamp is useful for tracking the elapsed time of various | |||
* events in your program. You can also use it to keep constistant | * events in your program. You can also use it to keep consistent | |||
* motion across varying frame rates. | * motion across varying frame rates. | |||
* | ||||
* Note SGTimestamp does not deliver the time of day. The content of this | ||||
* stamps might be, dependent on the implementation, a time to an arbitrary | ||||
* base time. | ||||
*/ | */ | |||
class SGTimeStamp { | class SGTimeStamp { | |||
public: | ||||
typedef long sec_type; | ||||
typedef int nsec_type; | ||||
private: | /** Default constructor, initialize time to zero. */ | |||
SGTimeStamp() : | ||||
_nsec(0), | ||||
_sec(0) | ||||
{ } | ||||
/** Hmm, might reenable them at some time, but since it is not clear | ||||
what the input unit of the int is, omit them for now. | ||||
Use the static constructor functions where it is clear from the met | ||||
hod | ||||
name how the arguments are meant. | ||||
*/ | ||||
// SGTimeStamp(sec_type sec) | ||||
// { setTime(sec, 0); } | ||||
// SGTimeStamp(int sec) | ||||
// { setTime(sec, 0); } | ||||
// SGTimeStamp(const double& sec) | ||||
// { setTime(sec); } | ||||
long seconds; | /** Update stored time to current time (seconds and nanoseconds) */ | |||
long usec; | void stamp(); | |||
public: | /** Set the time from a double value */ | |||
void setTime(const double& seconds) | ||||
{ | ||||
sec_type wholeSecs = sec_type(floor(seconds)); | ||||
nsec_type reminder; | ||||
reminder = nsec_type(floor((seconds - wholeSecs)*(1000*1000*1000))) | ||||
; | ||||
setTime(wholeSecs, reminder); | ||||
} | ||||
/** Set the time from a seconds/nanoseconds pair */ | ||||
void setTime(sec_type sec, nsec_type nsec) | ||||
{ | ||||
if (0 <= nsec) { | ||||
_sec = sec + nsec / (1000*1000*1000); | ||||
_nsec = nsec % (1000*1000*1000); | ||||
} else { | ||||
_sec = sec - 1 + nsec / (1000*1000*1000); | ||||
_nsec = (1000*1000*1000) + nsec % (1000*1000*1000); | ||||
} | ||||
} | ||||
/** Default constructor */ | /** @return the saved seconds of this time stamp */ | |||
SGTimeStamp(); | long get_seconds() const { return _sec; } | |||
/** @return the saved microseconds of this time stamp */ | ||||
int get_usec() const { return _nsec/1000; } | ||||
/** @return the saved seconds of this time stamp */ | ||||
const sec_type& getSeconds() const | ||||
{ return _sec; } | ||||
/** @return the saved nanoseconds of this time stamp */ | ||||
const nsec_type& getNanoSeconds() const | ||||
{ return _nsec; } | ||||
/** @return the value of the timestamp in nanoseconds, | ||||
* use doubles to avoid overflow. | ||||
* If you need real nanosecond accuracy for time differences, build up | ||||
a | ||||
* SGTimeStamp reference time and compare SGTimeStamps directly. | ||||
*/ | ||||
double toNSecs() const | ||||
{ return _nsec + double(_sec)*1000*1000*1000; } | ||||
/** @return the value of the timestamp in microseconds, | ||||
* use doubles to avoid overflow. | ||||
* If you need real nanosecond accuracy for time differences, build up | ||||
a | ||||
* SGTimeStamp reference time and compare SGTimeStamps directly. | ||||
*/ | ||||
double toUSecs() const | ||||
{ return 1e-3*_nsec + double(_sec)*1000*1000; } | ||||
/** @return the value of the timestamp in milliseconds, | ||||
* use doubles to avoid overflow. | ||||
* If you need real nanosecond accuracy for time differences, build up | ||||
a | ||||
* SGTimeStamp reference time and compare SGTimeStamps directly. | ||||
*/ | ||||
double toMSecs() const | ||||
{ return 1e-6*_nsec + double(_sec)*1000; } | ||||
/** @return the value of the timestamp in seconds, | ||||
* use doubles to avoid overflow. | ||||
* If you need real nanosecond accuracy for time differences, build up | ||||
a | ||||
* SGTimeStamp reference time and compare SGTimeStamps directly. | ||||
*/ | ||||
double toSecs() const | ||||
{ return 1e-9*_nsec + _sec; } | ||||
/** Inplace addition. | ||||
*/ | ||||
SGTimeStamp& operator+=(const SGTimeStamp& c) | ||||
{ | ||||
_sec += c._sec; | ||||
_nsec += c._nsec; | ||||
if ((1000*1000*1000) <= _nsec) { | ||||
_nsec -= (1000*1000*1000); | ||||
_sec += 1; | ||||
} | ||||
return *this; | ||||
} | ||||
/** Inplace subtraction. | ||||
*/ | ||||
SGTimeStamp& operator-=(const SGTimeStamp& c) | ||||
{ | ||||
_sec -= c._sec; | ||||
_nsec -= c._nsec; | ||||
if (_nsec < 0) { | ||||
_nsec += (1000*1000*1000); | ||||
_sec -= 1; | ||||
} | ||||
return *this; | ||||
} | ||||
/** | /** | |||
* This creates an instance of the SGTimeStamp object. When | * Create SGTimeStamps from input with given units | |||
* calling the constructor you may provide initial seconds an | ||||
* microseconds values. | ||||
* @param s initial seconds value | ||||
* @param m initial microseconds value | ||||
*/ | */ | |||
SGTimeStamp( const long s, const long m ); | static SGTimeStamp fromSecMSec(sec_type sec, nsec_type msec) | |||
~SGTimeStamp(); | { return SGTimeStamp(sec, 1000*1000*msec); } | |||
static SGTimeStamp fromSecUSec(sec_type sec, nsec_type usec) | ||||
{ return SGTimeStamp(sec, 1000*usec); } | ||||
static SGTimeStamp fromSecNSec(sec_type sec, nsec_type nsec) | ||||
{ return SGTimeStamp(sec, nsec); } | ||||
static SGTimeStamp fromSec(int sec) | ||||
{ SGTimeStamp ts; ts.setTime(sec); return ts; } | ||||
static SGTimeStamp fromSec(const double& sec) | ||||
{ SGTimeStamp ts; ts.setTime(sec); return ts; } | ||||
static SGTimeStamp fromMSec(nsec_type msec) | ||||
{ return SGTimeStamp(0, 1000*1000*msec); } | ||||
static SGTimeStamp fromUSec(nsec_type usec) | ||||
{ return SGTimeStamp(0, 1000*usec); } | ||||
static SGTimeStamp fromNSec(nsec_type nsec) | ||||
{ return SGTimeStamp(0, nsec); } | ||||
/** Update stored time to current time (seconds and microseconds) */ | /** | |||
void stamp(); | * Return a timestamp with the current time. | |||
*/ | ||||
static SGTimeStamp now() | ||||
{ SGTimeStamp ts; ts.stamp(); return ts; } | ||||
/** Compare two time stamps for equality */ | /** | |||
SGTimeStamp& operator = ( const SGTimeStamp& t ); | * Sleep until the time of abstime is passed. | |||
*/ | ||||
static bool sleepUntil(const SGTimeStamp& abstime); | ||||
/** | /** | |||
* Increment the saved time by the specified number of microseconds | * Sleep for reltime. | |||
* @param t time stamp | ||||
* @param m microseconds increment | ||||
* @return new time stamp | ||||
*/ | */ | |||
friend SGTimeStamp operator + (const SGTimeStamp& t, const long& m); | static bool sleepFor(const SGTimeStamp& reltime); | |||
/** | /** | |||
* Subtract two time stamps returning the difference in microseconds. | * Alias for the most common use case with milliseconds. | |||
* @param a timestamp 1 | ||||
* @param b timestame 2 | ||||
* @return difference in microseconds | ||||
*/ | */ | |||
friend long operator - (const SGTimeStamp& a, const SGTimeStamp& b); | static bool sleepForMSec(unsigned msec) | |||
{ return sleepFor(fromMSec(msec)); } | ||||
/** @return the saved seconds of this time stamp */ | /** | |||
inline long get_seconds() const { return seconds; } | * elapsed time since the stamp was taken, in msec | |||
*/ | ||||
int elapsedMSec() const; | ||||
private: | ||||
SGTimeStamp(sec_type sec, nsec_type nsec) | ||||
{ setTime(sec, nsec); } | ||||
/** @return the saved microseconds of this time stamp */ | nsec_type _nsec; | |||
inline long get_usec() const { return usec; } | sec_type _sec; | |||
}; | }; | |||
inline SGTimeStamp::SGTimeStamp() : | inline bool | |||
seconds(0), | operator==(const SGTimeStamp& c1, const SGTimeStamp& c2) | |||
usec(0) | ||||
{ | { | |||
if (c1.getNanoSeconds() != c2.getNanoSeconds()) | ||||
return false; | ||||
return c1.getSeconds() == c2.getSeconds(); | ||||
} | } | |||
inline SGTimeStamp::SGTimeStamp( const long s, const long u ) { | inline bool | |||
seconds = s; | operator!=(const SGTimeStamp& c1, const SGTimeStamp& c2) | |||
usec = u; | { return !operator==(c1, c2); } | |||
} | ||||
inline SGTimeStamp::~SGTimeStamp() { | inline bool | |||
operator<(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ | ||||
if (c1.getSeconds() < c2.getSeconds()) | ||||
return true; | ||||
if (c1.getSeconds() > c2.getSeconds()) | ||||
return false; | ||||
return c1.getNanoSeconds() < c2.getNanoSeconds(); | ||||
} | } | |||
inline SGTimeStamp& SGTimeStamp::operator = (const SGTimeStamp& t) | inline bool | |||
operator>(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ return c2 < c1; } | ||||
inline bool | ||||
operator>=(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ return !(c1 < c2); } | ||||
inline bool | ||||
operator<=(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ return !(c1 > c2); } | ||||
inline SGTimeStamp | ||||
operator+(const SGTimeStamp& c1) | ||||
{ return c1; } | ||||
inline SGTimeStamp | ||||
operator-(const SGTimeStamp& c1) | ||||
{ return SGTimeStamp::fromSec(0) -= c1; } | ||||
inline SGTimeStamp | ||||
operator+(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ return SGTimeStamp(c1) += c2; } | ||||
inline SGTimeStamp | ||||
operator-(const SGTimeStamp& c1, const SGTimeStamp& c2) | ||||
{ return SGTimeStamp(c1) -= c2; } | ||||
template<typename char_type, typename traits_type> | ||||
inline | ||||
std::basic_ostream<char_type, traits_type>& | ||||
operator<<(std::basic_ostream<char_type, traits_type>& os, const SGTimeStam | ||||
p& c) | ||||
{ | { | |||
seconds = t.seconds; | std::basic_stringstream<char_type, traits_type> stream; | |||
usec = t.usec; | ||||
return *this; | SGTimeStamp pos = c; | |||
if (c.getSeconds() < 0) { | ||||
stream << stream.widen('-'); | ||||
pos = - c; | ||||
} | ||||
stream << pos.getSeconds() << stream.widen('.'); | ||||
stream << std::setw(9) << std::setfill('0') << pos.getNanoSeconds(); | ||||
return os << stream.str(); | ||||
} | } | |||
#endif // _TIMESTAMP_HXX | #endif // _TIMESTAMP_HXX | |||
End of changes. 27 change blocks. | ||||
52 lines changed or deleted | 230 lines changed or added | |||
timezone.h | timezone.h | |||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
/** \file timezone.h | /** \file timezone.h | |||
* | * | |||
* Provides SGTimeZone and SGTimeZoneContainer | * Provides SGTimeZone and SGTimeZoneContainer | |||
* | * | |||
*/ | */ | |||
#ifndef _TIMEZONE_H_ | #ifndef _TIMEZONE_H_ | |||
#define _TIMEZONE_H_ | #define _TIMEZONE_H_ | |||
#include <stdio.h> | ||||
#include <string> | #include <string> | |||
#include <vector> | ||||
#include <simgear/timing/geocoord.h> | #include <simgear/math/SGMath.hxx> | |||
#include <simgear/math/SGGeod.hxx> | ||||
/** | /** | |||
* SGTimeZone is derived from geocoord, and stores the timezone centerpoint , | * SGTimeZone stores the timezone centerpoint, | |||
* as well as the countrycode and the timezone descriptor. The latter is | * as well as the countrycode and the timezone descriptor. The latter is | |||
* used in order to get the local time. | * used in order to get the local time. | |||
* | * | |||
*/ | */ | |||
class SGTimeZone : public SGGeoCoord | class SGTimeZone | |||
{ | { | |||
private: | private: | |||
string countryCode; | SGVec3d centerpoint; // centre of timezone, in cartesian coordinates | |||
string descriptor; | std::string countryCode; | |||
std::string descriptor; | ||||
public: | public: | |||
/** | /** | |||
* Default constructor. | ||||
*/ | ||||
SGTimeZone() : SGGeoCoord() | ||||
{ | ||||
countryCode.erase(); | ||||
descriptor.erase(); | ||||
}; | ||||
/** | ||||
* Build a timezone object with a specifed latitude, longitude, country | * Build a timezone object with a specifed latitude, longitude, country | |||
* code, and descriptor | * code, and descriptor | |||
* @param la latitude | * @param pt centerpoint | |||
* @param lo longitude | ||||
* @param cc country code | * @param cc country code | |||
* @param desc descriptor | * @param desc descriptor | |||
*/ | */ | |||
SGTimeZone(float la, float lo, char* cc, char* desc); | SGTimeZone(const SGGeod& pt, char* cc, char* desc); | |||
/** | /** | |||
* Build a timezone object from a textline in zone.tab | * Build a timezone object from a textline in zone.tab | |||
* @param infoString the textline from zone.tab | * @param infoString the textline from zone.tab | |||
*/ | */ | |||
SGTimeZone(const char *infoString); | SGTimeZone(const char *infoString); | |||
/** | /** | |||
* The copy constructor | * The copy constructor | |||
* @param other the source object | * @param other the source object | |||
*/ | */ | |||
SGTimeZone(const SGTimeZone &other); | SGTimeZone(const SGTimeZone &other); | |||
/** | /** | |||
* Virutal destructor | ||||
*/ | ||||
virtual ~SGTimeZone() { }; | ||||
/** | ||||
* Return the descriptor string | * Return the descriptor string | |||
* @return descriptor string (char array) | * @return descriptor string (char array) | |||
*/ | */ | |||
virtual const char * getDescription() { return descriptor.c_str(); }; | const char * getDescription() { return descriptor.c_str(); }; | |||
const SGVec3d& cartCenterpoint() const | ||||
{ | ||||
return centerpoint; | ||||
} | ||||
}; | }; | |||
/** | /** | |||
* SGTimeZoneContainer is derived from SGGeoCoordContainer, and has some | * SGTimeZoneContainer | |||
* added functionality. | ||||
*/ | */ | |||
class SGTimeZoneContainer : public SGGeoCoordContainer | class SGTimeZoneContainer | |||
{ | { | |||
public: | public: | |||
SGTimeZoneContainer(const char *filename); | SGTimeZoneContainer(const char *filename); | |||
virtual ~SGTimeZoneContainer(); | ~SGTimeZoneContainer(); | |||
SGTimeZone* getNearest(const SGGeod& ref) const; | ||||
private: | ||||
typedef std::vector<SGTimeZone*> TZVec; | ||||
TZVec zones; | ||||
}; | }; | |||
#endif // _TIMEZONE_H_ | #endif // _TIMEZONE_H_ | |||
End of changes. 15 change blocks. | ||||
29 lines changed or deleted | 26 lines changed or added | |||
tr.h | tr.h | |||
---|---|---|---|---|
/* $Id: tr.h,v 1.3 2006-02-21 10:47:21 ehofman Exp $ */ | /* $Id$ */ | |||
/* | /* | |||
* $Log: tr.h,v $ | * $Log$ | |||
* Revision 1.3 2006-02-21 10:47:21 ehofman | * Revision 1.4 2008/07/27 16:10:37 ehofman | |||
* | ||||
* | ||||
* - remove the SG_GLxxxx_H #defines, since OSG provides its own versions | ||||
* - this exposed a bizarre issue on Mac where dragging in <AGL/agl.h> in | ||||
* extensions.hxx was pulling in all of Carbon to the global namespace | ||||
* - very scary. As a result, I now need to explicitly include CoreFound | ||||
ation | ||||
* in fg_init.cxx. | ||||
* - change SG_USING_STD(x) to using std::x | ||||
* | ||||
* Issues: | ||||
* | ||||
* - the logic for X11 and Win32 in RenderTexture and extensions is tortur | ||||
ed, | ||||
* please see if you agree I got all the ifdefs correct. | ||||
* | ||||
* Revision 1.3 2006/02/21 10:47:21 ehofman | ||||
* Back out the previous patch. | * Back out the previous patch. | |||
* | * | |||
* Revision 1.2 2004/11/18 19:10:34 curt | * Revision 1.2 2004/11/18 19:10:34 curt | |||
* Abstract out location of gl.h, glut.h, and glu.h includes so that we can | * Abstract out location of gl.h, glut.h, and glu.h includes so that we can | |||
* make the Mac platform happy since they put these in a different place co mpared | * make the Mac platform happy since they put these in a different place co mpared | |||
* to the rest of the world. | * to the rest of the world. | |||
* | * | |||
* Revision 1.1.1.1 2002/09/07 02:58:19 curt | * Revision 1.1.1.1 2002/09/07 02:58:19 curt | |||
* Initial revsion of Simgear-0.3.0 | * Initial revsion of Simgear-0.3.0 | |||
* | * | |||
skipping to change at line 86 | skipping to change at line 101 | |||
* 6. Delete the tile rendering context when finished: | * 6. Delete the tile rendering context when finished: | |||
* trDelete(t); | * trDelete(t); | |||
* | * | |||
*/ | */ | |||
#ifndef TR_H | #ifndef TR_H | |||
#define TR_H | #define TR_H | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include SG_GL_H | #include <osg/GL> | |||
//#ifdef __cplusplus | //#ifdef __cplusplus | |||
//extern "C" { | //extern "C" { | |||
//#endif | //#endif | |||
#define TR_VERSION "1.1" | #define TR_VERSION "1.1" | |||
#define TR_MAJOR_VERSION 1 | #define TR_MAJOR_VERSION 1 | |||
#define TR_MINOR_VERSION 1 | #define TR_MINOR_VERSION 1 | |||
typedef struct _TRctx TRcontext; | typedef struct _TRctx TRcontext; | |||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 21 lines changed or added | |||
uranus.hxx | uranus.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: uranus.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _URANUS_HXX_ | #ifndef _URANUS_HXX_ | |||
#define _URANUS_HXX_ | #define _URANUS_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Uranus : public CelestialBody | class Uranus : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
userdata.hxx | userdata.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: userdata.hxx,v 1.5 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
#ifndef _SG_USERDATA_HXX | #ifndef _SG_USERDATA_HXX | |||
#define _SG_USERDATA_HXX | #define _SG_USERDATA_HXX | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include STL_STRING | #include <osg/Node> | |||
#include <plib/ssg.h> | ||||
SG_USING_STD(string); | ||||
class SGMaterial; | ||||
class SGMatModel; | class SGMatModel; | |||
class SGMatModelGroup; | ||||
class SGModelLib; | ||||
class SGPropertyNode; | class SGPropertyNode; | |||
/** | /** | |||
* the application must call sgUserDataInit() and specify the | * the application must call sgUserDataInit() and specify the | |||
* following values (needed by the model loader callback at draw time) | * following values (needed by the model loader callback at draw time) | |||
* before drawing any scenery. | * before drawing any scenery. | |||
*/ | */ | |||
void sgUserDataInit( SGModelLib *m, const string &r, | void sgUserDataInit(SGPropertyNode *p); | |||
SGPropertyNode *p, double t ); | ||||
/** | namespace simgear | |||
* User data for populating leaves when they come in range. | ||||
*/ | ||||
class SGLeafUserData : public ssgBase | ||||
{ | { | |||
public: | ||||
bool is_filled_in; | ||||
ssgLeaf *leaf; | ||||
SGMaterial *mat; | ||||
ssgBranch *branch; | ||||
float sin_lat; | ||||
float cos_lat; | ||||
float sin_lon; | ||||
float cos_lon; | ||||
void setup_triangle( int i ); | ||||
}; | ||||
/** | /** | |||
* User data for populating triangles when they come in range. | * Get the property root for the simulation | |||
*/ | */ | |||
class SGTriUserData : public ssgBase | SGPropertyNode* getPropertyRoot(); | |||
{ | } | |||
public: | ||||
bool is_filled_in; | ||||
float * p1; | ||||
float * p2; | ||||
float * p3; | ||||
sgVec3 center; | ||||
double area; | ||||
SGMatModelGroup * object_group; | ||||
ssgBranch * branch; | ||||
SGLeafUserData * leafData; | ||||
unsigned int seed; | ||||
void fill_in_triangle(); | ||||
void add_object_to_triangle(SGMatModel * object); | ||||
void makeWorldMatrix (sgMat4 ROT, double hdg_deg ); | ||||
}; | ||||
/** | ||||
* ssgEntity with a dummy bounding sphere, to fool culling. | ||||
* | ||||
* This forces the in-range and out-of-range branches to be visited | ||||
* when appropriate, even if they have no children. It's ugly, but | ||||
* it works and seems fairly efficient (since branches can still | ||||
* be culled when they're out of the view frustum). | ||||
*/ | ||||
class SGDummyBSphereEntity : public ssgBranch | ||||
{ | ||||
public: | ||||
SGDummyBSphereEntity (float radius) | ||||
{ | ||||
bsphere.setCenter(0, 0, 0); | ||||
bsphere.setRadius(radius); | ||||
} | ||||
virtual ~SGDummyBSphereEntity () {} | ||||
virtual void recalcBSphere () { bsphere_is_invalid = false; } | ||||
}; | ||||
#endif // _SG_USERDATA_HXX | #endif // _SG_USERDATA_HXX | |||
End of changes. 9 change blocks. | ||||
67 lines changed or deleted | 7 lines changed or added | |||
venus.hxx | venus.hxx | |||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Library General Public License for more details. | * Library General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
* | * | |||
* $Id: venus.hxx,v 1.4 2006-03-08 18:16:08 mfranz Exp $ | * $Id$ | |||
************************************************************************** / | ************************************************************************** / | |||
#ifndef _VENUS_HXX_ | #ifndef _VENUS_HXX_ | |||
#define _VENUS_HXX_ | #define _VENUS_HXX_ | |||
#include <simgear/ephemeris/celestialBody.hxx> | #include <simgear/ephemeris/celestialBody.hxx> | |||
#include <simgear/ephemeris/star.hxx> | #include <simgear/ephemeris/star.hxx> | |||
class Venus : public CelestialBody | class Venus : public CelestialBody | |||
{ | { | |||
public: | public: | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added | |||
version.h | version.h | |||
---|---|---|---|---|
// version.h -- SimGear version | #define SIMGEAR_VERSION 2.12.0 | |||
// | ||||
// Written by Curtis Olson, started February 2000. | ||||
// | ||||
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt/ | ||||
// | ||||
// This library is free software; you can redistribute it and/or | ||||
// modify it under the terms of the GNU Library General Public | ||||
// License as published by the Free Software Foundation; either | ||||
// version 2 of the License, or (at your option) any later version. | ||||
// | ||||
// This library is distributed in the hope that it will be useful, | ||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
// Library General Public License for more details. | ||||
// | ||||
// You should have received a copy of the GNU Library General Public | ||||
// License along with this library; if not, write to the | ||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||||
// Boston, MA 02111-1307, USA. | ||||
// | ||||
// $Id: version.h.in,v 1.3 2006-02-21 10:47:20 ehofman Exp $ | ||||
#ifndef _SIMGEAR_VERSION_H | ||||
#define _SIMGEAR_VERSION_H | ||||
#define SIMGEAR_VERSION 1.0.0 | ||||
#endif // _SIMGEAR_VERSION_H | ||||
End of changes. 1 change blocks. | ||||
lines changed or deleted | lines changed or added | |||
xmlsound.hxx | xmlsound.hxx | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// | // | |||
// This program is distributed in the hope that it will be useful, but | // This program is distributed in the hope that it will be useful, but | |||
// WITHOUT ANY WARRANTY; without even the implied warranty of | // WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// General Public License for more details. | // General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: xmlsound.hxx,v 1.3 2006-03-08 18:16:09 mfranz Exp $ | // $Id$ | |||
/** | /** | |||
* \file sound.hxx | * \file sound.hxx | |||
* Provides a class to manage a single sound event including things | * Provides a class to manage a single sound event including things | |||
* like looping, volume and pitch changes. | * like looping, volume and pitch changes. | |||
*/ | */ | |||
#ifndef _SG_SOUND_HXX | #ifndef _SG_SOUND_HXX | |||
#define _SG_SOUND_HXX 1 | #define _SG_SOUND_HXX 1 | |||
#ifndef __cplusplus | #include <vector> | |||
# error This library requires C++ | #include <string> | |||
#endif | ||||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <simgear/props/condition.hxx> | ||||
#include "sample_openal.hxx" | #include <simgear/props/propsfwd.hxx> | |||
#include "soundmgr_openal.hxx" | #include <simgear/structure/SGSharedPtr.hxx> | |||
// forward decls | ||||
class SGSampleGroup; | ||||
class SGSoundSample; | ||||
class SGCondition; | ||||
class SGPath; | ||||
static const double MAX_TRANSIT_TIME = 0.1; // 100 ms. | static const double MAX_TRANSIT_TIME = 0.1; // 100 ms. | |||
/** | /** | |||
* Class for handling one sound event. | * Class for handling one sound event. | |||
* | * | |||
* This class handles everything for a particular sound event, by | * This class handles everything for a particular sound event, by | |||
* scanning an a pre-loaded property tree structure for sound | * scanning an a pre-loaded property tree structure for sound | |||
* settings, setting up its internal states, and managing sound | * settings, setting up its internal states, and managing sound | |||
* playback whenever such an event happens. | * playback whenever such an event happens. | |||
skipping to change at line 63 | skipping to change at line 67 | |||
{ | { | |||
public: | public: | |||
SGXmlSound(); | SGXmlSound(); | |||
virtual ~SGXmlSound(); | virtual ~SGXmlSound(); | |||
/** | /** | |||
* Initialize the sound event. | * Initialize the sound event. | |||
* | * | |||
* Prior to initialization of the sound event the propgrams property root | * Prior to initialization of the sound event the program's property root | |||
* has to be defined, the sound configuration XML tree has to be loaded | * has to be defined, the sound configuration XML tree has to be loaded | |||
* and a sound manager class has to be defined. | * and a sound manager class has to be defined. | |||
* | * | |||
* A sound configuration file would look like this: | * A sound configuration file would look like this: | |||
* <fx> | * <fx> | |||
* <event_name> | * <event_name> | |||
* <name/> Define the name of the event. For refference only. | * <name/> Define the name of the event. For reference only. | |||
* <mode/> Either: | * <mode/> Either: | |||
* looped: play this sound looped. | * looped: play this sound looped. | |||
* in-transit: play looped while the event is happening. | * in-transit: play looped while the event is happening. | |||
* once: play this sound once. | * once: play this sound once. | |||
* <path/> The relative path to the audio file. | * <path/> The relative path to the audio file. | |||
* <property/> Take action if this property becomes true. | * <property/> Take action if this property becomes true. | |||
* <condition/> Take action if this condition becomes true. | * <condition/> Take action if this condition becomes true. | |||
* <delay-sec/> Time after which the sound should be played. | ||||
* <volume> or <pitch> Define volume or pitch settings. | * <volume> or <pitch> Define volume or pitch settings. | |||
* <property/> Take the value of this property as a refference for th e | * <property/> Take the value of this property as a reference for the | |||
* result. | * result. | |||
* <internal/> Either: | * <internal/> Either: | |||
* dt_start: the time elapsed since this sound is playi ng. | * dt_start: the time elapsed since this sound is playi ng. | |||
* dt_stop: the time elapsed since this sound has stopp ed. | * dt_stop: the time elapsed since this sound has stopp ed. | |||
* <offset/> Add this value to the result. | * <offset/> Add this value to the result. | |||
* <factor/> Multiply the result by this factor. | * <factor/> Multiply the result by this factor. | |||
* <min/> Make sure the value is never less than this value. | * <min/> Make sure the value is never less than this value. | |||
* <max/> Make sure the value is never larger than this value. | * <max/> Make sure the value is never larger than this value. | |||
* </volume> or </pitch> | * </volume> or </pitch> | |||
* </event_name> | * </event_name> | |||
* | * | |||
* <event_name> | * <event_name> | |||
* </event_name> | * </event_name> | |||
* </fx> | * </fx> | |||
* | * | |||
* @param root The root node of the programs property tree. | * @param root The root node of the programs property tree. | |||
* @param child A pointer to the location of the current event as defined | * @param child A pointer to the location of the current event as defined | |||
* in the configuration file. | * in the configuration file. | |||
* @param sndmgr A pointer to a pre-initialized sound manager class. | * @param sgrp A pointer to a pre-initialized sample group class. | |||
* @param avionics A pointer to the pre-initialized avionics sample group | ||||
. | ||||
* @param path The path where the audio files remain. | * @param path The path where the audio files remain. | |||
*/ | */ | |||
virtual void init (SGPropertyNode *, SGPropertyNode *, SGSoundMgr *, | virtual void init (SGPropertyNode *, SGPropertyNode *, SGSampleGroup *, | |||
const string &); | SGSampleGroup *, const SGPath& currentDir); | |||
/** | /** | |||
* Check wheter an event has happened and if action has to be taken. | * Check whether an event has happened and if action has to be taken. | |||
*/ | */ | |||
virtual void update (double dt); | virtual void update (double dt); | |||
/** | /** | |||
* Stop taking action on the pre-defined events. | * Stop taking action on the pre-defined events. | |||
*/ | */ | |||
void stop(); | void stop(); | |||
protected: | protected: | |||
skipping to change at line 134 | skipping to change at line 140 | |||
double *intern; | double *intern; | |||
double factor; | double factor; | |||
double offset; | double offset; | |||
double min; | double min; | |||
double max; | double max; | |||
bool subtract; | bool subtract; | |||
} _snd_prop; | } _snd_prop; | |||
private: | private: | |||
SGSoundMgr * _mgr; | SGSampleGroup * _sgrp; | |||
SGSharedPtr<SGSoundSample> _sample; | SGSharedPtr<SGSoundSample> _sample; | |||
SGCondition * _condition; | SGSharedPtr<SGCondition> _condition; | |||
SGPropertyNode_ptr _property; | SGPropertyNode_ptr _property; | |||
bool _active; | bool _active; | |||
string _name; | std::string _name; | |||
int _mode; | int _mode; | |||
double _prev_value; | double _prev_value; | |||
double _dt_play; | double _dt_play; | |||
double _dt_stop; | double _dt_stop; | |||
double _stopping; // time after the sound should have stopped. | double _delay; // time after which the sound should be started (de | |||
// This is usefull for lost packets in in-trasit mod | fault: 0) | |||
e. | double _stopping; // time after the sound should have stopped. | |||
// This is useful for lost packets in in-transit mo | ||||
vector<_snd_prop> _volume; | de. | |||
vector<_snd_prop> _pitch; | bool _initialized; | |||
std::vector<_snd_prop> _volume; | ||||
std::vector<_snd_prop> _pitch; | ||||
}; | }; | |||
#endif // _SG_SOUND_HXX | #endif // _SG_SOUND_HXX | |||
End of changes. 16 change blocks. | ||||
23 lines changed or deleted | 32 lines changed or added | |||
zfstream.hxx | zfstream.hxx | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
// | // | |||
// This library is distributed in the hope that it will be useful, | // This library is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
// Library General Public License for more details. | // Library General Public License for more details. | |||
// | // | |||
// You should have received a copy of the GNU General Public License | // You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | // along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1, USA. | |||
// | // | |||
// $Id: zfstream.hxx,v 1.5 2006-03-08 18:16:08 mfranz Exp $ | // $Id$ | |||
#ifndef _zfstream_hxx | #ifndef _zfstream_hxx | |||
#define _zfstream_hxx | #define _zfstream_hxx | |||
#include <simgear/compiler.h> | #include <simgear/compiler.h> | |||
#include <zlib.h> | #include <zlib.h> | |||
#ifdef SG_HAVE_STD_INCLUDES | #include <streambuf> | |||
#include <istream> | ||||
# include <streambuf> | #define ios_openmode std::ios_base::openmode | |||
# include <istream> | #define ios_in std::ios_base::in | |||
#define ios_out std::ios_base::out | ||||
#define ios_app std::ios_base::app | ||||
#define ios_binary std::ios_base::binary | ||||
# define ios_openmode ios_base::openmode | #define ios_seekdir std::ios_base::seekdir | |||
# define ios_in ios_base::in | ||||
# define ios_out ios_base::out | ||||
# define ios_app ios_base::app | ||||
# define ios_binary ios_base::binary | ||||
# define ios_seekdir ios_base::seekdir | ||||
# define ios_badbit ios_base::badbit | ||||
# define ios_failbit ios_base::failbit | ||||
SG_USING_STD(streambuf); | ||||
SG_USING_STD(ios_base); | ||||
SG_USING_STD(streampos); | ||||
SG_USING_STD(streamoff); | ||||
#else | #define ios_badbit std::ios_base::badbit | |||
#define ios_failbit std::ios_base::failbit | ||||
# ifdef SG_HAVE_STREAMBUF | ||||
# include <streambuf.h> | ||||
# include <istream.h> | ||||
# else | ||||
# include <iostream.h> | ||||
# endif | ||||
//# define ios_openmode ios::open_mode | ||||
# define ios_openmode int | ||||
# define ios_in ios::in | ||||
# define ios_out ios::out | ||||
# define ios_app ios::app | ||||
#if defined(__GNUC__) && __GNUC_MINOR__ < 8 | ||||
# define ios_binary ios::bin | ||||
#else | ||||
# define ios_binary ios::binary | ||||
#endif | ||||
# define ios_seekdir ios::seek_dir | ||||
# define ios_badbit ios::badbit | ||||
# define ios_failbit ios::failbit | ||||
# include <simgear/sg_traits.hxx> | ||||
#endif // SG_HAVE_STD_INCLUDES | ||||
/** | /** | |||
* A C++ I/O streams interface to the zlib gz* functions. | * A C++ I/O streams interface to the zlib gz* functions. | |||
*/ | */ | |||
#ifdef SG_NEED_STREAMBUF_HACK | #ifdef SG_NEED_STREAMBUF_HACK | |||
class gzfilebuf : public __streambuf | class gzfilebuf : public __streambuf { | |||
typedef __streambuf parent; | ||||
#else | #else | |||
class gzfilebuf : public streambuf | class gzfilebuf : public std::streambuf { | |||
#endif | typedef std::streambuf parent; | |||
{ | ||||
public: | ||||
#ifndef SG_HAVE_STD_INCLUDES | ||||
typedef char_traits<char> traits_type; | ||||
typedef char_traits<char>::int_type int_type; | ||||
// typedef char_traits<char>::pos_type pos_type; | ||||
// typedef char_traits<char>::off_type off_type; | ||||
#endif | #endif | |||
public: | ||||
/** Constructor */ | /** Constructor */ | |||
gzfilebuf(); | gzfilebuf(); | |||
/** Destructor */ | /** Destructor */ | |||
virtual ~gzfilebuf(); | virtual ~gzfilebuf(); | |||
/** | /** | |||
* Open a stream | * Open a stream | |||
* @param name file name | * @param name file name | |||
* @param io_mode mdoe flags | * @param io_mode mode flags | |||
* @return file stream | * @return file stream | |||
*/ | */ | |||
gzfilebuf* open( const char* name, ios_openmode io_mode ); | gzfilebuf* open( const char* name, ios_openmode io_mode ); | |||
/** | /** | |||
* Attach to an existing file descriptor | * Attach to an existing file descriptor | |||
* @param file_descriptor file descriptor | * @param file_descriptor file descriptor | |||
* @param io_mode mode flags | * @param io_mode mode flags | |||
* @return file stream | * @return file stream | |||
*/ | */ | |||
gzfilebuf* attach( int file_descriptor, ios_openmode io_mode ); | gzfilebuf* attach( int file_descriptor, ios_openmode io_mode ); | |||
/** Close stream */ | /** Close stream */ | |||
gzfilebuf* close(); | gzfilebuf* close(); | |||
// int setcompressionlevel( int comp_level ); | int setcompressionlevel( int comp_level ); | |||
// int setcompressionstrategy( int comp_strategy ); | int setcompressionstrategy( int comp_strategy ); | |||
/** @return true if open, false otherwise */ | /** @return true if open, false otherwise */ | |||
bool is_open() const { return (file != NULL); } | bool is_open() const { return (file != NULL); } | |||
/** @return stream position */ | /** @return stream position */ | |||
virtual streampos seekoff( streamoff off, ios_seekdir way, int which ); | virtual std::streampos seekoff( std::streamoff off, ios_seekdir way, io s_openmode which ); | |||
/** sync the stream */ | /** sync the stream */ | |||
virtual int sync(); | virtual int sync(); | |||
protected: | protected: | |||
virtual int_type underflow(); | virtual int_type underflow(); | |||
#ifndef SG_HAVE_STD_INCLUDES | ||||
virtual int_type overflow( int_type c = traits_type::eof() ); | virtual int_type overflow( int_type c = parent::traits_type::eof() ); | |||
#else | bool out_waiting(); | |||
virtual int_type overflow( int_type c = streambuf::traits_type::eof() ) | char* base() {return obuffer;} | |||
; | int blen() {return obuf_size;} | |||
#endif | char allocate(); | |||
private: | private: | |||
int_type flushbuf(); | int_type flushbuf(); | |||
int fillbuf(); | int fillbuf(); | |||
// Convert io_mode to "rwab" string. | // Convert io_mode to "rwab" string. | |||
void cvt_iomode( char* mode_str, ios_openmode io_mode ); | void cvt_iomode( char* mode_str, ios_openmode io_mode ); | |||
private: | private: | |||
gzFile file; | gzFile file; | |||
ios_openmode mode; | ios_openmode mode; | |||
bool own_file_descriptor; | bool own_file_descriptor; | |||
// Get (input) buffer. | // Get (input) buffer. | |||
int ibuf_size; | int ibuf_size; | |||
char* ibuffer; | char* ibuffer; | |||
enum { page_size = 4096 }; | // Put (output) buffer. | |||
int obuf_size; | ||||
char* obuffer; | ||||
enum { page_size = 65536 }; | ||||
private: | private: | |||
// Not defined | // Not defined | |||
gzfilebuf( const gzfilebuf& ); | gzfilebuf( const gzfilebuf& ); | |||
void operator= ( const gzfilebuf& ); | void operator= ( const gzfilebuf& ); | |||
}; | }; | |||
/** | /** | |||
* document me | * document me | |||
*/ | */ | |||
struct gzifstream_base | struct gzifstream_base | |||
{ | { | |||
gzifstream_base() {} | gzifstream_base() {} | |||
gzfilebuf gzbuf; | gzfilebuf gzbuf; | |||
}; | }; | |||
/** | ||||
* document me too | ||||
*/ | ||||
struct gzofstream_base | ||||
{ | ||||
gzofstream_base() {} | ||||
gzfilebuf gzbuf; | ||||
}; | ||||
#endif // _zfstream_hxx | #endif // _zfstream_hxx | |||
End of changes. 14 change blocks. | ||||
70 lines changed or deleted | 41 lines changed or added | |||