#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/math/SGGeometry.hxx>
#include "lowlevel.hxx"
#include "sg_binobj.hxx"
}
};
-
-// 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,
}
// 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());
}
// 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");
/** 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;
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; }
{ return wgs84_nodes; }
inline void set_wgs84_nodes( const std::vector<SGVec3d>& 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<SGVec4f>& get_colors() const { return colors; }
inline void set_colors( const std::vector<SGVec4f>& 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<SGVec3f>& get_normals() const { return normals; }
inline void set_normals( const std::vector<SGVec3f>& 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<SGVec2f>& get_texcoords() const { return texcoords; }
inline void set_texcoords( const std::vector<SGVec2f>& 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; }
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
#include <string>
#include <vector>
-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;
// 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<SGVec2f> sgCalcTexCoords( const SGBucket& b, const std::vector<SGGeod>& 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<SGVec2f> sgCalcTexCoords( double centerLat, const std::vector<SGGeod>& geod_nodes,
const int_list& fan, double scale )
{
// cout << "calculating texture coordinates for a specific fan of size = "
// 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 ) {
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();
}
}
}
// 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
}
// generate tex_list
- Point3D adjusted_t;
- point_list tex;
+ SGVec2f adjusted_t;
+ std::vector<SGVec2f> 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;
}
#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 );
#include <simgear/bucket/newbucket.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
* @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<SGVec2f> sgCalcTexCoords( const SGBucket& b, const std::vector<SGGeod>& geod_nodes,
const int_list& fan, double scale = 1.0 );
-point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes,
+std::vector<SGVec2f> sgCalcTexCoords( double centerLat, const std::vector<SGGeod>& geod_nodes,
const int_list& fan, double scale = 1.0 );
const SGPropertyNode *props)
{
// Gather the path(s) to the texture(s)
- vector<SGPropertyNode_ptr> textures = props->getChildren("texture");
+ std::vector<SGPropertyNode_ptr> textures = props->getChildren("texture");
for (unsigned int i = 0; i < textures.size(); i++)
{
string tname = textures[i]->getStringValue();
}
}
- vector<SGPropertyNode_ptr> texturesets = props->getChildren("texture-set");
+ std::vector<SGPropertyNode_ptr> texturesets = props->getChildren("texture-set");
for (unsigned int i = 0; i < texturesets.size(); i++)
{
_internal_state st( NULL, false, options );
- vector<SGPropertyNode_ptr> textures = texturesets[i]->getChildren("texture");
+ std::vector<SGPropertyNode_ptr> textures = texturesets[i]->getChildren("texture");
for (unsigned int j = 0; j < textures.size(); j++)
{
string tname = textures[j]->getStringValue();
if (props->hasChild("effect"))
effect = props->getStringValue("effect");
- vector<SGPropertyNode_ptr> object_group_nodes =
+ std::vector<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> glyph_nodes = props->getChildren("glyph");
+ std::vector<SGPropertyNode_ptr> 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)
}
// Note all the model paths
- vector <SGPropertyNode_ptr> path_nodes = node->getChildren("path");
+ std::vector <SGPropertyNode_ptr> path_nodes = node->getChildren("path");
for (unsigned int i = 0; i < path_nodes.size(); i++)
_paths.push_back(path_nodes[i]->getStringValue());
: _range_m(node->getDoubleValue("range-m", 2000))
{
// Load the object subnodes
- vector<SGPropertyNode_ptr> object_nodes =
+ std::vector<SGPropertyNode_ptr> object_nodes =
((SGPropertyNode *)node)->getChildren("object");
for (unsigned int i = 0; i < object_nodes.size(); i++) {
const SGPropertyNode * object_node = object_nodes[i];
SGVec3f normals[latPoints][lonPoints];
SGVec3d rel[latPoints][lonPoints];
- point_list geod_nodes;
+ std::vector<SGGeod> geod_nodes;
osg::Vec3Array* vl;
osg::Vec3Array* nl;
}
// Calculate texture coordinates
- point_list geod_nodes(latPoints * lonPoints);
- VectorArrayAdapter<point_list> geodNodesArray(geod_nodes, lonPoints);
+ typedef std::vector<SGGeod> GeodVector;
+
+ GeodVector geod_nodes(latPoints * lonPoints);
+ VectorArrayAdapter<GeodVector> geodNodesArray(geod_nodes, lonPoints);
int_list rectangle(latPoints * lonPoints);
VectorArrayAdapter<int_list> 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<SGVec2f> Vec2Array;
+ Vec2Array texs = sgCalcTexCoords( clat, geod_nodes, rectangle,
1000.0 / tex_width );
- VectorArrayAdapter<point_list> texsArray(texs, lonPoints);
+
+
+ VectorArrayAdapter<Vec2Array> 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));
}
}
#include <strings.h>
#endif
-using std::string;
-using std::vector;
-
namespace simgear {
class ModelLoadHelper;
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
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);