// Written by Curtis Olson, started January 2000.
//
-// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
+// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
//
// 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
//
// 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$
*
* - 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
*
class SGBinObject {
unsigned short version;
- Point3D gbs_center;
+ SGVec3d gbs_center;
float gbs_radius;
- point_list wgs84_nodes;
- point_list normals;
- point_list texcoords;
- group_list pts_v;
- string_list pt_materials;
- group_list tris_v;
- group_list tris_tc;
- string_list tri_materials;
- group_list strips_v;
- group_list strips_tc;
- string_list strip_materials;
- group_list fans_v;
- group_list fans_tc;
- string_list fan_materials;
+
+ std::vector<SGVec3d> wgs84_nodes; // vertex list
+ std::vector<SGVec4f> colors; // color list
+ std::vector<SGVec3f> normals; // normal list
+ std::vector<SGVec2f> texcoords; // texture coordinate list
+
+ group_list pts_v; // points vertex index
+ group_list pts_n; // points normal index
+ group_list pts_c; // points color index
+ group_list pts_tc; // points texture coordinate index
+ string_list pt_materials; // points materials
+
+ group_list tris_v; // triangles vertex index
+ group_list tris_n; // triangles normal index
+ group_list tris_c; // triangles color index
+ group_list tris_tc; // triangles texture coordinate index
+ string_list tri_materials; // triangles materials
+
+ group_list strips_v; // tristrips vertex index
+ group_list strips_n; // tristrips normal index
+ group_list strips_c; // tristrips color index
+ group_list strips_tc; // tristrips texture coordinate index
+ string_list strip_materials;// tristrips materials
+
+ group_list fans_v; // fans vertex index
+ group_list fans_n; // fans normal index
+ group_list fans_c; // fans color index
+ group_list fans_tc; // fans texture coordinate index
+ string_list fan_materials; // fans materials
public:
inline unsigned short get_version() const { return version; }
- inline Point3D get_gbs_center() const { return gbs_center; }
- inline void set_gbs_center( Point3D p ) { gbs_center = p; }
+ 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 void set_gbs_center( const SGVec3d& p ) { gbs_center = p; }
inline float get_gbs_radius() const { return gbs_radius; }
inline void set_gbs_radius( float r ) { gbs_radius = r; }
- inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
- inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
-
- inline point_list get_normals() const { return normals; }
- inline void set_normals( point_list n ) { normals = n; }
-
- inline point_list get_texcoords() const { return texcoords; }
- inline void set_texcoords( point_list t ) { texcoords = t; }
-
- inline group_list get_pts_v() const { return pts_v; }
- inline void set_pts_v( group_list g ) { pts_v = g; }
- inline string_list get_pt_materials() const { return pt_materials; }
- inline void set_pt_materials( string_list s ) { pt_materials = s; }
-
- inline group_list get_tris_v() const { return tris_v; }
- inline void set_tris_v( group_list g ) { tris_v = g; }
- inline group_list get_tris_tc() const { return tris_tc; }
- inline void set_tris_tc( group_list g ) { tris_tc = g; }
- inline string_list get_tri_materials() const { return tri_materials; }
- inline void set_tri_materials( string_list s ) { tri_materials = s; }
+ inline const std::vector<SGVec3d>& get_wgs84_nodes() const
+ { 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; }
+ inline void set_pts_n( const group_list& g ) { pts_n = g; }
+ inline const group_list& get_pts_c() const { return pts_c; }
+ inline void set_pts_c( const group_list& g ) { pts_c = g; }
+ inline const group_list& get_pts_tc() const { return pts_tc; }
+ inline void set_pts_tc( const group_list& g ) { pts_tc = g; }
+ inline const string_list& get_pt_materials() const { return pt_materials; }
+ inline void set_pt_materials( const string_list& s ) { pt_materials = s; }
+
+ inline const group_list& get_tris_v() const { return tris_v; }
+ inline void set_tris_v( const group_list& g ) { tris_v = g; }
+ inline const group_list& get_tris_n() const { return tris_n; }
+ inline void set_tris_n( const group_list& g ) { tris_n = g; }
+ inline const group_list& get_tris_c() const { return tris_c; }
+ inline void set_tris_c( const group_list& g ) { tris_c = g; }
+ inline const group_list& get_tris_tc() const { return tris_tc; }
+ inline void set_tris_tc( const group_list& g ) { tris_tc = g; }
+ inline const string_list& get_tri_materials() const { return tri_materials; }
+ inline void set_tri_materials( const string_list& s ) { tri_materials = s; }
- inline group_list get_strips_v() const { return strips_v; }
- inline void set_strips_v( group_list g ) { strips_v = g; }
- inline group_list get_strips_tc() const { return strips_tc; }
- inline void set_strips_tc( group_list g ) { strips_tc = g; }
- inline string_list get_strip_materials() const { return strip_materials; }
- inline void set_strip_materials( string_list s ) { strip_materials = s; }
+ inline const group_list& get_strips_v() const { return strips_v; }
+ inline void set_strips_v( const group_list& g ) { strips_v = g; }
+ inline const group_list& get_strips_n() const { return strips_n; }
+ inline void set_strips_n( const group_list& g ) { strips_n = g; }
+ inline const group_list& get_strips_c() const { return strips_c; }
+ inline void set_strips_c( const group_list& g ) { strips_c = g; }
+
+ inline const group_list& get_strips_tc() const { return strips_tc; }
+ inline void set_strips_tc( const group_list& g ) { strips_tc = g; }
+ inline const string_list& get_strip_materials() const { return strip_materials; }
+ inline void set_strip_materials( const string_list& s ) { strip_materials = s; }
- inline group_list get_fans_v() const { return fans_v; }
- inline void set_fans_v( group_list g ) { fans_v = g; }
- inline group_list get_fans_tc() const { return fans_tc; }
- inline void set_fans_tc( group_list g ) { fans_tc = g; }
- inline string_list get_fan_materials() const { return fan_materials; }
- inline void set_fan_materials( string_list s ) { fan_materials = s; }
+ inline const group_list& get_fans_v() const { return fans_v; }
+ inline void set_fans_v( const group_list& g ) { fans_v = g; }
+ inline const group_list& get_fans_n() const { return fans_n; }
+ inline void set_fans_n( const group_list& g ) { fans_n = g; }
+ inline const group_list& get_fans_c() const { return fans_c; }
+ inline void set_fans_c( const group_list& g ) { fans_c = g; }
+
+ inline const group_list& get_fans_tc() const { return fans_tc; }
+ inline void set_fans_tc( const group_list& g ) { fans_tc = g; }
+ inline const string_list& get_fan_materials() const { return fan_materials; }
+ inline void set_fan_materials( const string_list& s ) { fan_materials = s; }
/**
* Read a binary file object and populate the provided structures.
};
+/**
+ * \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.