From: curt Date: Sat, 6 Jan 2001 04:31:11 +0000 (+0000) Subject: made read/write functions into members of SGBinObject. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2efac3d949e9f34d503d6b04fde740f99d7246e0;p=simgear.git made read/write functions into members of SGBinObject. --- diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 1cb467a0..98e8da55 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -108,27 +108,15 @@ double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ) { // read a binary file and populate the provided structures. -bool sgReadBinObj( const string& file, SGBinObject* obj ) { +bool SGBinObject::read_bin( const string& file ) { Point3D p; int i, j, k; char material[256]; - Point3D gbs_center = Point3D( 0 ); - float gbs_radius = 0.0; - point_list wgs84_nodes; - point_list normals; - point_list texcoords; - 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; - // zero out structures + gbs_center = Point3D( 0 ); + gbs_radius = 0.0; + wgs84_nodes.clear(); normals.clear(); texcoords.clear(); @@ -481,21 +469,6 @@ bool sgReadBinObj( const string& file, SGBinObject* obj ) { // close the file gzclose(fp); - obj->set_gbs_center( gbs_center ); - obj->set_gbs_radius( gbs_radius ); - obj->set_wgs84_nodes( wgs84_nodes ); - obj->set_normals( normals ); - obj->set_texcoords( texcoords ); - obj->set_tris_v( tris_v ); - obj->set_tris_tc( tris_tc ); - obj->set_tri_materials( tri_materials ); - obj->set_strips_v( strips_v ); - obj->set_strips_tc( strips_tc ); - obj->set_strip_materials( strip_materials ); - obj->set_fans_v( fans_v ); - obj->set_fans_tc( fans_tc ); - obj->set_fan_materials( fan_materials ); - if ( sgReadError() ) { cout << "We detected an error while reading the file." << endl; return false; @@ -508,29 +481,14 @@ bool sgReadBinObj( const string& file, SGBinObject* obj ) { // write out the structures to a binary file. We assume that the // groups come to us sorted by material property. If not, things // don't break, but the result won't be as optimal. -bool sgWriteBinObj( const string& base, const string& name, const SGBucket& b, - const SGBinObject* obj ) +bool SGBinObject::write_bin( const string& base, const string& name, + const SGBucket& b ) { Point3D p; sgVec2 t; sgVec3 pt; int i, j; - Point3D gbs_center = obj->get_gbs_center(); - float gbs_radius = obj->get_gbs_radius(); - point_list wgs84_nodes = obj->get_wgs84_nodes(); - point_list normals = obj->get_normals(); - point_list texcoords = obj->get_texcoords(); - group_list tris_v = obj->get_tris_v(); - group_list tris_tc = obj->get_tris_tc(); - string_list tri_materials = obj->get_tri_materials(); - group_list strips_v = obj->get_strips_v(); - group_list strips_tc = obj->get_strips_tc(); - string_list strip_materials = obj->get_strip_materials(); - group_list fans_v = obj->get_fans_v(); - group_list fans_tc = obj->get_fans_tc(); - string_list fan_materials = obj->get_fan_materials(); - string dir = base + "/" + b.gen_base_path(); string command = "mkdir -p " + dir; #ifdef _MSC_VER @@ -802,27 +760,12 @@ bool sgWriteBinObj( const string& base, const string& name, const SGBucket& b, // write out the structures to an ASCII file. We assume that the // groups come to us sorted by material property. If not, things // don't break, but the result won't be as optimal. -bool sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b, - SGBinObject *obj ) +bool SGBinObject::write_ascii( const string& base, const string& name, + const SGBucket& b ) { Point3D p; int i, j; - Point3D gbs_center = obj->get_gbs_center(); - float gbs_radius = obj->get_gbs_radius(); - point_list wgs84_nodes = obj->get_wgs84_nodes(); - point_list normals = obj->get_normals(); - point_list texcoords = obj->get_texcoords(); - group_list tris_v = obj->get_tris_v(); - group_list tris_tc = obj->get_tris_tc(); - string_list tri_materials = obj->get_tri_materials(); - group_list strips_v = obj->get_strips_v(); - group_list strips_tc = obj->get_strips_tc(); - string_list strip_materials = obj->get_strip_materials(); - group_list fans_v = obj->get_fans_v(); - group_list fans_tc = obj->get_fans_tc(); - string_list fan_materials = obj->get_fan_materials(); - string dir = base + "/" + b.gen_base_path(); string command = "mkdir -p " + dir; #ifdef _MSC_VER diff --git a/simgear/io/sg_binobj.hxx b/simgear/io/sg_binobj.hxx index 566427ff..a0e11aa6 100644 --- a/simgear/io/sg_binobj.hxx +++ b/simgear/io/sg_binobj.hxx @@ -53,6 +53,25 @@ typedef group_list::const_iterator const_group_list_iterator; #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION ) +/* + scenery-file: magic, nobjects, object+ + magic: "TG" + version + object: obj_typecode, nproperties, nelements, property+, element+ + element: nbytes, BYTE+ + property: prop_typecode, nbytes, BYTE+ + obj_typecode: bounding sphere | vertices | normals | texcoords | triangles | + fans | strips + prop_typecode: material_name | ??? + nelements: SHORT (Gives us 65536 which ought to be enough, right?) + nproperties: SHORT + *_typecode: CHAR + nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384 + floats = 5461 vertices which is not enough for future + growth) + vertex: FLOAT, FLOAT, FLOAT +*/ + + class SGBinObject { Point3D gbs_center; float gbs_radius; @@ -106,26 +125,21 @@ public: 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; } -}; + // read a binary file object and populate the provided structures. + bool read_bin( const string& file ); -/* - scenery-file: magic, nobjects, object+ - magic: "TG" + version - object: obj_typecode, nproperties, nelements, property+, element+ - element: nbytes, BYTE+ - property: prop_typecode, nbytes, BYTE+ - obj_typecode: bounding sphere | vertices | normals | texcoords | triangles | - fans | strips - prop_typecode: material_name | ??? - nelements: SHORT (Gives us 65536 which ought to be enough, right?) - nproperties: SHORT - *_typecode: CHAR - nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384 - floats = 5461 vertices which is not enough for future - growth) - vertex: FLOAT, FLOAT, FLOAT -*/ + // write out the structures to a binary file. We assume that the + // groups come to us sorted by material property. If not, things + // don't break, but the result won't be as optimal. + bool write_bin( const string& base, const string& name, const SGBucket& b ); + + // write out the structures to an ASCII file. We assume that the + // groups come to us sorted by material property. If not, things + // don't break, but the result won't be as optimal. + bool write_ascii( const string& base, const string& name, + const SGBucket& b ); +}; // calculate the bounding sphere. Center is the center of the @@ -133,20 +147,4 @@ public: double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ); -// read a binary file object and populate the provided structures. -bool sgReadBinObj( const string& file, SGBinObject* obj ); - -// write out the structures to a binary file. We assume that the -// groups come to us sorted by material property. If not, things -// don't break, but the result won't be as optimal. -bool sgWriteBinObj( const string& base, const string& name, const SGBucket& b, - const SGBinObject* obj ); - -// write out the structures to an ASCII file. We assume that the -// groups come to us sorted by material property. If not, things -// don't break, but the result won't be as optimal. -bool sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b, - SGBinObject* obj ); - - #endif // _SG_BINOBJ_HXX