X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2Fpoint3d.hxx;h=089da93aa3f1ab9bc069090d47f59cdf81ca1e43;hb=006f90997a8eef6704de2511e38fcc786672308d;hp=0cc469b90feb983f8109f2c686759351b17945d3;hpb=75911b6c643d8e5597565bc63c34bdc2009a037a;p=simgear.git diff --git a/simgear/math/point3d.hxx b/simgear/math/point3d.hxx index 0cc469b9..089da93a 100644 --- a/simgear/math/point3d.hxx +++ b/simgear/math/point3d.hxx @@ -8,7 +8,7 @@ * Adapted from algebra3 by Jean-Francois Doue, started October 1998. */ -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// Copyright (C) 1998 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 @@ -20,10 +20,9 @@ // 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. +// 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-1301, USA. // // $Id$ @@ -32,40 +31,18 @@ #define _POINT3D_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif - -#include - -#ifdef SG_MATH_EXCEPTION_CLASH -# define exception c_exception #endif -#ifdef SG_HAVE_STD_INCLUDES -# include -# include -# include -#else -# include -# include -# include -#endif - -#include - -// I don't understand ... or 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_NAMESPACE(std); -#endif +#include -#ifndef SG_HAVE_NATIVE_SGI_COMPILERS -SG_USING_STD(ostream); -SG_USING_STD(istream); -#endif +#include +#include +#include +#include +#include "SGMath.hxx" const double fgPoint3_Epsilon = 0.0000001; @@ -73,8 +50,8 @@ enum {PX, PY, PZ}; // axes // Kludge for msvc++ 6.0 - requires forward decls of friend functions. class Point3D; -istream& operator>> ( istream&, Point3D& ); -ostream& operator<< ( ostream&, const Point3D& ); +std::istream& operator>> ( std::istream&, Point3D& ); +std::ostream& operator<< ( std::ostream&, const Point3D& ); Point3D operator- (const Point3D& p); // -p1 bool operator== (const Point3D& a, const Point3D& b); // p1 == p2? @@ -97,6 +74,12 @@ public: explicit Point3D(const double d); Point3D(const Point3D &p); + static Point3D fromSGGeod(const SGGeod& geod); + static Point3D fromSGGeoc(const SGGeoc& geoc); + static Point3D fromSGVec3(const SGVec3& cart); + static Point3D fromSGVec3(const SGVec3& cart); + static Point3D fromSGVec2(const SGVec2& cart); + // Assignment operators Point3D& operator = ( const Point3D& p ); // assignment of a Point3D @@ -108,6 +91,10 @@ public: void setx(const double x); void sety(const double y); void setz(const double z); + void setlon(const double x); + void setlat(const double y); + void setradius(const double z); + void setelev(const double z); // Queries @@ -124,11 +111,18 @@ public: double radius() const; // polar radius double elev() const; // geodetic elevation (if specifying a surface point) + SGGeod toSGGeod(void) const; + SGGeoc toSGGeoc(void) const; + + SGVec3d toSGVec3d(void) const; + SGVec3f toSGVec3f(void) const; + SGVec2f toSGVec2f(void) const; + // friends friend Point3D operator - (const Point3D& p); // -p1 friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2? - friend istream& operator>> ( istream&, Point3D& ); - friend ostream& operator<< ( ostream&, const Point3D& ); + friend std::istream& operator>> ( std::istream&, Point3D& ); + friend std::ostream& operator<< ( std::ostream&, const Point3D& ); // Special functions double distance3D(const Point3D& a) const; // distance between @@ -137,8 +131,8 @@ public: // input from stream -inline istream& -operator >> ( istream& in, Point3D& p) +inline std::istream& +operator >> ( std::istream& in, Point3D& p) { char c; @@ -169,8 +163,8 @@ operator >> ( istream& in, Point3D& p) return in; } -inline ostream& -operator<< ( ostream& out, const Point3D& p ) +inline std::ostream& +operator<< ( std::ostream& out, const Point3D& p ) { return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ]; } @@ -183,7 +177,11 @@ operator<< ( ostream& out, const Point3D& p ) // CONSTRUCTORS -inline Point3D::Point3D() {} +inline Point3D::Point3D() +{ + n[PX] = n[PY] = 0.0; + n[PZ] = -9999.0; +} inline Point3D::Point3D(const double x, const double y, const double z) { @@ -200,6 +198,51 @@ inline Point3D::Point3D(const Point3D& p) n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ]; } +inline Point3D Point3D::fromSGGeod(const SGGeod& geod) +{ + Point3D pt; + pt.setlon(geod.getLongitudeRad()); + pt.setlat(geod.getLatitudeRad()); + pt.setelev(geod.getElevationM()); + return pt; +} + +inline Point3D Point3D::fromSGGeoc(const SGGeoc& geoc) +{ + Point3D pt; + pt.setlon(geoc.getLongitudeRad()); + pt.setlat(geoc.getLatitudeRad()); + pt.setradius(geoc.getRadiusM()); + return pt; +} + +inline Point3D Point3D::fromSGVec3(const SGVec3& cart) +{ + Point3D pt; + pt.setx(cart.x()); + pt.sety(cart.y()); + pt.setz(cart.z()); + return pt; +} + +inline Point3D Point3D::fromSGVec3(const SGVec3& cart) +{ + Point3D pt; + pt.setx(cart.x()); + pt.sety(cart.y()); + pt.setz(cart.z()); + return pt; +} + +inline Point3D Point3D::fromSGVec2(const SGVec2& cart) +{ + Point3D pt; + pt.setx(cart.x()); + pt.sety(cart.y()); + pt.setz(0); + return pt; +} + // ASSIGNMENT OPERATORS inline Point3D& Point3D::operator = (const Point3D& p) @@ -240,6 +283,22 @@ inline void Point3D::setz(const double z) { n[PZ] = z; } +inline void Point3D::setlon(const double x) { + n[PX] = x; +} + +inline void Point3D::setlat(const double y) { + n[PY] = y; +} + +inline void Point3D::setradius(const double z) { + n[PZ] = z; +} + +inline void Point3D::setelev(const double z) { + n[PZ] = z; +} + // QUERIES inline double& Point3D::operator [] ( int i) @@ -268,6 +327,38 @@ inline double Point3D::radius() const { return n[PZ]; } inline double Point3D::elev() const { return n[PZ]; } +inline SGGeod Point3D::toSGGeod(void) const +{ + SGGeod geod; + geod.setLongitudeRad(lon()); + geod.setLatitudeRad(lat()); + geod.setElevationM(elev()); + return geod; +} + +inline SGGeoc Point3D::toSGGeoc(void) const +{ + SGGeoc geoc; + geoc.setLongitudeRad(lon()); + geoc.setLatitudeRad(lat()); + geoc.setRadiusM(radius()); + return geoc; +} + +inline SGVec3d Point3D::toSGVec3d(void) const +{ + return SGVec3d(x(), y(), z()); +} + +inline SGVec3f Point3D::toSGVec3f(void) const +{ + return SGVec3f(x(), y(), z()); +} + +inline SGVec2f Point3D::toSGVec2f(void) const +{ + return SGVec2f(x(), y()); +} // FRIENDS