]> git.mxchange.org Git - simgear.git/blob - simgear/io/sg_binobj.hxx
made read/write functions into members of SGBinObject.
[simgear.git] / simgear / io / sg_binobj.hxx
1 // sg_binobj.hxx -- routines to read and write low level flightgear 3d objects
2 //
3 // Written by Curtis Olson, started January 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 //
23
24
25 #ifndef _SG_BINOBJ_HXX
26 #define _SG_BINOBJ_HXX
27
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33 #include <plib/sg.h>
34
35 #include <simgear/compiler.h>
36 #include <simgear/constants.h>
37 #include <simgear/math/sg_types.hxx>
38 #include <simgear/bucket/newbucket.hxx>
39
40 #include <stdio.h>
41 #include <time.h>
42
43 #include <list>
44 #include STL_STRING
45
46
47
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;
51
52
53 #define SG_FILE_MAGIC_NUMBER  ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
54
55
56 /*
57    scenery-file: magic, nobjects, object+
58    magic: "TG" + version
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 |
63                 fans | strips 
64    prop_typecode: material_name | ???
65    nelements: SHORT (Gives us 65536 which ought to be enough, right?)
66    nproperties: SHORT
67    *_typecode: CHAR
68    nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
69                     floats = 5461 vertices which is not enough for future
70                     growth)
71    vertex: FLOAT, FLOAT, FLOAT
72 */
73
74
75 class SGBinObject {
76     Point3D gbs_center;
77     float gbs_radius;
78     point_list wgs84_nodes;
79     point_list normals;
80     point_list texcoords;
81     group_list tris_v;
82     group_list tris_tc; 
83     string_list tri_materials;
84     group_list strips_v;
85     group_list strips_tc; 
86     string_list strip_materials;
87     group_list fans_v;
88     group_list fans_tc;
89     string_list fan_materials;
90
91 public:
92
93     inline Point3D get_gbs_center() const { return gbs_center; }
94     inline void set_gbs_center( Point3D p ) { gbs_center = p; }
95
96     inline float get_gbs_radius() const { return gbs_radius; }
97     inline void set_gbs_radius( float r ) { gbs_radius = r; }
98
99     inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
100     inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
101
102     inline point_list get_normals() const { return normals; }
103     inline void set_normals( point_list n ) { normals = n; }
104
105     inline point_list get_texcoords() const { return texcoords; }
106     inline void set_texcoords( point_list t ) { texcoords = t; }
107
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; }
114     
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; }
121     
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; }
128
129     // read a binary file object and populate the provided structures.
130     bool read_bin( const string& file );
131
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 );
136
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,
141                       const SGBucket& b );
142 };
143
144
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 );
148
149
150 #endif // _SG_BINOBJ_HXX