From: James Turner Date: Mon, 26 Jul 2010 10:24:16 +0000 (+0100) Subject: Remove deprecated vector classes - finally! X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aa859c488f21d0b1f8d54c657e23a738dcadacca;p=simgear.git Remove deprecated vector classes - finally! --- diff --git a/projects/VC90/SimGear.vcproj b/projects/VC90/SimGear.vcproj index e80a935c..af9ff1aa 100644 --- a/projects/VC90/SimGear.vcproj +++ b/projects/VC90/SimGear.vcproj @@ -559,14 +559,6 @@ RelativePath="..\..\simgear\math\localconsts.hxx" > - - - - @@ -599,14 +591,6 @@ RelativePath="..\..\simgear\math\sphrintp.h" > - - - - #include #include -#include -#include #include #include #include @@ -42,7 +40,7 @@ using std::vector; typedef struct { - Point3D pt; + SGVec3d pt; int depth; int prev; } lt_tree_seg; @@ -146,7 +144,7 @@ public: ~SGLightning(); void lt_Render(void); void lt_build(void); - void lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize); + void lt_build_tree_branch(int tree_nr, SGVec3d &start, float energy, int nbseg, float segsize); // contains all the segments of the lightning lt_tree_seg lt_tree[MAX_LT_TREE_SEG]; @@ -381,7 +379,7 @@ void SGEnviro::callback_cloud(float heading, float alt, float radius, int family if(lightning_enable_state && min_time_before_lt <= 0.0 && (family == SGNewCloud::CLFamilly_cb) && dist < 15000.0 * 15000.0 && sg_random() > 0.9f) { double lat, lon; - Point3D orig, dest; + SGVec3d orig, dest; orig.setlat(last_lat * SG_DEGREES_TO_RADIANS ); orig.setlon(last_lon * SG_DEGREES_TO_RADIANS ); orig.setelev(0.0); @@ -560,169 +558,21 @@ SGLightning::~SGLightning() { } // lightning rendering code -void SGLightning::lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize) { +void SGLightning::lt_build_tree_branch(int tree_nr, SGVec3d &start, float energy, int nbseg, float segsize) { // OSGFIXME return; - - sgVec3 dir, newdir; - int nseg = 0; - Point3D pt = start; - if( nbseg == 50 ) - sgSetVec3( dir, 0.0, -1.0, 0.0 ); - else { - sgSetVec3( dir, sg_random() - 0.5f, sg_random() - 0.5f, sg_random() - 0.5f); - sgNormaliseVec3(dir); - } - if( nb_tree >= MAX_LT_TREE_SEG ) - return; - - lt_tree[nb_tree].depth = tree_nr; - nseg = 0; - lt_tree[nb_tree].pt = pt; - lt_tree[nb_tree].prev = -1; - nb_tree ++; - - // TODO:check agl - while(nseg < nbseg && pt.y() > 0.0) { - int prev = nb_tree - 1; - nseg++; - // add a branch - if( energy * sg_random() > 0.8f ) - lt_build_tree_branch(tree_nr + 1, pt, energy * 0.9f, nbseg == 50 ? 10 : static_cast(nbseg * 0.4f), segsize * 0.7f); - - if( nb_tree >= MAX_LT_TREE_SEG ) - return; - sgSetVec3(newdir, (sg_random() - 0.5f), (sg_random() - 0.5f) - (nbseg == 50 ? 0.5f : 0.0), (sg_random() - 0.5f)); - sgNormaliseVec3(newdir); - sgAddVec3( dir, newdir); - sgNormaliseVec3(dir); - sgVec3 scaleDir; - sgScaleVec3( scaleDir, dir, segsize * energy * 0.5f ); - pt[PX] += scaleDir[0]; - pt[PY] += scaleDir[1]; - pt[PZ] += scaleDir[2]; - - lt_tree[nb_tree].depth = tree_nr; - lt_tree[nb_tree].pt = pt; - lt_tree[nb_tree].prev = prev; - nb_tree ++; - } } void SGLightning::lt_build(void) { // OSGFIXME return; - Point3D top; - nb_tree = 0; - top[PX] = 0 ; - top[PY] = alt; - top[PZ] = 0; - lt_build_tree_branch(0, top, 1.0, 50, top[PY] / 8.0); - if( ! sgEnviro.sampleGroup ) - return; - Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 ); - Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 ); - double course = 0.0, dist = 0.0; - calc_gc_course_dist( dest, start, &course, &dist ); - if( dist < 10000.0 && ! sgEnviro.snd_playing && (dist < sgEnviro.snd_dist || ! sgEnviro.snd_active) ) { - sgEnviro.snd_timer = 0.0; - sgEnviro.snd_wait = dist / 340; - sgEnviro.snd_dist = dist; - sgEnviro.snd_pos_lat = lat; - sgEnviro.snd_pos_lon = lon; - sgEnviro.snd_active = true; - sgEnviro.snd_playing = false; - } + } void SGLightning::lt_Render(void) { // OSGFIXME return; - float flash = 0.5; - if( fmod(sgEnviro.elapsed_time*100.0, 100.0) > 50.0 ) - flash = sg_random() * 0.75f + 0.25f; - float h = lt_tree[0].pt[PY]; - sgVec4 col={0.62f, 0.83f, 1.0f, 1.0f}; - sgVec4 c; - -#define DRAW_SEG() \ - {glColorMaterial(GL_FRONT, GL_EMISSION); \ - glDisable(GL_LINE_SMOOTH); glBegin(GL_LINES); \ - glColor4fv(c); \ - glVertex3f(lt_tree[n].pt[PX], lt_tree[n].pt[PZ], lt_tree[n].pt[PY]); \ - glVertex3f(lt_tree[lt_tree[n].prev].pt[PX], lt_tree[lt_tree[n].prev].pt[PZ], lt_tree[lt_tree[n].prev].pt[PY]); \ - glEnd(); glEnable(GL_LINE_SMOOTH);} - - glDepthMask( GL_FALSE ); - glEnable(GL_BLEND); - glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glBindTexture(GL_TEXTURE_2D, 0); - - glDisable(GL_LIGHTING); - glDisable( GL_FOG ); - glPushMatrix(); - sgMat4 modelview, tmp; - // OSGFIXME -// ssgGetModelviewMatrix( modelview ); - sgCopyMat4( tmp, sgEnviro.transform ); - sgPostMultMat4( tmp, modelview ); - // OSGFIXME -// ssgLoadModelviewMatrix( tmp ); - - Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 ); - Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 ); - double course = 0.0, dist = 0.0; - calc_gc_course_dist( dest, start, &course, &dist ); - double ax = 0.0, ay = 0.0; - ax = cos(course) * dist; - ay = sin(course) * dist; - - glTranslatef( ax, ay, -sgEnviro.last_alt ); - - sgEnviro.radarEcho.push_back( SGWxRadarEcho ( course, 0.0, 0.0, dist, age, true, 0 ) ); - - for( int n = 0 ; n < nb_tree ; n++ ) { - if( lt_tree[n].prev < 0 ) - continue; - - float t1 = sgLerp(0.5, 1.0, lt_tree[n].pt[PY] / h); - t1 *= flash; - if( lt_tree[n].depth >= 2 ) { - glLineWidth(3); - sgScaleVec4(c, col, t1 * 0.6f); - DRAW_SEG(); - } else { - if( lt_tree[n].depth == 0 ) { - glLineWidth(12); - sgScaleVec4(c, col, t1 * 0.5f); - DRAW_SEG(); - - glLineWidth(6); - sgScaleVec4(c, col, t1); - DRAW_SEG(); - } else { - glLineWidth(6); - sgScaleVec4(c, col, t1 * 0.7f); - DRAW_SEG(); - } - - if( lt_tree[n].depth == 0 ) - glLineWidth(3); - else - glLineWidth(2); - - sgSetVec4(c, t1, t1, t1, t1); - DRAW_SEG(); - } - - } - glLineWidth(1); - glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; - glPopMatrix(); - glDepthMask( GL_TRUE ); - glEnable( GL_FOG ); - glEnable(GL_LIGHTING); } void SGEnviro::addLightning(double lon, double lat, double alt) { @@ -737,53 +587,6 @@ void SGEnviro::addLightning(double lon, double lat, double alt) { void SGEnviro::drawLightning(void) { // OSGFIXME return; - list_of_lightning::iterator iLightning; - // play 'thunder' for lightning - if( snd_active ) { - if( !snd_playing ) { - // wait until sound has reached us - snd_timer += dt; - if( snd_timer >= snd_wait ) { - snd_playing = true; - // compute relative position of lightning - Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 ); - Point3D dest( snd_pos_lon*SG_DEGREES_TO_RADIANS, snd_pos_lat*SG_DEGREES_TO_RADIANS, 0.0 ); - double course = 0.0, dist = 0.0; - calc_gc_course_dist( dest, start, &course, &dist ); - double ax = 0.0, ay = 0.0; - ax = cos(course) * dist; - ay = sin(course) * dist; - SGSharedPtr snd = sampleGroup->find("thunder"); - if( snd ) { - SGVec3d pos = SGVec3d(ax, ay, -sgEnviro.last_alt); - snd->set_position(pos); - snd->play_once(); - } - } - } else { - if( !sampleGroup->is_playing("thunder") ) { - snd_active = false; - snd_playing = false; - } - } - - } - if( ! lightning_enable_state ) - return; - - for( iLightning = lightnings.begin() ; iLightning != lightnings.end() ; iLightning++ ) { - if( dt ) - if( sg_random() > 0.95f ) - (*iLightning)->lt_build(); - (*iLightning)->lt_Render(); - (*iLightning)->age -= dt; - if( (*iLightning)->age < 0.0 ) { - delete (*iLightning); - lightnings.erase( iLightning ); - break; - } - } - } diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 3c321308..faed1e68 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -38,6 +38,7 @@ #include #include +#include #include "lowlevel.hxx" #include "sg_binobj.hxx" @@ -115,51 +116,6 @@ public: } }; - -// calculate the center of a list of points, by taking the halfway -// point between the min and max points. -Point3D sgCalcCenter( point_list& wgs84_nodes ) { - Point3D p, min, max; - - if ( wgs84_nodes.size() ) { - min = max = wgs84_nodes[0]; - } else { - min = max = Point3D( 0 ); - } - - for ( int i = 0; i < (int)wgs84_nodes.size(); ++i ) { - p = wgs84_nodes[i]; - - if ( p.x() < min.x() ) { min.setx( p.x() ); } - if ( p.y() < min.y() ) { min.sety( p.y() ); } - if ( p.z() < min.z() ) { min.setz( p.z() ); } - - if ( p.x() > max.x() ) { max.setx( p.x() ); } - if ( p.y() > max.y() ) { max.sety( p.y() ); } - if ( p.z() > max.z() ) { max.setz( p.z() ); } - } - - return ( min + max ) / 2.0; -} - -// calculate the bounding sphere. Center is the center of the -// tile and zero elevation -double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ) { - double dist_squared; - double radius_squared = 0; - - for ( int i = 0; i < (int)wgs84_nodes.size(); ++i ) { - dist_squared = center.distance3Dsquared( wgs84_nodes[i] ); - if ( dist_squared > radius_squared ) { - radius_squared = dist_squared; - } - } - - return sqrt(radius_squared); -} - - - // read object properties static void read_object( gzFile fp, int obj_type, @@ -1128,19 +1084,16 @@ bool SGBinObject::write_ascii( const string& base, const string& name, } // cout << "group = " << start << " to " << end - 1 << endl; - // make a list of points for the group - point_list group_nodes; - group_nodes.clear(); - SGVec3d bs_center; - double bs_radius = 0; - for ( i = start; i < end; ++i ) { - for ( j = 0; j < (int)tris_v[i].size(); ++j ) { - group_nodes.push_back( Point3D::fromSGVec3(wgs84_nodes[ tris_v[i][j] ]) ); - bs_center = sgCalcCenter( group_nodes ).toSGVec3d(); - bs_radius = sgCalcBoundingRadius( Point3D::fromSGVec3(bs_center), group_nodes ); - } - } - + SGSphered d; + for ( i = start; i < end; ++i ) { + for ( j = 0; j < (int)tris_v[i].size(); ++j ) { + d.expandBy(wgs84_nodes[ tris_v[i][j] ]); + } + } + + SGVec3d bs_center = d.getCenter(); + double bs_radius = d.getRadius(); + // write group headers fprintf(fp, "\n"); fprintf(fp, "# usemtl %s\n", material.c_str()); @@ -1179,18 +1132,16 @@ bool SGBinObject::write_ascii( const string& base, const string& name, } // cout << "group = " << start << " to " << end - 1 << endl; - // make a list of points for the group - point_list group_nodes; - group_nodes.clear(); - SGVec3d bs_center; - double bs_radius = 0; - for ( i = start; i < end; ++i ) { - for ( j = 0; j < (int)strips_v[i].size(); ++j ) { - group_nodes.push_back( Point3D::fromSGVec3(wgs84_nodes[ strips_v[i][j] ]) ); - bs_center = sgCalcCenter( group_nodes ).toSGVec3d(); - bs_radius = sgCalcBoundingRadius( Point3D::fromSGVec3(bs_center), group_nodes ); - } - } + + SGSphered d; + for ( i = start; i < end; ++i ) { + for ( j = 0; j < (int)tris_v[i].size(); ++j ) { + d.expandBy(wgs84_nodes[ tris_v[i][j] ]); + } + } + + SGVec3d bs_center = d.getCenter(); + double bs_radius = d.getRadius(); // write group headers fprintf(fp, "\n"); diff --git a/simgear/io/sg_binobj.hxx b/simgear/io/sg_binobj.hxx index be77d586..13a826bc 100644 --- a/simgear/io/sg_binobj.hxx +++ b/simgear/io/sg_binobj.hxx @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -45,7 +44,7 @@ /** 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::const_iterator const_group_list_iterator; @@ -126,9 +125,7 @@ public: inline unsigned short get_version() const { return version; } - inline Point3D get_gbs_center() const { return Point3D::fromSGVec3(gbs_center); } - inline void set_gbs_center( const Point3D& p ) { gbs_center = p.toSGVec3d(); } - inline const SGVec3d& get_gbs_center2() const { return gbs_center; } + inline const SGVec3d& get_gbs_center() const { return gbs_center; } inline void set_gbs_center( const SGVec3d& p ) { gbs_center = p; } inline float get_gbs_radius() const { return gbs_radius; } @@ -138,40 +135,16 @@ public: { return wgs84_nodes; } inline void set_wgs84_nodes( const std::vector& n ) { wgs84_nodes = n; } - inline void set_wgs84_nodes( const point_list& n ) - { - wgs84_nodes.resize(n.size()); - for (unsigned i = 0; i < wgs84_nodes.size(); ++i) - wgs84_nodes[i] = n[i].toSGVec3d(); - } inline const std::vector& get_colors() const { return colors; } inline void set_colors( const std::vector& c ) { colors = c; } - inline void set_colors( const point_list& c ) - { - colors.resize(c.size()); - for (unsigned i = 0; i < colors.size(); ++i) - colors[i] = SGVec4f(c[i].toSGVec3f(), 1); - } - + inline const std::vector& get_normals() const { return normals; } inline void set_normals( const std::vector& n ) { normals = n; } - inline void set_normals( const point_list& n ) - { - normals.resize(n.size()); - for (unsigned i = 0; i < normals.size(); ++i) - normals[i] = n[i].toSGVec3f(); - } - + inline const std::vector& get_texcoords() const { return texcoords; } inline void set_texcoords( const std::vector& t ) { texcoords = t; } - inline void set_texcoords( const point_list& t ) - { - texcoords.resize(t.size()); - for (unsigned i = 0; i < texcoords.size(); ++i) - texcoords[i] = t[i].toSGVec2f(); - } - + inline const group_list& get_pts_v() const { return pts_v; } inline void set_pts_v( const group_list& g ) { pts_v = g; } inline const group_list& get_pts_n() const { return pts_n; } @@ -249,26 +222,4 @@ public: 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 diff --git a/simgear/math/Makefile.am b/simgear/math/Makefile.am index 5474f297..e82e15f1 100644 --- a/simgear/math/Makefile.am +++ b/simgear/math/Makefile.am @@ -24,12 +24,9 @@ lib_LIBRARIES = libsgmath.a include_HEADERS = \ interpolater.hxx \ leastsqs.hxx \ - point3d.hxx \ - polar3d.hxx \ sg_geodesy.hxx \ sg_random.h \ sg_types.hxx \ - vector.hxx \ Math.hxx \ SGBox.hxx \ SGCMath.hxx \ @@ -59,7 +56,6 @@ libsgmath_a_SOURCES = \ interpolater.cxx \ leastsqs.cxx \ sg_random.c \ - vector.cxx \ SGGeod.cxx \ SGGeodesy.cxx diff --git a/simgear/math/point3d.hxx b/simgear/math/point3d.hxx deleted file mode 100644 index 089da93a..00000000 --- a/simgear/math/point3d.hxx +++ /dev/null @@ -1,438 +0,0 @@ -/** - * \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 -// -// 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 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$ - - -#ifndef _POINT3D_HXX -#define _POINT3D_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include - -#include -#include -#include -#include - -#include "SGMath.hxx" - -const double fgPoint3_Epsilon = 0.0000001; - -enum {PX, PY, PZ}; // axes - -// Kludge for msvc++ 6.0 - requires forward decls of friend functions. -class 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? - - -/** - * 3D Point class. - */ - -class Point3D { - -protected: - - double n[3]; - -public: - - /** 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& cart); - static Point3D fromSGVec3(const SGVec3& cart); - static Point3D fromSGVec2(const SGVec2& cart); - - // Assignment operators - - Point3D& operator = ( const Point3D& p ); // assignment of a Point3D - Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D - Point3D& operator -= ( const Point3D& p ); // decrementation by a Point3D - Point3D& operator *= ( const double d ); // multiplication by a constant - Point3D& operator /= ( const double d ); // division by a constant - - 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 - - double& operator [] ( int i); // indexing - double operator[] (int i) const; // read-only indexing - - inline const double *get_n() const { return n; }; - double x() const; // cartesian x - double y() const; // cartesian y - double z() const; // cartesian z - - double lon() const; // polar longitude - double lat() const; // polar latitude - 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 std::istream& operator>> ( std::istream&, Point3D& ); - friend std::ostream& operator<< ( std::ostream&, const Point3D& ); - - // Special functions - double distance3D(const Point3D& a) const; // distance between - double distance3Dsquared(const Point3D& a) const; // distance between ^ 2 -}; - - -// input from stream -inline std::istream& -operator >> ( std::istream& in, Point3D& p) -{ - char c; - - in >> p.n[PX]; - - // read past optional comma - while ( in.get(c) ) { - if ( (c != ' ') && (c != ',') ) { - // push back on the stream - in.putback(c); - break; - } - } - - in >> p.n[PY]; - - // read past optional comma - while ( in.get(c) ) { - if ( (c != ' ') && (c != ',') ) { - // push back on the stream - in.putback(c); - break; - } - } - - in >> p.n[PZ]; - - return in; -} - -inline std::ostream& -operator<< ( std::ostream& out, const Point3D& p ) -{ - return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ]; -} - -/////////////////////////// -// -// Point3D Member functions -// -/////////////////////////// - -// CONSTRUCTORS - -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) -{ - n[PX] = x; n[PY] = y; n[PZ] = z; -} - -inline Point3D::Point3D(const double d) -{ - n[PX] = n[PY] = n[PZ] = d; -} - -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) -{ - n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ]; return *this; -} - -inline Point3D& Point3D::operator += ( const Point3D& p ) -{ - n[PX] += p.n[PX]; n[PY] += p.n[PY]; n[PZ] += p.n[PZ]; return *this; -} - -inline Point3D& Point3D::operator -= ( const Point3D& p ) -{ - n[PX] -= p.n[PX]; n[PY] -= p.n[PY]; n[PZ] -= p.n[PZ]; return *this; -} - -inline Point3D& Point3D::operator *= ( const double d ) -{ - n[PX] *= d; n[PY] *= d; n[PZ] *= d; return *this; -} - -inline Point3D& Point3D::operator /= ( const double d ) -{ - double d_inv = 1./d; n[PX] *= d_inv; n[PY] *= d_inv; n[PZ] *= d_inv; - return *this; -} - -inline void Point3D::setx(const double x) { - n[PX] = x; -} - -inline void Point3D::sety(const double y) { - n[PY] = y; -} - -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) -{ - assert(! (i < PX || i > PZ)); - return n[i]; -} - -inline double Point3D::operator [] ( int i) const { - assert(! (i < PX || i > PZ)); - return n[i]; -} - - -inline double Point3D::x() const { return n[PX]; } - -inline double Point3D::y() const { return n[PY]; } - -inline double Point3D::z() const { return n[PZ]; } - -inline double Point3D::lon() const { return n[PX]; } - -inline double Point3D::lat() const { return n[PY]; } - -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 - -inline Point3D operator - (const Point3D& a) -{ - return Point3D(-a.n[PX],-a.n[PY],-a.n[PZ]); -} - -inline Point3D operator + (const Point3D& a, const Point3D& b) -{ - return Point3D(a) += b; -} - -inline Point3D operator - (const Point3D& a, const Point3D& b) -{ - return Point3D(a) -= b; -} - -inline Point3D operator * (const Point3D& a, const double d) -{ - return Point3D(a) *= d; -} - -inline Point3D operator * (const double d, const Point3D& a) -{ - return a*d; -} - -inline Point3D operator / (const Point3D& a, const double d) -{ - return Point3D(a) *= (1.0 / d ); -} - -inline bool operator == (const Point3D& a, const Point3D& b) -{ - return - fabs(a.n[PX] - b.n[PX]) < fgPoint3_Epsilon && - fabs(a.n[PY] - b.n[PY]) < fgPoint3_Epsilon && - fabs(a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon; -} - -inline bool operator != (const Point3D& a, const Point3D& b) -{ - return !(a == b); -} - -// Special functions - -inline double -Point3D::distance3D(const Point3D& a ) const -{ - double x, y, z; - - x = n[PX] - a.n[PX]; - y = n[PY] - a.n[PY]; - z = n[PZ] - a.n[PZ]; - - return sqrt(x*x + y*y + z*z); -} - - -inline double -Point3D::distance3Dsquared(const Point3D& a ) const -{ - double x, y, z; - - x = n[PX] - a.n[PX]; - y = n[PY] - a.n[PY]; - z = n[PZ] - a.n[PZ]; - - return(x*x + y*y + z*z); -} - - -#endif // _POINT3D_HXX - - diff --git a/simgear/math/polar3d.hxx b/simgear/math/polar3d.hxx deleted file mode 100644 index 9721dc72..00000000 --- a/simgear/math/polar3d.hxx +++ /dev/null @@ -1,69 +0,0 @@ -/** - * \file polar3d.hxx - * Routines to deal with polar math and transformations. - */ - -// Written by Curtis Olson, started June 1997. -// -// Copyright (C) 1997 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 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$ - - -#ifndef _POLAR3D_HXX -#define _POLAR3D_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include -#include "SGMath.hxx" - -/** - * Calculate new lon/lat given starting lon/lat, and offset radial, and - * distance. NOTE: starting point is specifed in radians, distance is - * specified in meters (and converted internally to radians) - * ... assumes a spherical world. - * @param orig specified in polar coordinates - * @param course offset radial - * @param dist offset distance - * @return destination point in polar coordinates - */ -inline Point3D calc_gc_lon_lat(const Point3D& orig, double course, double dist) -{ return Point3D::fromSGGeoc(orig.toSGGeoc().advanceRadM(course, dist)); } - - -/** - * Calculate course/dist given two spherical points. - * @param start starting point - * @param dest ending point - * @param course resulting course - * @param dist resulting distance - */ -inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest, - double *course, double *dist ) -{ - SGGeoc gs = start.toSGGeoc(); - SGGeoc gd = dest.toSGGeoc(); - *course = SGGeoc::courseRad(gs, gd); - *dist = SGGeoc::distanceM(gs, gd); -} - -#endif // _POLAR3D_HXX - diff --git a/simgear/math/sg_geodesy.hxx b/simgear/math/sg_geodesy.hxx index f19e4358..2ee46e08 100644 --- a/simgear/math/sg_geodesy.hxx +++ b/simgear/math/sg_geodesy.hxx @@ -1,7 +1,6 @@ #ifndef _SG_GEODESY_HXX #define _SG_GEODESY_HXX -#include #include "SGMath.hxx" // Compatibility header. @@ -52,21 +51,6 @@ inline void sgCartToGeod(const double* xyz, double* lat, double* lon, double* al *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(p.x(), p.y(), p.z()), geod); - return Point3D::fromSGGeod(geod); -} - - /** * Convert a geodetic lat/lon/altitude to a cartesian point. * @@ -84,20 +68,6 @@ inline void sgGeodToCart(double lat, double lon, double alt, double* xyz) 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 cart; - SGGeodesy::SGGeodToCart(SGGeod::fromRadM(geod.lon(), geod.lat(), geod.elev()), cart); - return Point3D::fromSGVec3(cart); -} - /** * Given a starting position and an offset radial and distance, * calculate an ending positon on a wgs84 ellipsoid. diff --git a/simgear/math/sg_types.hxx b/simgear/math/sg_types.hxx index f413c26b..36a2a35a 100644 --- a/simgear/math/sg_types.hxx +++ b/simgear/math/sg_types.hxx @@ -38,28 +38,18 @@ #include #include -class Point3D; - -using std::vector; -using std::string; - /** 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::const_iterator const_int_list_iterator; /** 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::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 */ -typedef vector < string > string_list; +typedef std::vector < std::string > string_list; typedef string_list::iterator string_list_iterator; typedef string_list::const_iterator const_string_list_iterator; diff --git a/simgear/math/vector.cxx b/simgear/math/vector.cxx deleted file mode 100644 index a5d3ee0a..00000000 --- a/simgear/math/vector.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// vector.cxx -- additional vector routines -// -// Written by Curtis Olson, started December 1997. -// -// Copyright (C) 1997 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 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$ - - -#include -#include - -// #include - -#include "vector.hxx" - - -// calculate the projection, p, of u along the direction of d. -void sgProjection(sgVec3 p, const sgVec3 u, const sgVec3 d){ - double denom = sgScalarProductVec3(d,d); - if (denom == 0.) sgCopyVec3(p, u); - else sgScaleVec3(p, d, sgScalarProductVec3(u,d) / denom); -} - -// Same thing, except using double precision -void sgProjection(sgdVec3 p, const sgdVec3 u, const sgdVec3 d){ - double denom = sgdScalarProductVec3(d,d); - if (denom == 0.) sgdCopyVec3(p, u); - else sgdScaleVec3(p, d, sgdScalarProductVec3(u,d) / denom); -} - -// Given a point p, and a line through p0 with direction vector d, -// find the closest point (p1) on the line -void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0, - const sgVec3 d ) { - - sgVec3 u, u1; - - // u = p - p0 - sgSubVec3(u, p, p0); - - // calculate the projection, u1, of u along d. - sgProjection(u1, u, d); - - // calculate the point p1 along the line that is closest to p - // p0 = p1 + u1 - sgAddVec3(p1, p0, u1); -} - - -// Given a point p, and a line through p0 with direction vector d, -// find the closest point (p1) on the line -void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0, - const sgdVec3 d ) { - - sgdVec3 u, u1; - - // u = p - p0 - sgdSubVec3(u, p, p0); - - // calculate the projection, u1, of u along d. - sgProjection(u1, u, d); - - // calculate the point p1 along the line that is closest to p - // p0 = p1 + u1 - sgdAddVec3(p1, p0, u1); -} - - -// Given a point p, and a line through p0 with direction vector d, -// find the shortest distance (squared) from the point to the line -double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0, - const sgVec3 d ) { - - sgVec3 u, u1, v; - - // u = p - p0 - sgSubVec3(u, p, p0); - - // calculate the projection, u1, of u along d. - sgProjection(u1, u, d); - - // v = u - u1 = vector from closest point on line, p1, to the - // original point, p. - sgSubVec3(v, u, u1); - - return ( sgScalarProductVec3(v, v) ); -} - - -// Given a point p, and a line through p0 with direction vector d, -// find the shortest distance (squared) from the point to the line -double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0, - const sgdVec3 d ) { - - sgdVec3 u, u1, v; - - // u = p - p0 - sgdSubVec3(u, p, p0); - - // calculate the projection, u1, of u along d. - sgProjection(u1, u, d); - - // v = u - u1 = vector from closest point on line, p1, to the - // original point, p. - sgdSubVec3(v, u, u1); - - return ( sgdScalarProductVec3(v, v) ); -} - - -// This is a quicker form of -// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans ) -// sgPostMultMat4( sgMat, sgTRANS ); -void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans ) -{ - for( int i=0; i<4; i++) { - for( int j=0; j<3; j++ ) { - src[i][j] += (src[i][3] * trans[j]); - } - } -} - - diff --git a/simgear/math/vector.hxx b/simgear/math/vector.hxx deleted file mode 100644 index b4cbb2f3..00000000 --- a/simgear/math/vector.hxx +++ /dev/null @@ -1,175 +0,0 @@ -/** - * \file vector.hxx - * Additional vector routines. - */ - -// Written by Curtis Olson, started December 1997. -// -// Copyright (C) 1997 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 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$ - - -#ifndef _VECTOR_HXX -#define _VECTOR_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include - -#include - - -/** - * calculate the projection, p, of u along the direction of d. - * @param p (out) the projection - * @param u (in) the vector to be projected - * @param d (in) the direction onto which we project - */ -void sgProjection(sgVec3 p, const sgVec3 u, const sgVec3 d); -void sgProjection(sgdVec3 p, const sgdVec3 u, const sgdVec3 d); - - -/** - * Map i.e. project a vector onto a plane. - * @param normal (in) normal vector for the plane - * @param v0 (in) a point on the plane - * @param vec (in) the vector to map onto the plane - * @param result (out) the result vector - */ -inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal, - sgVec3 v0, - sgVec3 vec, - sgVec3 result ) -{ - sgVec3 u1, v, tmp; - - // calculate a vector "u1" representing the shortest distance from - // the plane specified by normal and v0 to a point specified by - // "vec". "u1" represents both the direction and magnitude of - // this desired distance. - - // u1 = ( (normal vec) / (normal normal) ) * normal - - sgScaleVec3( u1, - normal, - ( sgScalarProductVec3(normal, vec) / - sgScalarProductVec3(normal, normal) - ) - ); - - // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]); - // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]); - // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]); - - // calculate the vector "v" which is the vector "vec" mapped onto - // the plane specified by "normal" and "v0". - - // v = v0 + vec - u1 - - sgAddVec3(tmp, v0, vec); - sgSubVec3(v, tmp, u1); - // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]); - - // Calculate the vector "result" which is "v" - "v0" which is a - // directional vector pointing from v0 towards v - - // result = v - v0 - - sgSubVec3(result, v, v0); - // printf(" result = %.2f, %.2f, %.2f\n", - // result[0], result[1], result[2]); -} - - -/** - * Copy and negate a vector. - * @param dst (out) result vector - * @param src (in) input vector - */ -inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src ) -{ - dst [ 0 ] = -src [ 0 ] ; - dst [ 1 ] = -src [ 1 ] ; - dst [ 2 ] = -src [ 2 ] ; - dst [ 3 ] = -src [ 3 ] ; -} - -/** - * Given a point p, and a line through p0 with direction vector d, - * find the closest point (p1) on the line (float version). - * @param p1 (out) closest point to p on the line - * @param p (in) original point - * @param p0 (in) point on the line - * @param d (in) vector defining line direction - */ -void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0, - const sgVec3 d ); - -/** - * Given a point p, and a line through p0 with direction vector d, - * find the closest point (p1) on the line (double version). - * @param p1 (out) closest point to p on the line - * @param p (in) original point - * @param p0 (in) point on the line - * @param d (in) vector defining line direction - */ -void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0, - const sgdVec3 d ); - -/** - * Given a point p, and a line through p0 with direction vector d, - * find the shortest distance (squared) from the point to the line (float - * version.) - * @param p (in) original point - * @param p0 (in) point on the line - * @param d (in) vector defining line direction - * @return shortest distance (squared) from p to line - */ -double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0, - const sgVec3 d ); - -/** - * Given a point p, and a line through p0 with direction vector d, - * find the shortest distance (squared) from the point to the line (double - * version.) - * @param p (in) original point - * @param p0 (in) point on the line - * @param d (in) vector defining line direction - * @return shortest distance (squared) from p to line - */ -double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0, - const sgdVec3 d ); - -/** - * This is same as: - * - *
  • sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans ) - *
  • sgPostMultMat4( sgMat4 src, sgTRANS ); - * - * @param src starting sgMat4 matrix - * @param trans translation vector - */ -void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans ); - - -#endif // _VECTOR_HXX - - diff --git a/simgear/misc/texcoord.cxx b/simgear/misc/texcoord.cxx index 30af6eff..4a19fb44 100644 --- a/simgear/misc/texcoord.cxx +++ b/simgear/misc/texcoord.cxx @@ -149,7 +149,6 @@ enter this in the official comments in case I forget again. :-) #include "texcoord.hxx" -#include // using std::cout; // using std::endl; @@ -160,28 +159,28 @@ enter this in the official comments in case I forget again. :-) // return the basic unshifted/unmoded texture coordinate for a lat/lon -static inline Point3D basic_tex_coord( const Point3D& p, +static inline SGVec2f basic_tex_coord( const SGGeod& p, double degree_width, double degree_height, double scale ) { - return Point3D( p.x() * ( degree_width * scale / + return SGVec2f( p.getLongitudeDeg() * ( degree_width * scale / FG_STANDARD_TEXTURE_DIMENSION ), - p.y() * ( degree_height * scale / - FG_STANDARD_TEXTURE_DIMENSION ), - 0.0 ); + p.getLatitudeDeg() * ( degree_height * scale / + FG_STANDARD_TEXTURE_DIMENSION ) + ); } // traverse the specified fan/strip/list of vertices and attempt to // calculate "none stretching" texture coordinates -point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, +std::vector sgCalcTexCoords( const SGBucket& b, const std::vector& geod_nodes, const int_list& fan, double scale ) { return sgCalcTexCoords(b.get_center_lat(), geod_nodes, fan, scale); } -point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, +std::vector sgCalcTexCoords( double centerLat, const std::vector& geod_nodes, const int_list& fan, double scale ) { // cout << "calculating texture coordinates for a specific fan of size = " @@ -214,16 +213,16 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, // cout << "degree_height = " << degree_height << endl; // find min/max of fan - Point3D tmin, tmax, p, t; + SGVec2f tmin, tmax; bool first = true; int i; for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; + SGGeod p = geod_nodes[ fan[i] ]; // cout << "point p = " << p << endl; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "basic_tex_coord = " << t << endl; if ( first ) { @@ -231,16 +230,16 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, first = false; } else { if ( t.x() < tmin.x() ) { - tmin.setx( t.x() ); + tmin.x() = t.x(); } if ( t.y() < tmin.y() ) { - tmin.sety( t.y() ); + tmin.y() = t.y(); } if ( t.x() > tmax.x() ) { - tmax.setx( t.x() ); + tmax.x() = t.x(); } if ( t.y() > tmax.y() ) { - tmax.sety( t.y() ); + tmax.y() = t.y(); } } } @@ -256,30 +255,31 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, // but is the best we can do. // cout << "SHIFTING" << endl; if ( tmin.x() < 0 ) { - tmin.setx( (double)( (int)tmin.x() - 1 ) ); + tmin.x() = (double)( (int)tmin.x() - 1 ) ; } else { - tmin.setx( (int)tmin.x() ); + tmin.x() = (int)tmin.x(); } + if ( tmin.y() < 0 ) { - tmin.sety( (double)( (int)tmin.y() - 1 ) ); + tmin.y() = (double)( (int)tmin.y() - 1 ); } else { - tmin.sety( (int)tmin.y() ); + tmin.y() = (int)tmin.y(); } // cout << "found tmin = " << tmin << endl; } else { if ( tmin.x() < 0 ) { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } if ( tmin.y() < 0 ) { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } #if 0 // structure is small enough ... we can mod it so we can @@ -319,12 +319,12 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, } // generate tex_list - Point3D adjusted_t; - point_list tex; + SGVec2f adjusted_t; + std::vector tex; tex.clear(); for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGGeod p = geod_nodes[ fan[i] ]; + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "second t = " << t << endl; adjusted_t = t - tmin; @@ -342,12 +342,12 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, } #endif if ( adjusted_t.x() < SG_EPSILON ) { - adjusted_t.setx( 0.0 ); + adjusted_t.x() = 0.0; } if ( adjusted_t.y() < SG_EPSILON ) { - adjusted_t.sety( 0.0 ); + adjusted_t.y() = 0.0; } - adjusted_t.setz( 0.0 ); + // cout << "adjusted_t = " << adjusted_t << endl; tex.push_back( adjusted_t ); diff --git a/simgear/misc/texcoord.hxx b/simgear/misc/texcoord.hxx index a5d49bd4..20537922 100644 --- a/simgear/misc/texcoord.hxx +++ b/simgear/misc/texcoord.hxx @@ -36,6 +36,9 @@ #include #include +#include +#include +#include /** * Traverse the specified fan/strip/list of vertices and attempt to @@ -46,10 +49,10 @@ * @param scale (default = 1.0) scaling factor * @return list of texture coordinates */ -point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, +std::vector sgCalcTexCoords( const SGBucket& b, const std::vector& geod_nodes, const int_list& fan, double scale = 1.0 ); -point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, +std::vector sgCalcTexCoords( double centerLat, const std::vector& geod_nodes, const int_list& fan, double scale = 1.0 ); diff --git a/simgear/route/route.cxx b/simgear/route/route.cxx index 7a1a6c08..a02428e1 100644 --- a/simgear/route/route.cxx +++ b/simgear/route/route.cxx @@ -26,8 +26,6 @@ #include -#include - #include "route.hxx" diff --git a/simgear/route/waypoint.cxx b/simgear/route/waypoint.cxx index f9a9ab0b..73669037 100644 --- a/simgear/route/waypoint.cxx +++ b/simgear/route/waypoint.cxx @@ -24,7 +24,6 @@ # include #endif -#include #include #include "waypoint.hxx" diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 83b1a9fa..cc2d178a 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -119,7 +119,7 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, const SGPropertyNode *props) { // Gather the path(s) to the texture(s) - vector textures = props->getChildren("texture"); + std::vector textures = props->getChildren("texture"); for (unsigned int i = 0; i < textures.size(); i++) { string tname = textures[i]->getStringValue(); @@ -141,11 +141,11 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, } } - vector texturesets = props->getChildren("texture-set"); + std::vector texturesets = props->getChildren("texture-set"); for (unsigned int i = 0; i < texturesets.size(); i++) { _internal_state st( NULL, false, options ); - vector textures = texturesets[i]->getChildren("texture"); + std::vector textures = texturesets[i]->getChildren("texture"); for (unsigned int j = 0; j < textures.size(); j++) { string tname = textures[j]->getStringValue(); @@ -229,13 +229,13 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, if (props->hasChild("effect")) effect = props->getStringValue("effect"); - vector object_group_nodes = + std::vector object_group_nodes = ((SGPropertyNode *)props)->getChildren("object-group"); for (unsigned int i = 0; i < object_group_nodes.size(); i++) object_groups.push_back(new SGMatModelGroup(object_group_nodes[i])); // read glyph table for taxi-/runway-signs - vector glyph_nodes = props->getChildren("glyph"); + std::vector glyph_nodes = props->getChildren("glyph"); for (unsigned int i = 0; i < glyph_nodes.size(); i++) { const char *name = glyph_nodes[i]->getStringValue("name"); if (name) diff --git a/simgear/scene/material/matmodel.cxx b/simgear/scene/material/matmodel.cxx index 93cbd494..0ac77543 100644 --- a/simgear/scene/material/matmodel.cxx +++ b/simgear/scene/material/matmodel.cxx @@ -65,7 +65,7 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m) } // Note all the model paths - vector path_nodes = node->getChildren("path"); + std::vector path_nodes = node->getChildren("path"); for (unsigned int i = 0; i < path_nodes.size(); i++) _paths.push_back(path_nodes[i]->getStringValue()); @@ -182,7 +182,7 @@ SGMatModelGroup::SGMatModelGroup (SGPropertyNode * node) : _range_m(node->getDoubleValue("range-m", 2000)) { // Load the object subnodes - vector object_nodes = + std::vector object_nodes = ((SGPropertyNode *)node)->getChildren("object"); for (unsigned int i = 0; i < object_nodes.size(); i++) { const SGPropertyNode * object_node = object_nodes[i]; diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index e534a37a..72462cc7 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -54,7 +54,6 @@ #include #include #include -#include #include "newcloud.hxx" #include "cloudfield.hxx" @@ -144,9 +143,7 @@ SGCloudLayer::SGCloudLayer( const string &tex_path ) : layer_coverage(SG_CLOUD_CLEAR), scale(4000.0), speed(0.0), - direction(0.0), - last_lon(0.0), - last_lat(0.0) + direction(0.0) { // XXX // Render bottoms before the rest of transparent objects (rendered @@ -498,7 +495,6 @@ SGCloudLayer::rebuild() } scale = 4000.0; - last_lon = last_lat = -999.0f; setTextureOffset(base); // build the cloud layer @@ -675,20 +671,17 @@ bool SGCloudLayer::reposition( const SGVec3f& p, const SGVec3f& up, double lon, // now calculate update texture coordinates - if ( last_lon < -900 ) { - last_lon = lon; - last_lat = lat; + SGGeod pos = SGGeod::fromRad(lon, lat); + if ( last_pos == SGGeod() ) { + last_pos = pos; } double sp_dist = speed*dt; - - if ( lon != last_lon || lat != last_lat || sp_dist != 0 ) { - Point3D start( last_lon, last_lat, 0.0 ); - Point3D dest( lon, lat, 0.0 ); - double course = 0.0, dist = 0.0; - - calc_gc_course_dist( dest, start, &course, &dist ); - // cout << "course = " << course << ", dist = " << dist << endl; + + + if ( lon != last_pos.getLongitudeRad() || lat != last_pos.getLatitudeRad() || sp_dist != 0 ) { + double course = SGGeodesy::courseDeg(last_pos, pos) * SG_DEGREES_TO_RADIANS, + dist = SGGeodesy::distanceM(last_pos, pos); // if start and dest are too close together, // calc_gc_course_dist() can return a course of "nan". If @@ -753,8 +746,7 @@ bool SGCloudLayer::reposition( const SGVec3f& p, const SGVec3f& up, double lon, // cout << "base = " << base[0] << "," << base[1] << endl; setTextureOffset(base); - last_lon = lon; - last_lat = lat; + last_pos = pos; } layer3D->reposition( p, up, lon, lat, dt, layer_asl); diff --git a/simgear/scene/sky/cloud.hxx b/simgear/scene/sky/cloud.hxx index 4b282a61..91a977b0 100644 --- a/simgear/scene/sky/cloud.hxx +++ b/simgear/scene/sky/cloud.hxx @@ -225,7 +225,8 @@ private: // from winds, and to simulate the clouds being tied to ground // position, not view position // double xoff, yoff; - double last_lon, last_lat, last_course; + SGGeod last_pos; + double last_course; osg::Vec2 base; diff --git a/simgear/scene/sky/cloudfield.cxx b/simgear/scene/sky/cloudfield.cxx index b99a2d16..dde4c653 100644 --- a/simgear/scene/sky/cloudfield.cxx +++ b/simgear/scene/sky/cloudfield.cxx @@ -34,7 +34,6 @@ #include #include #include -#include #include #include diff --git a/simgear/scene/sky/cloudfield.hxx b/simgear/scene/sky/cloudfield.hxx index 1b2f97f1..0d8fba52 100644 --- a/simgear/scene/sky/cloudfield.hxx +++ b/simgear/scene/sky/cloudfield.hxx @@ -44,6 +44,7 @@ namespace osg #include #include +#include using std::vector; diff --git a/simgear/scene/tgdb/SGOceanTile.cxx b/simgear/scene/tgdb/SGOceanTile.cxx index 337a3103..7e7b590c 100644 --- a/simgear/scene/tgdb/SGOceanTile.cxx +++ b/simgear/scene/tgdb/SGOceanTile.cxx @@ -81,7 +81,7 @@ public: SGVec3f normals[latPoints][lonPoints]; SGVec3d rel[latPoints][lonPoints]; - point_list geod_nodes; + std::vector geod_nodes; osg::Vec3Array* vl; osg::Vec3Array* nl; @@ -122,27 +122,31 @@ void OceanMesh::calcMesh(const SGVec3d& cartCenter, const SGQuatd& orient, } // Calculate texture coordinates - point_list geod_nodes(latPoints * lonPoints); - VectorArrayAdapter geodNodesArray(geod_nodes, lonPoints); + typedef std::vector GeodVector; + + GeodVector geod_nodes(latPoints * lonPoints); + VectorArrayAdapter geodNodesArray(geod_nodes, lonPoints); int_list rectangle(latPoints * lonPoints); VectorArrayAdapter rectArray(rectangle, lonPoints); for (int j = 0; j < latPoints; j++) { for (int i = 0; i < lonPoints; i++) { - geodNodesArray(j, i) = Point3D(geod[j][i].getLongitudeDeg(), - geod[j][i].getLatitudeDeg(), - geod[j][i].getElevationM()); + geodNodesArray(j, i) = geod[j][i]; rectArray(j, i) = j * 5 + i; } } - point_list texs = sgCalcTexCoords( clat, geod_nodes, rectangle, + + typedef std::vector Vec2Array; + Vec2Array texs = sgCalcTexCoords( clat, geod_nodes, rectangle, 1000.0 / tex_width ); - VectorArrayAdapter texsArray(texs, lonPoints); + + + VectorArrayAdapter texsArray(texs, lonPoints); for (int j = 0; j < latPoints; j++) { for (int i = 0; i < lonPoints; ++i) { vlArray(j, i) = toOsg(rel[j][i]); nlArray(j, i) = toOsg(normals[j][i]); - tlArray(j, i) = toOsg(texsArray(j, i).toSGVec2f()); + tlArray(j, i) = toOsg(texsArray(j, i)); } } diff --git a/simgear/scene/tgdb/TileCache.hxx b/simgear/scene/tgdb/TileCache.hxx index f141507d..adcaacf7 100644 --- a/simgear/scene/tgdb/TileCache.hxx +++ b/simgear/scene/tgdb/TileCache.hxx @@ -27,7 +27,6 @@ #include #include -#include #include using std::map; diff --git a/simgear/scene/tgdb/TileEntry.hxx b/simgear/scene/tgdb/TileEntry.hxx index 5fc69827..1c620a41 100644 --- a/simgear/scene/tgdb/TileEntry.hxx +++ b/simgear/scene/tgdb/TileEntry.hxx @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -47,9 +46,6 @@ #include #endif -using std::string; -using std::vector; - namespace simgear { class ModelLoadHelper; @@ -64,10 +60,6 @@ public: SGBucket tile_bucket; std::string tileFileName; - typedef vector < Point3D > point_list; - typedef point_list::iterator point_list_iterator; - typedef point_list::const_iterator const_point_list_iterator; - private: // pointer to ssg range selector for this tile diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index fd6d42e2..4481b830 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -563,7 +563,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool if (!tile.read_bin(path)) return false; - SGVec3d center = tile.get_gbs_center2(); + SGVec3d center = tile.get_gbs_center(); SGGeod geodPos = SGGeod::fromCart(center); SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180); diff --git a/simgear/scene/tgdb/userdata.cxx b/simgear/scene/tgdb/userdata.cxx index 6aa71821..bf5823c9 100644 --- a/simgear/scene/tgdb/userdata.cxx +++ b/simgear/scene/tgdb/userdata.cxx @@ -28,7 +28,6 @@ #include #include -#include #include #include #include