1 // sg_binobj.hxx -- routines to read and write low level flightgear 3d objects
3 // Written by Curtis Olson, started January 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifndef _SG_BINOBJ_HXX
26 #define _SG_BINOBJ_HXX
35 #include <simgear/compiler.h>
36 #include <simgear/constants.h>
37 #include <simgear/math/sg_types.hxx>
38 #include <simgear/bucket/newbucket.hxx>
48 typedef vector < int_list > group_list;
49 typedef group_list::iterator group_list_iterator;
50 typedef group_list::const_iterator const_group_list_iterator;
53 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
57 scenery-file: magic, nobjects, object+
59 object: obj_typecode, nproperties, nelements, property+, element+
60 element: nbytes, BYTE+
61 property: prop_typecode, nbytes, BYTE+
62 obj_typecode: bounding sphere | vertices | normals | texcoords | triangles |
64 prop_typecode: material_name | ???
65 nelements: SHORT (Gives us 65536 which ought to be enough, right?)
68 nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
69 floats = 5461 vertices which is not enough for future
71 vertex: FLOAT, FLOAT, FLOAT
78 point_list wgs84_nodes;
83 string_list tri_materials;
86 string_list strip_materials;
89 string_list fan_materials;
93 inline Point3D get_gbs_center() const { return gbs_center; }
94 inline void set_gbs_center( Point3D p ) { gbs_center = p; }
96 inline float get_gbs_radius() const { return gbs_radius; }
97 inline void set_gbs_radius( float r ) { gbs_radius = r; }
99 inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
100 inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
102 inline point_list get_normals() const { return normals; }
103 inline void set_normals( point_list n ) { normals = n; }
105 inline point_list get_texcoords() const { return texcoords; }
106 inline void set_texcoords( point_list t ) { texcoords = t; }
108 inline group_list get_tris_v() const { return tris_v; }
109 inline void set_tris_v( group_list g ) { tris_v = g; }
110 inline group_list get_tris_tc() const { return tris_tc; }
111 inline void set_tris_tc( group_list g ) { tris_tc = g; }
112 inline string_list get_tri_materials() const { return tri_materials; }
113 inline void set_tri_materials( string_list s ) { tri_materials = s; }
115 inline group_list get_strips_v() const { return strips_v; }
116 inline void set_strips_v( group_list g ) { strips_v = g; }
117 inline group_list get_strips_tc() const { return strips_tc; }
118 inline void set_strips_tc( group_list g ) { strips_tc = g; }
119 inline string_list get_strip_materials() const { return strip_materials; }
120 inline void set_strip_materials( string_list s ) { strip_materials = s; }
122 inline group_list get_fans_v() const { return fans_v; }
123 inline void set_fans_v( group_list g ) { fans_v = g; }
124 inline group_list get_fans_tc() const { return fans_tc; }
125 inline void set_fans_tc( group_list g ) { fans_tc = g; }
126 inline string_list get_fan_materials() const { return fan_materials; }
127 inline void set_fan_materials( string_list s ) { fan_materials = s; }
129 // read a binary file object and populate the provided structures.
130 bool read_bin( const string& file );
132 // write out the structures to a binary file. We assume that the
133 // groups come to us sorted by material property. If not, things
134 // don't break, but the result won't be as optimal.
135 bool write_bin( const string& base, const string& name, const SGBucket& b );
137 // write out the structures to an ASCII file. We assume that the
138 // groups come to us sorted by material property. If not, things
139 // don't break, but the result won't be as optimal.
140 bool write_ascii( const string& base, const string& name,
145 // calculate the bounding sphere. Center is the center of the
146 // tile and zero elevation
147 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
150 #endif // _SG_BINOBJ_HXX