X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fsg_binobj.hxx;h=d594113de0ef3b9e8f3b622df2e2441520f0d66e;hb=adb7db9229db1d869b254ac18f1471bed464c508;hp=ae3ccad504300fd44b4f56edf3fbadc93aa25449;hpb=b2a4cd488dfcfbf1d02fa41f2dfa5ad39aabb13a;p=simgear.git diff --git a/simgear/io/sg_binobj.hxx b/simgear/io/sg_binobj.hxx index ae3ccad5..d594113d 100644 --- a/simgear/io/sg_binobj.hxx +++ b/simgear/io/sg_binobj.hxx @@ -19,7 +19,7 @@ // // 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$ @@ -27,31 +27,24 @@ #ifndef _SG_BINOBJ_HXX #define _SG_BINOBJ_HXX - -#include +#include // for gzFile #include #include #include -#include - -#include -#include - -#include -#include STL_STRING - +#include +#include +#include /** 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; - -/** Magic Number for our file format */ -#define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION ) - +// forward decls +class SGBucket; +class SGPath; /** * A class to manipulate the simgear 3d object format. @@ -74,9 +67,9 @@ typedef group_list::const_iterator const_group_list_iterator; * * - 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 * @@ -87,15 +80,16 @@ typedef group_list::const_iterator const_group_list_iterator; * - vertex: FLOAT, FLOAT, FLOAT */ class SGBinObject { +private: unsigned short version; - Point3D gbs_center; + SGVec3d gbs_center; float gbs_radius; - point_list wgs84_nodes; // vertex list - point_list colors; // color list - point_list normals; // normal list - point_list texcoords; // texture coordinate list + std::vector wgs84_nodes; // vertex list + std::vector colors; // color list + std::vector normals; // normal list + std::vector texcoords; // texture coordinate list group_list pts_v; // points vertex index group_list pts_n; // points normal index @@ -121,28 +115,48 @@ class SGBinObject { group_list fans_tc; // fans texture coordinate index string_list fan_materials; // fans materials + void read_properties(gzFile fp, int nproperties); + + void read_object( gzFile fp, + int obj_type, + int nproperties, + int nelements, + group_list& vertices, + group_list& normals, + group_list& colors, + group_list& texCoords, + string_list& materials); + + void write_header(gzFile fp, int type, int nProps, int nElements); + void write_objects(gzFile fp, int type, const group_list& verts, + const group_list& normals, const group_list& colors, + const group_list& texCoords, const string_list& materials); + + unsigned int count_objects(const string_list& materials); public: inline unsigned short get_version() const { return version; } - inline const Point3D& get_gbs_center() const { return gbs_center; } - inline void set_gbs_center( const Point3D& p ) { gbs_center = p; } + 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; } inline void set_gbs_radius( float r ) { gbs_radius = r; } - inline const point_list& get_wgs84_nodes() const { return wgs84_nodes; } - inline void set_wgs84_nodes( const point_list& n ) { wgs84_nodes = n; } - - inline const point_list& get_colors() const { return colors; } - inline void set_colors( const point_list& c ) { colors = c; } - - inline const point_list& get_normals() const { return normals; } - inline void set_normals( const point_list& n ) { normals = n; } - - inline const point_list& get_texcoords() const { return texcoords; } - inline void set_texcoords( const point_list& t ) { texcoords = t; } + inline const std::vector& get_wgs84_nodes() const + { return wgs84_nodes; } + inline void set_wgs84_nodes( const std::vector& n ) + { wgs84_nodes = n; } + inline const std::vector& get_colors() const { return colors; } + inline void set_colors( const std::vector& c ) { colors = c; } + + inline const std::vector& get_normals() const { return normals; } + inline void set_normals( const std::vector& n ) { normals = n; } + + inline const std::vector& get_texcoords() const { return texcoords; } + inline void set_texcoords( const std::vector& t ) { texcoords = t; } + 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; } @@ -194,7 +208,7 @@ public: * @param file input file name * @return result of read */ - bool read_bin( const string& file ); + bool read_bin( const std::string& file ); /** * Write out the structures to a binary file. We assume that the @@ -205,7 +219,10 @@ public: * @param b bucket for object location * @return result of write */ - bool write_bin( const string& base, const string& name, const SGBucket& b ); + bool write_bin( const std::string& base, const std::string& name, const SGBucket& b ); + + + bool write_bin_file(const SGPath& file); /** * Write out the structures to an ASCII file. We assume that the @@ -216,30 +233,8 @@ public: * @param b bucket for object location * @return result of write */ - bool write_ascii( const string& base, const string& name, + bool write_ascii( const std::string& base, const std::string& name, 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