]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/point3d.hxx
Modified Files:
[simgear.git] / simgear / math / point3d.hxx
index 10b14533dbdcbcad213c11219bb527eca40f4895..529674fa4a91eacf90b392f854c619d90163c0aa 100644 (file)
@@ -1,22 +1,28 @@
-// point3d.hxx -- a 3d point class.  
+/**
+ * \file point3d.hxx
+ * A 3d point class (depricated).  This class is depricated and we are
+ * in the process of removing all usage of it in favor of plib's "sg"
+ * library of point, vector, and math routines.  Plib's sg lib is less
+ * object oriented, but integrates more seamlessly with opengl.
+ *
+ * Adapted from algebra3 by Jean-Francois Doue, started October 1998.
+ */
+
+// Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
-// Adapted from algebra3 by Jean-Francois Doue, started October 1998.
+// 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.
 //
-// Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
-//
-// 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
+// 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
-// 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
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #define _POINT3D_HXX
 
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
+#endif
 
 #include <simgear/compiler.h>
 
-#ifdef FG_MATH_EXCEPTION_CLASH
+#ifdef SG_MATH_EXCEPTION_CLASH
 # define exception c_exception
 #endif
 
-#ifdef FG_HAVE_STD_INCLUDES
+#ifdef SG_HAVE_STD_INCLUDES
 # include <iostream>
 # include <cassert>
 # include <cmath>
 # include <math.h>
 #endif
 
+#include "SGMath.hxx"
+
 // I don't understand ... <math.h> or <cmath> should be included
-// already depending on how you defined FG_HAVE_STD_INCLUDES, but I
+// already depending on how you defined SG_HAVE_STD_INCLUDES, but I
 // can go ahead and add this -- CLO
 #ifdef __MWERKS__
-FG_USING_NAMESPACE(std);
+SG_USING_NAMESPACE(std);
 #endif
 
-#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
-FG_USING_STD(ostream);
-FG_USING_STD(istream);
-#endif
+SG_USING_STD(ostream);
+SG_USING_STD(istream);
 
 
 const double fgPoint3_Epsilon = 0.0000001;
@@ -70,11 +76,9 @@ Point3D operator- (const Point3D& p);                    // -p1
 bool operator== (const Point3D& a, const Point3D& b);  // p1 == p2?
 
 
-///////////////////////////
-//
-// 3D Point
-//
-///////////////////////////
+/**
+ * 3D Point class.
+ */
 
 class Point3D {
 
@@ -84,13 +88,16 @@ protected:
 
 public:
 
-    // Constructors
-
+    /** Default constructor */
     Point3D();
     Point3D(const double x, const double y, const double z);
     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<double>& cart);
+
     // Assignment operators
 
     Point3D& operator = ( const Point3D& p );   // assignment of a Point3D
@@ -102,6 +109,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 
 
@@ -118,6 +129,9 @@ public:
     double radius() const; // polar radius
     double elev() const;   // geodetic elevation (if specifying a surface point)
 
+    SGGeod toSGGeod(void) const;
+    SGGeoc toSGGeoc(void) const;
+
     // friends
     friend Point3D operator - (const Point3D& p);                  // -p1
     friend bool operator == (const Point3D& a, const Point3D& b);  // p1 == p2?
@@ -177,7 +191,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)
 {
@@ -194,6 +212,33 @@ 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<double>& cart)
+{
+  Point3D pt;
+  pt.setx(cart.x());
+  pt.sety(cart.y());
+  pt.setz(cart.z());
+  return pt;
+}
+
 // ASSIGNMENT OPERATORS
 
 inline Point3D& Point3D::operator = (const Point3D& p)
@@ -234,6 +279,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)
@@ -262,6 +323,23 @@ 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;
+}
 
 // FRIENDS